Skip to content

Instantly share code, notes, and snippets.

@MarcoNicolodi
Created January 14, 2019 13:08
Show Gist options
  • Save MarcoNicolodi/fa2ceb44ba4fba054b1ad80245b76176 to your computer and use it in GitHub Desktop.
Save MarcoNicolodi/fa2ceb44ba4fba054b1ad80245b76176 to your computer and use it in GitHub Desktop.
Flaky unit test suite
[Fact(DisplayName = @"
GIVEN
that document Atendence List is published
AND SteveJobs is the elaborator
AND SteveJobs requested a new revision
AND the request is still open
AND SteveJobs has an open and closed revision request
WHEN
I replace SteveJobs with MrCatra
THEN
MrCatra should be the new responsible of the open revision request of the Attendance List document
AND SteveJobs should still be the responsible of the closed revision request
")]
public async void Replace_ShouldChangeResponsibleForRevisionRequest()
{
// Arrange
var context = InMemoryContextFactory.Create();
var document = DocumentMother.DocumentWithOnePublishedRevision(1, "CEA001", null, 1, UserMother.SteveJobs(), null);
var revision = document.GetLastPublishedRevision();
revision.RequestNewRevision("old revision request", UserMother.SteveJobsId);
revision.RejectRevisionRequest("rejected");
revision.RequestNewRevision("new revision request", UserMother.SteveJobsId);
await context.Documents.AddAsync(document);
await context.SaveChangesAsync();
context.DetachAllEntities();
var service = ReplaceResponsibleServiceFactory.Create(context);
//Act
await service.Replace(UserMother.SteveJobsId, UserMother.MrCatraId);
//Assert
var unitOfWork = UnitOfWorkFactory.Create(context);
var documentFromDatabase = unitOfWork.Document.Find(document.Id);
documentFromDatabase
.GetLastPublishedRevision()
.GetOpenRevisionRequest()
.ResponsibleId
.Should()
.Be(UserMother.MrCatraId, "because we replaced SteveJobs with MrCatra and SteveJobs was the requester of this revision");
documentFromDatabase
.GetLastPublishedRevision()
.GetClosedRevisionRequest()
.ResponsibleId
.Should()
.Be(UserMother.SteveJobsId, "because we shouldnt change history");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment