Пример #1
0
        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());
            }
        }
Пример #2
0
        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);
            }
        }