public void FindAllReturnsNoRecords() { var fakeTransactionType = new TransactionType[] { }; var options = new DbContextOptionsBuilder().Options; var context = new Mock<AccountingContext>(options); context.Setup(x => x.TransactionTypes).ReturnsDbSet(fakeTransactionType); context.Setup(i => i.Set<TransactionType>()).ReturnsDbSet(fakeTransactionType); var sut = new MockBaseRepository<TransactionType>(context.Object); var result = sut.FindAll(); var resultList = result.ToList(); result.Should().NotBeNull("the TransactionTypes should not exist but an emtpy IQueryable should be returned"); resultList.Count.Should().Be(0, "there are no TransactionTypes"); }
public void FindAllReturnsAllRecords() { var fakeTransactionType = new TransactionType[] { new TransactionType { Id = 1, Name="FakeTransaction1" }, new TransactionType { Id = 2, Name="FakeTransaction2" }, new TransactionType { Id = 3, Name="FakeTransaction3" } }; var options = new DbContextOptionsBuilder().Options; var context = new Mock<AccountingContext>(options); context.Setup(x => x.TransactionTypes).ReturnsDbSet(fakeTransactionType); context.Setup(i => i.Set<TransactionType>()).ReturnsDbSet(fakeTransactionType); var sut = new MockBaseRepository<TransactionType>(context.Object); var result = sut.FindAll(); var resultList = result.ToList(); result.Should().NotBeNull("the TransactionTypes should exist therefore they should be returned and not be Null"); resultList.Count.Should().BeGreaterThan(0, "there are TransactionTypes therefore there are more than 0"); resultList.Count.Should().BeLessThan(4, "there are only 3 TransactionTypes therefore there must be less than 4"); resultList.Should().Contain(fakeTransactionType[0], "this is one of the fakeTransactions that should exist therefore be in the set returned"); resultList.Should().Contain(fakeTransactionType[1], "this is one of the fakeTransactions that should exist therefore be in the set returned"); resultList.Should().Contain(fakeTransactionType[2], "this is one of the fakeTransactions that should exist therefore be in the set returned"); }