public async Task GetAllUnpaidResponseAsync_RETURNS_Valid_UnpaidResponse_List() { // Arrange. var options = new DbContextOptionsBuilder <UnpaidsContext>() .UseInMemoryDatabase(databaseName: "Get_unpaidResponses") .Options; using (var context = new UnpaidsContext(options)) { context.TbUnpaidResponse.Add(new TbUnpaidResponse { UnpaidResponseId = 1, UnpaidRequestId = 12, StatusId = 1, ResponseId = 1, Accepted = true }); context.TbUnpaidResponse.Add(new TbUnpaidResponse { UnpaidResponseId = 2, UnpaidRequestId = 50, StatusId = 1, ResponseId = 1, Accepted = true }); context.TbUnpaidResponse.Add(new TbUnpaidResponse { UnpaidResponseId = 3, UnpaidRequestId = 12, StatusId = 1, ResponseId = 1, Accepted = false }); context.TbUnpaidResponse.Add(new TbUnpaidResponse { UnpaidResponseId = 4, UnpaidRequestId = 25, StatusId = 1, ResponseId = 2, Accepted = true }); context.SaveChanges(); } // Act and Assert. using (var context = new UnpaidsContext(options)) { var service = new UnpaidResponseDataManager(context); var actual = await service.GetAllUnpaidResponseAsync(CancellationToken.None); Assert.AreEqual(4, actual.Count()); } }
public async Task GetAllUnpaidAsync_RETURNS_Valid_Unpaid_List() { // Arrange. var options = new DbContextOptionsBuilder <UnpaidsContext>() .UseInMemoryDatabase(databaseName: "Get_unpaids") .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.GetAllUnpaidAsync(CancellationToken.None); Assert.AreEqual(4, actual.Count()); } }
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 UpdateUnpaidRequestAsync_GIVEN_Valid_Input_RETURNS_Valid_Result() { // Arrange. var options = new DbContextOptionsBuilder <UnpaidsContext>() .UseInMemoryDatabase(databaseName: "Update_unpaidRequests_against_unpaidId") .Options; using (var context = new UnpaidsContext(options)) { context.TbUnpaidRequest.Add(new TbUnpaidRequest { UnpaidRequestId = 1, UnpaidId = 10, StatusId = 1, NotificationId = 1 }); context.TbUnpaidRequest.Add(new TbUnpaidRequest { UnpaidRequestId = 2, UnpaidId = 12, StatusId = 2, NotificationId = 3 }); context.TbUnpaidRequest.Add(new TbUnpaidRequest { UnpaidRequestId = 3, UnpaidId = 10, StatusId = 1, NotificationId = 1 }); context.TbUnpaidRequest.Add(new TbUnpaidRequest { UnpaidRequestId = 4, UnpaidId = 55, StatusId = 3, NotificationId = 2 }); context.SaveChanges(); } // Act. using (var context = new UnpaidsContext(options)) { var service = new UnpaidRequestDataManager(context); await service.UpdateUnpaidRequestAsync(3, Notification.Call, Status.Failed, "Testing.", DateTime.Now, "GUID_1", CancellationToken.None); } // Assert. // Use a separate instance of the context to verify correct data was saved to database using (var context = new UnpaidsContext(options)) { var actual = context.TbUnpaidRequest.FirstOrDefault(item => item.UnpaidRequestId == 3); if (actual != null) { Assert.AreEqual(3, actual.UnpaidRequestId); Assert.AreEqual(3, actual.StatusId); Assert.AreEqual(4, actual.NotificationId); Assert.AreEqual("Testing.", actual.StatusAdditionalInfo); Assert.AreEqual("GUID_1", actual.CorrelationId); } } }
public async Task GetAllUnpaidAsync_GIVEN_Valid_Input_RETURNS_Valid_Unpaid_List() { // Arrange. var options = new DbContextOptionsBuilder <UnpaidsContext>() .UseInMemoryDatabase(databaseName: "Get_unpaids_against_idempotencyKey") .Options; // Insert seed data into the database using one instance of the context. using (var context = new UnpaidsContext(options)) { context.TbUnpaidBatch.Add(new TbUnpaidBatch { BatchKey = "7c9e6679-7425-40de-944b-e07fc1f90ae7", StatusId = (int)Status.Pending, UserName = "******", UnpaidBatchId = 1 }); context.TbUnpaidBatch.Add(new TbUnpaidBatch { BatchKey = "7c9e6679-7425-40de-944b-e07fc1f90ae9", StatusId = (int)Status.Pending, UserName = "******", UnpaidBatchId = 2 }); context.SaveChanges(); } // 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", UnpaidBatchId = 1 }); context.TbUnpaid.Add(new TbUnpaid { UnpaidId = 2, PolicyNumber = "P2", Name = "Bob", IdNumber = "9009165023081", Message = "Test Message 2.", Title = "Test2", UnpaidBatchId = 2 }); context.TbUnpaid.Add(new TbUnpaid { UnpaidId = 3, PolicyNumber = "P1", IdNumber = "9009165023080", Name = "Tom", Message = "Test Message 3.", Title = "Test3", UnpaidBatchId = 1 }); context.TbUnpaid.Add(new TbUnpaid { UnpaidId = 4, PolicyNumber = "P4", IdNumber = "9009165023082", Name = "Brad", Message = "Test Message 4.", Title = "Test4", UnpaidBatchId = 2 }); 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.GetAllUnpaidAsync("7c9e6679-7425-40de-944b-e07fc1f90ae7", CancellationToken.None); var unpaidDbs = actual.ToList(); Assert.AreEqual(2, unpaidDbs.Count); Assert.AreEqual(1, unpaidDbs.ToList()[0].UnpaidId); Assert.AreEqual(3, unpaidDbs.ToList()[1].UnpaidId); } }
public async Task GetAllUnpaidRequestAsync_GIVEN_Valid_Input_RETURNS_Valid_UnpaidRequest_List() { // Arrange. var options = new DbContextOptionsBuilder <UnpaidsContext>() .UseInMemoryDatabase(databaseName: "Get_unpaidRequests_against_unpaidId") .Options; using (var context = new UnpaidsContext(options)) { context.TbUnpaidRequest.Add(new TbUnpaidRequest { UnpaidRequestId = 1, UnpaidId = 10, StatusId = 1, NotificationId = 1 }); context.TbUnpaidRequest.Add(new TbUnpaidRequest { UnpaidRequestId = 2, UnpaidId = 12, StatusId = 2, NotificationId = 3 }); context.TbUnpaidRequest.Add(new TbUnpaidRequest { UnpaidRequestId = 3, UnpaidId = 10, StatusId = 1, NotificationId = 1 }); context.TbUnpaidRequest.Add(new TbUnpaidRequest { UnpaidRequestId = 4, UnpaidId = 55, StatusId = 3, NotificationId = 2 }); context.SaveChanges(); } // Act and Assert. using (var context = new UnpaidsContext(options)) { var service = new UnpaidRequestDataManager(context); var actual = await service.GetAllUnpaidRequestAsync(10, CancellationToken.None); var unpaidRequests = actual.ToList(); Assert.AreEqual(2, unpaidRequests.Count()); Assert.AreEqual(1, unpaidRequests.ToList()[0].UnpaidRequestId); Assert.AreEqual(3, unpaidRequests.ToList()[1].UnpaidRequestId); } }
public async Task GetSingleUnpaidResponseAsync_GIVEN_Valid_Input_RETURNS_Valid_UnpaidResponse() { // Arrange. var options = new DbContextOptionsBuilder <UnpaidsContext>() .UseInMemoryDatabase(databaseName: "Find_unpaidResponse") .Options; using (var context = new UnpaidsContext(options)) { context.TbUnpaidResponse.Add(new TbUnpaidResponse { UnpaidResponseId = 1, UnpaidRequestId = 12, StatusId = 1, ResponseId = 1, Accepted = true }); context.TbUnpaidResponse.Add(new TbUnpaidResponse { UnpaidResponseId = 2, UnpaidRequestId = 50, StatusId = 1, ResponseId = 1, Accepted = true }); context.TbUnpaidResponse.Add(new TbUnpaidResponse { UnpaidResponseId = 3, UnpaidRequestId = 12, StatusId = 1, ResponseId = 1, Accepted = false }); context.TbUnpaidResponse.Add(new TbUnpaidResponse { UnpaidResponseId = 4, UnpaidRequestId = 25, StatusId = 1, ResponseId = 2, Accepted = true }); context.SaveChanges(); } // Act and Assert. using (var context = new UnpaidsContext(options)) { var service = new UnpaidResponseDataManager(context); var actual = await service.GetSingleUnpaidResponseAsync(3, CancellationToken.None); Assert.AreEqual(3, actual.UnpaidResponseId); Assert.AreEqual(12, actual.UnpaidRequestId); Assert.AreEqual(1, actual.StatusId); Assert.AreEqual(1, actual.ResponseId); Assert.AreEqual(false, actual.Accepted); } }
public async Task GetSingleUnpaidRequestAsync_GIVEN_Invalid_Input_RETURNS_Null() { // Arrange. var options = new DbContextOptionsBuilder <UnpaidsContext>() .UseInMemoryDatabase(databaseName: "Find_unpaidRequest2") .Options; using (var context = new UnpaidsContext(options)) { context.TbUnpaidRequest.Add(new TbUnpaidRequest { UnpaidRequestId = 1, UnpaidId = 10, StatusId = 1, NotificationId = 1 }); context.SaveChanges(); } // Act and Assert. using (var context = new UnpaidsContext(options)) { var service = new UnpaidRequestDataManager(context); var actual = await service.GetSingleUnpaidRequestAsync(0, CancellationToken.None); Assert.AreEqual(null, actual); } }