Beispiel #1
0
        public async System.Threading.Tasks.Task GetActiveDangerousDrugs_ReturnMultipleRecords()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <ProductContext>()
                          .UseInMemoryDatabase(databaseName: "Products Test 22")
                          .Options;

            using (var context = new ProductContext(options))
            {
                context.Products.Add(new Product {
                    ProductId = 10, Dangerous = true
                });
                context.Products.Add(new Product {
                    ProductId = 11, Dangerous = true
                });
                context.SaveChanges();
            }

            using (var context = new ProductContext(options))
            {
                // Act
                _productsController = new ProductsController(context);
                var response = await _productsController.GetActiveDangerousDrugs();

                // Assert
                Assert.NotNull(response.Value);
                Assert.Equal(2, response.Value.Count);
            }
        }
Beispiel #2
0
        public async System.Threading.Tasks.Task GetActiveDangerousDrugs_ReturnNothingIfDangerousIsFalse()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <ProductContext>()
                          .UseInMemoryDatabase(databaseName: "Products Test 20")
                          .Options;

            using (var context = new ProductContext(options))
            {
                context.Products.Add(new Product {
                    ProductId = 8, Dangerous = false
                });
                context.SaveChanges();
            }

            using (var context = new ProductContext(options))
            {
                // Act
                _productsController = new ProductsController(context);
                var response = await _productsController.GetActiveDangerousDrugs();

                // Assert
                Assert.Null(response.Value);
            }
        }
Beispiel #3
0
        public async System.Threading.Tasks.Task GetActiveDangerousDrugs_ReturnNothingWhenBothFieldDatesHavePast()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <ProductContext>()
                          .UseInMemoryDatabase(databaseName: "Products Test 21")
                          .Options;

            using (var context = new ProductContext(options))
            {
                context.Products.Add(new Product {
                    ProductId = 9, DeleteDate = new DateTime(2011, 11, 1), InactiveDate = new DateTime(2011, 11, 1), Dangerous = true
                });
                context.SaveChanges();
            }

            using (var context = new ProductContext(options))
            {
                // Act
                _productsController = new ProductsController(context);
                var response = await _productsController.GetActiveDangerousDrugs();

                // Assert
                Assert.Null(response.Value);
            }
        }
Beispiel #4
0
        public async System.Threading.Tasks.Task GetActiveDangerousDrugs_ReturnRecordWhenNeitherDateHasComeToPass()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <ProductContext>()
                          .UseInMemoryDatabase(databaseName: "Products Test 18")
                          .Options;

            using (var context = new ProductContext(options))
            {
                context.Products.Add(new Product {
                    ProductId = 7, DeleteDate = new DateTime(2022, 11, 1), InactiveDate = new DateTime(2022, 11, 1), Dangerous = true
                });
                context.SaveChanges();
            }

            using (var context = new ProductContext(options))
            {
                // Act
                _productsController = new ProductsController(context);
                var response = await _productsController.GetActiveDangerousDrugs();

                // Assert
                Assert.NotNull(response.Value);
                Assert.Single(response.Value);
            }
        }