public async Task GetSingleUnpaidAsync_GIVEN_Invalid_Input_RETURNS_Null() { // Arrange. var options = new DbContextOptionsBuilder <UnpaidsContext>() .UseInMemoryDatabase(databaseName: "Find_unpaid2") .Options; // Insert seed data into the database using one instance of the context. using (var context = new UnpaidsContext(options)) { context.TbUnpaid.Add(new TbUnpaid { UnpaidId = 1, PolicyNumber = "P1", Name = "Tom", Message = "Test Message 1." }); context.SaveChanges(); } // Act and Assert. // Use a clean instance of the context to run the test. using (var context = new UnpaidsContext(options)) { var service = new UnpaidDataManager(context); var actual = await service.GetSingleUnpaidAsync(0, CancellationToken.None); Assert.AreEqual(null, actual); } }
public async Task GetSingleUnpaidAsync_GIVEN_Valid_Input_RETURNS_Valid_Unpaid() { // Arrange. var options = new DbContextOptionsBuilder <UnpaidsContext>() .UseInMemoryDatabase(databaseName: "Find_unpaid") .Options; // Insert seed data into the database using one instance of the context. using (var context = new UnpaidsContext(options)) { context.TbUnpaid.Add(new TbUnpaid { UnpaidId = 1, PolicyNumber = "P1", IdNumber = "9009165023080", Name = "Tom", Message = "Test Message 1.", Title = "Test1" }); context.TbUnpaid.Add(new TbUnpaid { UnpaidId = 2, PolicyNumber = "P2", Name = "Bob", IdNumber = "9009165023081", Message = "Test Message 2.", Title = "Test2" }); context.TbUnpaid.Add(new TbUnpaid { UnpaidId = 3, PolicyNumber = "P1", IdNumber = "9009165023080", Name = "Tom", Message = "Test Message 3.", Title = "Test3" }); context.TbUnpaid.Add(new TbUnpaid { UnpaidId = 4, PolicyNumber = "P4", IdNumber = "9009165023082", Name = "Brad", Message = "Test Message 4.", Title = "Test4" }); context.SaveChanges(); } // Act and Assert. // Use a clean instance of the context to run the test. using (var context = new UnpaidsContext(options)) { var service = new UnpaidDataManager(context); var actual = await service.GetSingleUnpaidAsync(3, CancellationToken.None); Assert.AreEqual(3, actual.UnpaidId); Assert.AreEqual("P1", actual.PolicyNumber); Assert.AreEqual("9009165023080", actual.IdNumber); Assert.AreEqual("Tom", actual.Name); Assert.AreEqual("Test Message 3.", actual.Message); Assert.AreEqual("Test3", actual.Title); } }