public void GetProduct()
        {
            //Given: a product
            var p1 = new Product()
            {
                Id            = Guid.NewGuid(),
                Name          = "Golf Clubs",
                CatalogueId   = Guid.NewGuid(),
                CatalogueName = "Sports"
            };

            var mockService = new MockProductService(new List <Product> {
                p1
            });

            //When:
            var controller = new ProductsController(mockService);
            var result     = controller.GetProduct(p1.Id);

            //Then:
            var okResult    = Assert.IsType <OkObjectResult>(result);
            var returnValue = Assert.IsType <Product>(okResult.Value);

            Assert.Same(p1, returnValue);
        }
        public void GetProducts()
        {
            //Given: some products
            var catalogueId = Guid.NewGuid();

            var p1 = new Product()
            {
                Id            = Guid.NewGuid(),
                Name          = "Golf Clubs",
                CatalogueId   = catalogueId,
                CatalogueName = "Sports"
            };

            var p2 = new Product()
            {
                Id            = Guid.NewGuid(),
                Name          = "Soccer Ball",
                CatalogueId   = catalogueId,
                CatalogueName = "Sports"
            };

            var mockService = new MockProductService(new List <Product> {
                p1, p2
            });

            //When:
            var controller = new ProductsController(mockService);
            var result     = controller.GetProducts(catalogueId);

            //Then:
            var okResult    = Assert.IsType <OkObjectResult>(result);
            var returnValue = Assert.IsType <List <Product> >(okResult.Value);

            Assert.Same(mockService.Products, returnValue);
        }
            public void SetsDtoValuesFromUri()
            {
                // Arrange
                const string expectedProductKey   = "p12345";
                const string expectedAttributeKey = "asta";
                var          postData             = new SetChileProductAttributeRangesRequest
                {
                    AttributeRanges = new List <AttributeRangeRequest>
                    {
                        new AttributeRangeRequest
                        {
                            AttributeNameKey = expectedAttributeKey
                        }
                    }
                };
                ISetChileProductAttributeRangesParameters actualParams = null;

                MockProductService.Setup(
                    m => m.SetChileProductAttributeRanges(It.IsAny <ISetChileProductAttributeRangesParameters>()))
                .Callback((ISetChileProductAttributeRangesParameters p) => actualParams = p)
                .Returns(new SuccessResult());

                // Act
                SystemUnderTest.Post(expectedProductKey, postData);

                // Assert
                Assert.AreEqual(expectedProductKey, actualParams.ChileProductKey);
                Assert.AreEqual(expectedAttributeKey, actualParams.AttributeRanges.Single().AttributeNameKey);
            }
Пример #4
0
        public static void RegisterServices(this IContainerRegistry containerRegistry,
                                            IContainerProvider provider,
                                            INavigationService navigation)
        {
            containerRegistry.RegisterSingleton <IShoppingCartService, ShoppingCartService>();

            var api = new WooComerceApi(websiteRoot: eCommerce.Helpers.Secrets.Website,
                                        client: eCommerce.Helpers.Secrets.ClientId,
                                        secret: eCommerce.Helpers.Secrets.ClientSecret);

            containerRegistry.RegisterInstance(api);

            var productService =             //new ProductService(api);
                                 new MockProductService();

            // Products
            containerRegistry.RegisterInstance <IHttpFactory <Product> >(productService);
            containerRegistry.RegisterInstance <IProductService>(productService);

            // Tags
            containerRegistry.RegisterSingleton <IHttpFactory <ProductTag>, ProductTagService>();
            //new MockHttpFactory<ProductTag>("/products/tags")
            //);

            // Categories
            containerRegistry.RegisterSingleton <IHttpFactory <ProductCategory>,
                                                 MockHttpFactory <ProductCategory> >();
            //ProductCategoryService>();
        }
Пример #5
0
        public OrderControllerTest()
        {
            orderService = MockOrderService.GetOrderService();
            mapper       = new Mapper(MockProductService.GetProductService());
            var logger = new MockLogger <OrderController>().CreateLogger();

            orderController = new OrderController(orderService, mapper, logger);
        }
        public void InitMVP()
        {
            view           = new MockSearchProduct();
            productService = new MockProductService();
            presenter      = new SearchProductPresenter(productService);

            presenter.View = view;
        }
Пример #7
0
        public void Can_Create_A_Product()
        {
            var service = new MockProductService();
            var product = service.CreateProduct("1111", "Rusty's product", 12M);

            Assert.NotNull(product);
            Assert.IsFalse(product.HasIdentity);
            Assert.IsFalse(((Product)product).MasterVariant.HasIdentity);
        }
Пример #8
0
 public ProductControllerTest()
 {
     _testProduct = new Product()
     {
         Id = _testProductId, Name = "Carot", Category = ProductCategory.Vegetable
     };
     _mockService = new MockProductService();
     _controller  = GetProductsController(_mockService);
 }
Пример #9
0
 public void InitMVP()
 {
     view                  = new MockDetails();
     controller            = new MockOrdersController();
     productService        = new MockProductService();
     orderDetailsConverter = new OrderDetailsConverter(productService);
     presenter             = new OrderDetailsPresenter(controller, productService, orderDetailsConverter);
     presenter.View        = view;
 }
Пример #10
0
 public void InitMVP()
 {
     productService        = new MockProductService();
     customerService       = new MockCustomerService();
     employeeService       = new MockEmployeeService();
     employeeConverter     = new MockGenericConverter <Employee, EmployeeDisplay>();
     ordersConverter       = new MockGenericConverter <Order, OrderInfo>();
     orderDetailsConverter = new OrderDetailsConverter(productService);
     view           = new MockOrderPreviewPart();
     presenter      = new OrderPreviewPresenter(ordersConverter, orderDetailsConverter);
     presenter.View = view;
 }
            public void CallsServiceMethodAsExpected()
            {
                // Arrange
                const string expectedProductKey = "p12345";
                var          postData           = Fixture.Create <SetChileProductAttributeRangesRequest>();

                // Act
                SystemUnderTest.Post(expectedProductKey, postData);

                // Assert
                MockProductService.Verify(m => m.SetChileProductAttributeRanges(It.IsAny <ISetChileProductAttributeRangesParameters>()), Times.Once());
            }
            public void Returns201_OnSuccess()
            {
                // Arrange
                MockProductService.Setup(m => m.SetChileProductIngredients(It.IsAny <ISetChileProductIngredientsParameters>()))
                .Returns(new SuccessResult <string>());

                var input = Fixture.Create <SetChileProductIngredientsRequest>();

                // Act
                var result = SystemUnderTest.Post("key", input);

                // Assert
                Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
            }
Пример #13
0
        private ProductsController GetProductsController(MockProductService mockProductService)
        {
            var authService = MockAuthorizationService.BuildAuthorizationService(services =>
            {
                services.AddScoped <IProductService>(sp => mockProductService.Object);
                services.AddScoped <IAuthorizationHandler, AdminAuthorizationHandler>();
            });

            var controller = new ProductsController(mockProductService.Object, authService);

            MockAuthorizationService.SetupUserWithRole(controller, Constants.UserAdministratorsRole);

            return(controller);
        }
            public void CallsSetChileProductIngredientMethod()
            {
                // Arrange
                MockProductService.Setup(m => m.SetChileProductIngredients(It.IsAny <ISetChileProductIngredientsParameters>()))
                .Returns(new SuccessResult <string>());

                const string key   = "12345";
                var          input = Fixture.Create <SetChileProductIngredientsRequest>();

                // Act
                SystemUnderTest.Post(key, input);

                // Assert
                MockProductService.Verify(m => m.SetChileProductIngredients(It.IsAny <ISetChileProductIngredientsParameters>()), Times.Once());
            }
            public void Returns500OnFailure()
            {
                // Arrange
                const string expectedProductKey = "p12345";
                var          postData           = Fixture.Create <SetChileProductAttributeRangesRequest>();

                MockProductService.Setup(m => m.SetChileProductAttributeRanges(It.IsAny <ISetChileProductAttributeRangesParameters>()))
                .Returns(new FailureResult());

                // Act
                var response = SystemUnderTest.Post(expectedProductKey, postData);

                // Assert
                Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
            }
        public void GetProduct_NotFound()
        {
            //Given: no product
            var mockService = new MockProductService(new List <Product>());

            //When:
            var productId  = Guid.NewGuid();
            var controller = new ProductsController(mockService);
            var result     = controller.GetProduct(productId);

            //Then:
            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result);

            Assert.Equal(productId, notFoundObjectResult.Value);
        }
            public void Returns500_OnFailure()
            {
                // Arrange
                const string message = "Error Message";

                MockProductService.Setup(m => m.SetChileProductIngredients(It.IsAny <ISetChileProductIngredientsParameters>()))
                .Returns(new FailureResult <string>(null, message));

                var input = Fixture.Create <SetChileProductIngredientsRequest>();

                // Act
                var result = SystemUnderTest.Post("key", input);

                // Assert
                Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
                Assert.AreEqual(message, result.ReasonPhrase);
            }
            public void UtilizesUserIdentityProvider()
            {
                // Arrange
                const string expectedProductKey = "p12345";
                var          postData           = Fixture.Create <SetChileProductAttributeRangesRequest>();
                ISetChileProductAttributeRangesParameters actual = null;

                MockProductService.Setup(m => m.SetChileProductAttributeRanges(It.IsAny <ISetChileProductAttributeRangesParameters>()))
                .Callback((ISetChileProductAttributeRangesParameters param) => actual = param)
                .Returns(new SuccessResult());

                // Act
                SystemUnderTest.Post(expectedProductKey, postData);

                // Assert
                Assert.IsNotNull(actual);
                UserIdentityProviderMock.Verify(m => m.SetUserIdentity(actual), Times.Once());
            }
            public void SetsUserTokenFromUserIdentityProvider()
            {
                // Arrange
                ISetChileProductIngredientsParameters actualParams = null;

                MockProductService.Setup(m => m.SetChileProductIngredients(It.IsAny <ISetChileProductIngredientsParameters>()))
                .Callback((ISetChileProductIngredientsParameters p) => actualParams = p)
                .Returns(new SuccessResult <string>());

                const string expectedUserToken = "user13";

                MockUserTokenProvider.Setup(m => m.SetUserIdentity(It.IsAny <IUserIdentifiable>()))
                .Callback((IUserIdentifiable o) => o.UserToken = expectedUserToken);

                // Act
                SystemUnderTest.Post("2134", Fixture.Create <SetChileProductIngredientsRequest>());

                // Assert
                Assert.AreEqual(expectedUserToken, actualParams.UserToken);
                MockUserTokenProvider.Verify(m => m.SetUserIdentity(It.IsAny <IUserIdentifiable>()), Times.Once());
            }
            public void TranslatesDtoIntoServiceParameter()
            {
                // Arrange
                ISetChileProductIngredientsParameters actualParams = null;

                MockProductService.Setup(m => m.SetChileProductIngredients(It.IsAny <ISetChileProductIngredientsParameters>()))
                .Callback((ISetChileProductIngredientsParameters p) => actualParams = p)
                .Returns(new SuccessResult <string>());

                const string expectedUserToken = "user13";

                MockUserTokenProvider.Setup(m => m.SetUserIdentity(It.IsAny <IUserIdentifiable>()))
                .Callback((IUserIdentifiable o) => o.UserToken = expectedUserToken);

                const string expectedKey = "123";
                var          param       = Fixture.Create <SetChileProductIngredientsRequest>();

                // Act
                SystemUnderTest.Post(expectedKey, param);

                // Assert
                Assert.AreEqual(expectedKey, actualParams.ChileProductKey);
                Assert.AreEqual(expectedUserToken, actualParams.UserToken);
            }
 public new void SetUp()
 {
     MockProductService
     .Setup(m => m.SetChileProductAttributeRanges(It.IsAny <ISetChileProductAttributeRangesParameters>()))
     .Returns(new SuccessResult <string>(null));
 }