示例#1
0
        public void Start_ShouldRemoveFromCategory_IfInputStringIsInValidFormat()
        {
            //Arrange
            var validInput = "RemoveFromCategory ForMale Nivea";

            Console.SetIn(new StringReader(validInput));

            var factoryMock      = new Mock <ICosmeticsFactory>();
            var shoppingCartMock = new Mock <IShoppingCart>();

            var cosmeticsEngine = new CosmeticsEngineExtended(factoryMock.Object, shoppingCartMock.Object);

            var categoryMock = new Mock <ICategory>();
            var productMock  = new Mock <IProduct>();

            categoryMock.SetupGet(x => x.Name).Returns("ForMale");
            productMock.SetupGet(x => x.Name).Returns("Nivea");

            cosmeticsEngine.Categories.Add(categoryMock.Object.Name, categoryMock.Object);
            cosmeticsEngine.Products.Add(productMock.Object.Name, productMock.Object);

            //Act
            cosmeticsEngine.Start();

            //Assert
            categoryMock.Verify(x => x.RemoveCosmetics(productMock.Object), Times.Once());
        }
示例#2
0
        public void Start_ShouldCreateShampoo_IfInputStringIsInValidFormat()
        {
            //Arrange
            var validInput = "CreateShampoo Hair Elseve 10.00 men 100 everyday";

            Console.SetIn(new StringReader(validInput));

            var factoryMock      = new Mock <ICosmeticsFactory>();
            var shoppingCartMock = new Mock <IShoppingCart>();

            var shampooMock = new Mock <IShampoo>();

            factoryMock.Setup(x => x.CreateShampoo(
                                  It.IsAny <string>(),
                                  It.IsAny <string>(),
                                  It.IsAny <decimal>(),
                                  It.IsAny <GenderType>(),
                                  It.IsAny <uint>(),
                                  It.IsAny <UsageType>()))
            .Returns(shampooMock.Object);

            var cosmeticsEngine = new CosmeticsEngineExtended(factoryMock.Object, shoppingCartMock.Object);

            //Act
            cosmeticsEngine.Start();

            //Assert
            Assert.IsTrue(cosmeticsEngine.Products.ContainsKey("Hair"));
            Assert.AreEqual(shampooMock.Object, cosmeticsEngine.Products["Hair"]);
        }
示例#3
0
        public void Start_ShouldCreateToothpaste_IfInputStringIsInValidFormat()
        {
            //Arrange
            var validInput = "CreateToothpaste White Lacalut 5.00 men igredientOne,igredientTwo";

            Console.SetIn(new StringReader(validInput));

            var factoryMock      = new Mock <ICosmeticsFactory>();
            var shoppingCartMock = new Mock <IShoppingCart>();

            var toothpasteMock = new Mock <IToothpaste>();

            factoryMock.Setup(x => x.CreateToothpaste(
                                  It.IsAny <string>(),
                                  It.IsAny <string>(),
                                  It.IsAny <decimal>(),
                                  It.IsAny <GenderType>(),
                                  It.IsAny <List <string> >()))
            .Returns(toothpasteMock.Object);

            var cosmeticsEngine = new CosmeticsEngineExtended(factoryMock.Object, shoppingCartMock.Object);

            //Act
            cosmeticsEngine.Start();

            //Assert
            Assert.IsTrue(cosmeticsEngine.Products.ContainsKey("White"));
            Assert.AreEqual(toothpasteMock.Object, cosmeticsEngine.Products["White"]);
        }
示例#4
0
        public void Start_ShouldReadParseExecuteCreateCategoryCommandAndThenAddItToTheListOfCategories_WhenProvidedValidInput()
        {
            // Arrange
            var command = "CreateCategory";
            var name    = "NameOfCategory";
            var cosmeticsFactoryMock = new Mock <ICosmeticsFactory>();
            var shoppingCartMock     = new Mock <IShoppingCart>();
            var commandMock          = new Mock <ICommand>();

            commandMock.Setup(c => c.Name).Returns(command);
            commandMock.Setup(c => c.Parameters).Returns(new List <string>()
            {
                name
            });

            var commandParserMock = new Mock <ICommandParser>();

            commandParserMock.Setup(c => c.ReadCommands()).Returns(new List <ICommand>()
            {
                commandMock.Object
            });

            var cosmeticsEngine = new CosmeticsEngineExtended(cosmeticsFactoryMock.Object, shoppingCartMock.Object, commandParserMock.Object);

            // Act
            cosmeticsEngine.Start();

            // Assert
            //Assert.AreEqual(1, cosmeticsEngine.CategoriesExposer.Count);
            Assert.IsTrue(cosmeticsEngine.CategoriesExposer.ContainsKey(name));
        }
示例#5
0
        public void Start_ShouldCreateCategory_IfInputStringIsInValidFormat()
        {
            //Arrange
            var validInput = "CreateCategory SomeCategory";

            Console.SetIn(new StringReader(validInput));

            var factoryMock      = new Mock <ICosmeticsFactory>();
            var shoppingCartMock = new Mock <IShoppingCart>();

            var cosmeticsEngine = new CosmeticsEngineExtended(factoryMock.Object, shoppingCartMock.Object);

            //Act
            cosmeticsEngine.Start();

            //Assert
            Assert.IsTrue(cosmeticsEngine.Categories.ContainsKey("SomeCategory"));
        }
示例#6
0
        public void Start_ShouldAddToShoppingCart_IfInputStringIsInValidFormat()
        {
            //Arrange
            var productKey = "Nivea";
            var validInput = $"AddToShoppingCart {productKey}";

            Console.SetIn(new StringReader(validInput));

            var factoryMock      = new Mock <ICosmeticsFactory>();
            var shoppingCartMock = new Mock <IShoppingCart>();

            var cosmeticsEngine = new CosmeticsEngineExtended(factoryMock.Object, shoppingCartMock.Object);

            cosmeticsEngine.Products.Add(productKey, It.IsAny <IProduct>());

            //Act
            cosmeticsEngine.Start();

            //Assert
            shoppingCartMock.Verify(x => x.AddProduct(It.IsAny <IProduct>()), Times.Once());
        }
示例#7
0
        public void Start_ShouldReadParseExecuteRemoveToCategoryCommandAndThenRemoveProductFromTheCategory_WhenProvidedValidInput()
        {
            // Arrange
            var command      = "RemoveFromCategory";
            var categoryName = "CategoryOne";
            var productName  = "AddProductName";

            var cosmeticsFactoryMock = new Mock <ICosmeticsFactory>();
            var shoppingCartMock     = new Mock <IShoppingCart>();
            var categoryMock         = new Mock <ICategory>();
            var productMock          = new Mock <IProduct>();

            var commandAddMock = new Mock <ICommand>();

            commandAddMock.Setup(c => c.Name).Returns(command);
            commandAddMock.Setup(c => c.Parameters).Returns(new List <string>()
            {
                categoryName, productName
            });

            var commandParserMock = new Mock <ICommandParser>();

            commandParserMock.Setup(c => c.ReadCommands()).Returns(new List <ICommand>()
            {
                commandAddMock.Object
            });

            var cosmeticsEngine = new CosmeticsEngineExtended(cosmeticsFactoryMock.Object, shoppingCartMock.Object, commandParserMock.Object);

            cosmeticsEngine.CategoriesExposer.Add(categoryName, categoryMock.Object);
            cosmeticsEngine.ProductsExposer.Add(productName, productMock.Object);

            // Act
            cosmeticsEngine.Start();

            // Assert
            categoryMock.Verify(x => x.RemoveProduct(productMock.Object), Times.Once);
        }
示例#8
0
        public void Start_ShouldReadParseExecuteRemoveFromShoppingCartCommandAndRemoveTheProductFromTheShoppingCart_WhenProvidedValidInput()
        {
            // Arrange
            var command     = "RemoveFromShoppingCart";
            var productName = "Product";

            var cosmeticsFactoryMock = new Mock <ICosmeticsFactory>();
            var shoppingCartMock     = new Mock <IShoppingCart>();

            shoppingCartMock.Setup(s => s.ContainsProduct(It.IsAny <IProduct>())).Returns(true);

            var productMock = new Mock <IProduct>();

            var commandRemoveFromShoppingCart = new Mock <ICommand>();

            commandRemoveFromShoppingCart.Setup(c => c.Name).Returns(command);
            commandRemoveFromShoppingCart.Setup(c => c.Parameters).Returns(new List <string>()
            {
                productName
            });

            var commandParserMock = new Mock <ICommandParser>();

            commandParserMock.Setup(c => c.ReadCommands()).Returns(new List <ICommand>()
            {
                commandRemoveFromShoppingCart.Object
            });

            var cosmeticsEngine = new CosmeticsEngineExtended(cosmeticsFactoryMock.Object, shoppingCartMock.Object, commandParserMock.Object);

            cosmeticsEngine.ProductsExposer.Add(productName, productMock.Object);

            // Act
            cosmeticsEngine.Start();

            // Assert
            shoppingCartMock.Verify(s => s.RemoveProduct(It.IsAny <IProduct>()), Times.Once);
        }
示例#9
0
        public void Start_ShouldReadParseExecuteCreateShampooCommandAndAddTheShampooToTheProducts_WhenProvidedValidInput()
        {
            // Arrange
            var command            = "CreateShampoo";
            var ShampooName        = "ShampooName";
            var shampooBrand       = "ShampooBrand";
            var shampooPrice       = "12.34";
            var shampooGender      = "men";
            var shampooMilliliters = "20";
            var shampooUsage       = "everyday";

            var cosmeticsFactoryMock = new Mock <ICosmeticsFactory>();
            var shoppingCartMock     = new Mock <IShoppingCart>();

            var commandCreateShampooMock = new Mock <ICommand>();

            commandCreateShampooMock.Setup(c => c.Name).Returns(command);
            commandCreateShampooMock.Setup(c => c.Parameters).Returns(new List <string>()
            {
                ShampooName, shampooBrand, shampooPrice, shampooGender, shampooMilliliters, shampooUsage
            });

            var commandParserMock = new Mock <ICommandParser>();

            commandParserMock.Setup(c => c.ReadCommands()).Returns(new List <ICommand>()
            {
                commandCreateShampooMock.Object
            });

            var cosmeticsEngine = new CosmeticsEngineExtended(cosmeticsFactoryMock.Object, shoppingCartMock.Object, commandParserMock.Object);

            // Act
            cosmeticsEngine.Start();

            // Assert
            Assert.True(cosmeticsEngine.ProductsExposer.ContainsKey(ShampooName));
        }
示例#10
0
        public void Start_ShouldReadParseExecuteCreateToothpasteCommandAndAddTheToothpasteToTheProducts_WhenProvidedValidInput()
        {
            // Arrange
            var command               = "CreateToothpaste";
            var toothpasteName        = "Tooth";
            var toothpasteBrand       = "ToothBrand";
            var toothpastePrice       = "12.34";
            var toothpasteGender      = "men";
            var toothpasteIngrediends = "IngrediendOne, IngrediendTwo, IngrediendThree";

            var cosmeticsFactoryMock = new Mock <ICosmeticsFactory>();
            var shoppingCartMock     = new Mock <IShoppingCart>();

            var commandCreateToothpasteMock = new Mock <ICommand>();

            commandCreateToothpasteMock.Setup(c => c.Name).Returns(command);
            commandCreateToothpasteMock.Setup(c => c.Parameters).Returns(new List <string>()
            {
                toothpasteName, toothpasteBrand, toothpastePrice, toothpasteGender, toothpasteIngrediends
            });

            var commandParserMock = new Mock <ICommandParser>();

            commandParserMock.Setup(c => c.ReadCommands()).Returns(new List <ICommand>()
            {
                commandCreateToothpasteMock.Object
            });

            var cosmeticsEngine = new CosmeticsEngineExtended(cosmeticsFactoryMock.Object, shoppingCartMock.Object, commandParserMock.Object);

            // Act
            cosmeticsEngine.Start();

            // Assert
            Assert.True(cosmeticsEngine.ProductsExposer.ContainsKey(toothpasteName));
        }