public void FindAllWhereReturnCorrectRecords() { var fakeTransactionType = new TransactionType[] { new TransactionType { Id = 1, Name="FakeTransaction1" }, new TransactionType { Id = 2, Name="FakeTransaction2" }, new TransactionType { Id = 3, Name="FakeTransaction3" }, new TransactionType { Id = 4, Name="FakeTransaction1" } }; 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.FindAllWhere(t => t.Name.Equals("FakeTransaction1", StringComparison.InvariantCultureIgnoreCase)); var resultList = result.ToList(); resultList.Should().NotBeNull("the TransactionType should exist therefore it should be returned in a set and not be Null"); resultList.Count.Should().BeGreaterThan(0, "there are TransactionTypes therefore there are more than 0"); resultList.Count.Should().Be(2, "there are only 2 TransactionTypes with the name \"FakeTransaction1\" therefore there must be only 2"); resultList.Should().Contain(fakeTransactionType[0], "this is one of the fakeTransactions that should exist with the name therefore it should be in the set returned"); resultList.Should().Contain(fakeTransactionType[3], "this is one of the fakeTransactions that should exist with the name therefore it should be in the set returned"); }
public void FindAllWhereReturnNoRecords() { var fakeTransactionType = new TransactionType[] { new TransactionType { Id = 1, Name="FakeTransaction1" }, new TransactionType { Id = 2, Name="FakeTransaction2" }, new TransactionType { Id = 3, Name="FakeTransaction3" }, new TransactionType { Id = 4, Name="FakeTransaction1" } }; 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.FindAllWhere(t => t.Name.Equals("FakeTransaction4", StringComparison.InvariantCultureIgnoreCase)); var resultList = result.ToList(); resultList.Should().NotBeNull("the TransactionType even though empty should just return an empty set and not be Null"); resultList.Count.Should().Be(0, "there are no TransactionTypes therefore there should be 0"); }