Пример #1
0
        public async Task AddUnpaidResponseAsync_GIVEN_Valid_Unpaid_RETURNS_Valid_Result()
        {
            // Arrange.
            var options = new DbContextOptionsBuilder <UnpaidsContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            // Act.
            // Run the test against one instance of the context
            using (var context = new UnpaidsContext(options))
            {
                var service = new UnpaidResponseDataManager(context);
                var actual  = await service.AddUnpaidResponseAsync(new List <TbUnpaidResponse>
                {
                    new TbUnpaidResponse
                    {
                        UnpaidRequestId = 41,
                        StatusId        = 1,
                        ResponseId      = 1,
                        Accepted        = true
                    }
                }, CancellationToken.None);
            }

            // Assert.
            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new UnpaidsContext(options))
            {
                Assert.AreEqual(1, context.TbUnpaidResponse.Count());
                Assert.AreEqual(41, context.TbUnpaidResponse.Single().UnpaidRequestId);
                Assert.AreEqual(1, context.TbUnpaidResponse.Single().StatusId);
                Assert.AreEqual(1, context.TbUnpaidResponse.Single().ResponseId);
                Assert.IsTrue(context.TbUnpaidResponse.Single().Accepted);
            }
        }
Пример #2
0
        public async Task AddUnpaidResponseAsync_GIVEN_Null_UnpaidResponse_RETURNS_Valid_Result()
        {
            // Arrange.
            var options = new DbContextOptionsBuilder <UnpaidsContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database3")
                          .Options;

            // Act.
            // Run the test against one instance of the context
            using (var context = new UnpaidsContext(options))
            {
                var service = new UnpaidResponseDataManager(context);
                var actual  = await service.AddUnpaidResponseAsync(null, CancellationToken.None);
            }

            // Assert.
            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new UnpaidsContext(options))
            {
                Assert.AreEqual(0, context.TbUnpaidResponse.Count());
            }
        }