public async Task GivenABugRepository_WhenBugsAreRetrieved_ThenReturnsBugs() { // Arrange var connection = DbConnectionFactory.CreateTransient(); var dbContext = new BugDbContext(connection); The <IDbContextFactory>().Setup(x => x.CreateBugDbContext()).Returns(dbContext); var expectedBugs = Enumerable.Range(0, 10).Select(x => TestUtility.GenerateEntityBugLite()).ToList(); foreach (var bugEntity in expectedBugs) { dbContext.Bugs.Add(bugEntity); } await dbContext.SaveChangesAsync(); // Act var actualBugs = await Target.Get(); // Assert actualBugs.Count.Should().Be(expectedBugs.Count); foreach (var actualBug in actualBugs) { var expectedBug = expectedBugs.SingleOrDefault(x => x.Id == actualBug.Id); expectedBug.Should().NotBeNull(); actualBug.CreationDate.Should().Be(expectedBug.CreationDate); actualBug.LastModificationDate.Should().Be(expectedBug.LastModificationDate); actualBug.Title.Should().Be(expectedBug.Title); actualBug.Description.Should().Be(expectedBug.Description); } }
public async Task GivenABugRepository_WhenAnExistingBugIsUpdated_ThenReturnsUpdatedBug() { // Arrange var connection = DbConnectionFactory.CreateTransient(); var dbContext = new BugDbContext(connection); The <IDbContextFactory>().Setup(x => x.CreateBugDbContext()).Returns(dbContext); var expectedBug = TestUtility.GenerateEntityBugLite(); dbContext.Bugs.Add(expectedBug); await dbContext.SaveChangesAsync(); var modificationDate = expectedBug.LastModificationDate; expectedBug.Title = TestUtility.FixtureInstance.Create <string>(); expectedBug.Description = TestUtility.FixtureInstance.Create <string>(); // Act var actualBug = await Target.Update(expectedBug); // Assert actualBug.Should().NotBeNull(); actualBug.Title.Should().Be(expectedBug.Title); actualBug.Description.Should().Be(expectedBug.Description); actualBug.CreationDate.Should().Be(expectedBug.CreationDate); actualBug.LastModificationDate.Should().BeAfter(modificationDate); }
public async Task GivenABugRepository_WhenAnExistingBugIsDeleted_ThenReturnsTrue() { // Arrange var connection = DbConnectionFactory.CreateTransient(); var dbContext = new BugDbContext(connection); The <IDbContextFactory>().Setup(x => x.CreateBugDbContext()).Returns(dbContext); var expectedBug = TestUtility.GenerateEntityBugLite(); dbContext.Bugs.Add(expectedBug); await dbContext.SaveChangesAsync(); // Act var actualBug = await Target.Delete(expectedBug.Id); // Assert actualBug.Should().BeTrue(); }
public async Task GivenABugRepository_WhenABugIsRetrieved_ThenReturnsBug() { // Arrange var connection = DbConnectionFactory.CreateTransient(); var dbContext = new BugDbContext(connection); The <IDbContextFactory>().Setup(x => x.CreateBugDbContext()).Returns(dbContext); var bugEntity = TestUtility.GenerateEntityBugLite(); dbContext.Bugs.Add(bugEntity); await dbContext.SaveChangesAsync(); // Act var actualBug = await Target.Get(bugEntity.Id); // Assert actualBug.Should().NotBeNull(); actualBug.CreationDate.Should().Be(bugEntity.CreationDate); actualBug.LastModificationDate.Should().Be(bugEntity.LastModificationDate); actualBug.Title.Should().Be(bugEntity.Title); actualBug.Description.Should().Be(bugEntity.Description); }