Exemplo n.º 1
0
        public GetProductsTest(ITestOutputHelper output)
        {
            ILogger logger = new TestOutputLogger(output);

            var business1 = new Business("BUSINESS-1", "My First Business");
            var business2 = new Business("BUSINESS-2", "My Second Business");
            var products  = new List <Product>
            {
                new Product("01", business1, "Product One"),
                new Product("02", business1, "Product Two"),
                new Product("03", business1, "Product Three", "With description")
            };
            var business = new List <Business>()
            {
                business1, business2
            };

            IProductRepository  productRepository  = new InMemoryProductRepository(products);
            IBusinessRepository businessRepository = new InMemoryBusinessRepository(business);

            var collection = new ServiceCollection()
                             .AddScoped(sp => logger)
                             .AddScoped(sp => productRepository)
                             .AddScoped(sp => businessRepository)
                             .AddScoped <GetProductsByBusiness>();

            _serviceProvider = collection.BuildServiceProvider();
            // _factory = _serviceProvider.GetRequiredService<IServiceScopeFactory>();
        }
        public CreateProductTest(ITestOutputHelper output)
        {
            ILogger logger = new TestOutputLogger(output);

            var business = new Business("B1", "My Business");
            IBusinessRepository businessRepository = new InMemoryBusinessRepository(new List <Business>()
            {
                business
            });

            var products = new List <Product>
            {
                new Product("P01", business.Key, "My Product")
            };
            IProductRepository productRepository = new InMemoryProductRepository(products);

            var collection = new ServiceCollection()
                             .AddScoped(sp => logger)
                             .AddScoped(sp => productRepository)
                             .AddScoped(sp => businessRepository)
                             .AddScoped <CreateProduct>();

            _serviceProvider = collection.BuildServiceProvider();
            // _factory = _serviceProvider.GetRequiredService<IServiceScopeFactory>();
        }
Exemplo n.º 3
0
        public async Task Overview()
        {
            var productRepo = new InMemoryProductRepository();
            await productRepo.AddOrUpdate(new[] { new Product {
                                                      Key = "test1"
                                                  } });

            var builder = new WebHostBuilder()
                          .ConfigureServices(services => services
                                             .AddSingleton <IProductRepository>(productRepo)
                                             .AddSingleton <ProductHub>()
                                             )
                          .Configure(app => app
                                     .UseWebSockets()
                                     .Use(ProcessWebSocketRequest)
                                     );

            using (var server = new TestServer(builder))
            {
                var client = server.CreateWebSocketClient();
                var ws     = await client.ConnectAsync(new Uri("ws://localhost/overview"), CancellationToken.None);

                var msg = await ws.Receive <List <Product> >();

                Assert.Equal("test1", msg.Data[0].Key);

                await productRepo.AddOrUpdate(new[] { new Product {
                                                          Key = "test2"
                                                      } });

                msg = await ws.Receive <List <Product> >();

                Assert.Equal("test2", msg.Data[0].Key);
            }
        }
 public void SutIsProductRepository(InMemoryProductRepository sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom<ProductRepository>(sut);
     // Teardown
 }
 public void SutIsProductRepository(InMemoryProductRepository sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom <ProductRepository>(sut);
     // Teardown
 }
Exemplo n.º 6
0
        public async Task Upload()
        {
            var productRepo = new InMemoryProductRepository();

            var builder = new WebHostBuilder()
                          .ConfigureServices(services => services
                                             .AddSingleton <IProductRepository>(productRepo)
                                             .AddSingleton <ProductHub>()
                                             )
                          .Configure(app => app
                                     .UseWebSockets()
                                     .Use(ProcessWebSocketRequest)
                                     );

            using (var server = new TestServer(builder))
            {
                var client = server.CreateWebSocketClient();
                var ws     = await client.ConnectAsync(new Uri("ws://localhost/upload"), CancellationToken.None);

                await ws.Send(
                    @"Key,Artikelcode,colorcode,description,price,discountprice,delivered in,q1,size,color
00000002groe56,2,broek,Gaastra,8.00,,1-3 werkdagen,baby,56,groen"
                    );

                var msg = await ws.Receive <BatchResult <Product, string> >();

                var result = msg.Data;

                Assert.Single(result.Successes);
                Assert.Empty(result.Errors);

                var products = new List <Product>();
                var signal   = new ManualResetEvent(false);
                productRepo.StreamAll().Subscribe(p =>
                {
                    products.AddRange(p);
                    signal.Set();
                });

                signal.WaitOne();
                var product = products[0];

                Assert.Equal("00000002groe56", product.Key);
                Assert.Equal("2", product.ArticleCode);
                Assert.Equal("broek", product.ColorCode);
                Assert.Equal("Gaastra", product.Description);
                Assert.Equal(8.00m, product.Price);
                Assert.Null(product.DiscountPrice);
                Assert.Equal("1-3 werkdagen", product.DeliveredIn);
                Assert.Equal("baby", product.Q1);
                Assert.Equal(56, product.Size);
                Assert.Equal("groen", product.Color);
            }
        }
Exemplo n.º 7
0
        public void InMemoryProductRepository_should_add_the_given_product()
        {
            var testCokeProduct = _fixture.Create <Product>();
            var cut             = new InMemoryProductRepository();

            cut.AddProduct(testCokeProduct);
            var actual = cut.GetProductByProductCode(testCokeProduct.ProductCode);

            actual.Should().NotBeNull();
            actual.Should().Be(testCokeProduct);
        }
Exemplo n.º 8
0
        public void CreateProductInRepository()
        {
            InMemoryProductRepository productRepository = new InMemoryProductRepository();
            ProductController         productController = GetProductController(productRepository);
            tbl_Product product = GetProductID();

            productController.CreateProduct(product);
            IEnumerable <tbl_Product> products = productRepository.ProductList();

            Assert.IsTrue(products.Contains(product));
        }
Exemplo n.º 9
0
        public void InMemoryProductRepository_should_init_the_Product()
        {
            var cut = new InMemoryProductRepository();

            cut.Init();

            var actual   = cut.GetProducts();
            var products = actual.ToList();

            products.Should().NotBeNull();
            products.Count().Should().BeGreaterThan(0);
        }
Exemplo n.º 10
0
        public void InMemoryProductRepository_should_throw_the_Argument_Exception_When_Price_Is_negative_or_zero(decimal price)
        {
            var testProduct = _fixture.Create <Product>();

            void Action()
            {
                var cut = new InMemoryProductRepository();

                testProduct.Price = price;

                cut.AddProduct(testProduct);
            }

            Assert.Throws <ArgumentException>((Action)Action);
        }
Exemplo n.º 11
0
        public void InMemoryProductRepository_should_throw_the_Argument_Exception_When_Quantity_Is_negative_or_zero(int quantity)
        {
            var testProduct = _fixture.Create <Product>();

            void Action()
            {
                var cut = new InMemoryProductRepository();

                testProduct.Quantity = quantity;

                cut.AddProduct(testProduct);
            }

            Assert.Throws <ArgumentException>((Action)Action);
        }
Exemplo n.º 12
0
        public void InMemoryProductRepository_should_throw_the_Argument_Exception_When_description_Is_Null_or_empty(string description)
        {
            var testProduct = _fixture.Create <Product>();

            void Action()
            {
                var cut = new InMemoryProductRepository();

                testProduct.Description = description;

                cut.AddProduct(testProduct);
            }

            Assert.Throws <ArgumentException>((Action)Action);
        }
Exemplo n.º 13
0
        public void GetAllProductFromRepository()
        {
            // Arrange
            tbl_Product product1 = GetProductName(52, "Samsung TV");
            tbl_Product product2 = GetProductName(53, "Apple iPhone XS");
            InMemoryProductRepository productRepository = new InMemoryProductRepository();

            productRepository.Add(product1);
            productRepository.Add(product2);
            var controller = GetProductController(productRepository);
            var result     = controller.ProductList();
            var datamodel  = (IEnumerable <tbl_Product>)result;

            CollectionAssert.Contains(datamodel.ToList(), product1);
            CollectionAssert.Contains(datamodel.ToList(), product2);
        }
Exemplo n.º 14
0
        public void ValidInput_ShouldCreateTheProduct()
        {
            // Arrange
            var repository = new InMemoryProductRepository();
            var sut        = new CreateUseCase(repository);

            var input = new CreateInput {
                Name = "Name", Description = "Description"
            };

            // Act
            Action action = () => sut.Execute(input);

            // Assert
            action
            .Should()
            .NotThrow();
        }
Exemplo n.º 15
0
        public void RepositoryThrowsException()
        {
            // Arrange
            InMemoryProductRepository productRepository = new InMemoryProductRepository();
            Exception exception = new Exception();

            productRepository.ExceptionToThrow = exception;
            ProductController controller = GetProductController(productRepository);
            tbl_Product       product    = GetProductID();
            var result = (ViewResult)controller.CreateProduct(product);

            Assert.AreEqual("CreateProduct", result.ViewName);
            ModelState modelState = result.ViewData.ModelState[""];

            Assert.IsNotNull(modelState);
            Assert.IsTrue(modelState.Errors.Any());
            Assert.AreEqual(exception, modelState.Errors[0].Exception);
        }
Exemplo n.º 16
0
        private InMemoryProductRepository CreateRoteRepository()
        {
            var repo = new InMemoryProductRepository(new List <Product> {
                new Product {
                    Id = 1, Name = "Имя1", ExpectedEffects = "Ожидаемые эффекты1", Indicators = "Показатели1", Specifications = "Технические характеристики1", Tasks = "Задачи1"
                },
                new Product {
                    Id = 2, Name = "Имя2", ExpectedEffects = "Ожидаемые эффекты2", Indicators = "Показатели2", Specifications = "Технические характеристики2", Tasks = "Задачи2"
                },
                new Product {
                    Id = 3, Name = "Имя3", ExpectedEffects = "Ожидаемые эффекты3", Indicators = "Показатели3", Specifications = "Технические характеристики3", Tasks = "Задачи3"
                },
                new Product {
                    Id = 4, Name = "Имя4", ExpectedEffects = "Ожидаемые эффекты4", Indicators = "Показатели4", Specifications = "Технические характеристики4", Tasks = "Задачи4"
                },
            });

            return(repo);
        }
        public static IProducts CreateProductRepository()
        {
            string mode = ConfigurationManager.AppSettings["Mode"].ToString();

            IProducts repo;

            switch (mode.ToUpper())
            {
            case "TEST":
                repo = new InMemoryProductRepository();
                break;

            case "PROD":
                repo = new FileProductRepository();
                break;

            default:
                throw new Exception("No such repository, check your settings");
            }
            return(repo);
        }
Exemplo n.º 18
0
        public void InMemoryProductRepository_should_Return_the_product_by_filter_product_code()
        {
            var testCokeProduct = new Product()
            {
                ProductCode = "COKE",
                Name        = "Coke",
                OrderNumber = 1,
                ActualCost  = 1.25M,
                Price       = 1.25M,
                Description = "Diet Coke",
                Quantity    = 10
            };

            var cut = new InMemoryProductRepository();

            cut.Init();

            var actual = cut.GetProductByProductCode("COKE");

            actual.Should().NotBeNull();

            actual.Should().Be(testCokeProduct);
        }
Exemplo n.º 19
0
        private IProductRepository GetEmptyProductRepository()
        {
            var repository = new InMemoryProductRepository();

            return(repository);
        }