Exemplo n.º 1
0
        public void Start_WhenInputFormatIsValidAddToShoppingCartCommand_ShouldAddProductToTheShoppingCart()
        {
            //Arrange
            var productName = "Fa Shampoo";

            var mockedFactory = new Mock<ICosmeticsFactory>();
            var mockedShoppingCart = new Mock<IShoppingCart>();
            var mockedCommandParser = new Mock<ICommandParser>();

            var mockedCommand = new Mock<ICommand>();
            var mockedProduct = new Mock<IProduct>();

            mockedCommand.SetupGet(x => x.Name).Returns("AddToShoppingCart");
            mockedCommand.SetupGet(x => x.Parameters).Returns(new List<string>() { productName });

            mockedCommandParser.Setup(p => p.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object });

            var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object);

            engine.Products.Add(productName, mockedProduct.Object);

            //Act
            engine.Start();

            //Assert
            mockedShoppingCart.Verify(x => x.AddProduct(mockedProduct.Object), Times.Once);
        }
        public void Start_WhenInputStringIsValidAddToCategoryCommand_ProductShouldBeAddedToCategory()
        {
            // Arrange
            var categoryName = "ForMale";
            var productName = "White+";

            var mockedFactory = new Mock<ICosmeticsFactory>();
            var mockedShoppingCart = new Mock<IShoppingCart>();
            var mockedCommandParser = new Mock<ICommandParser>();

            var mockedCategory = new Mock<ICategory>();
            var mockedShampoo = new Mock<IShampoo>();
            var mockedCommand = new Mock<ICommand>();

            mockedCommand.SetupGet(x => x.Name).Returns("AddToCategory");
            mockedCommand.SetupGet(x => x.Parameters).Returns(new List<string>() { categoryName, productName });
            mockedCommandParser.Setup(p => p.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object });

            var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object);
            engine.Categories.Add(categoryName, mockedCategory.Object);
            engine.Products.Add(productName, mockedShampoo.Object);

            // Act
            engine.Start();

            // Assert
            mockedCategory.Verify(x => x.AddProduct(mockedShampoo.Object), Times.Once);
        }
Exemplo n.º 3
0
        public void Start_WhenInputFormatIsValidCreateCategoryCommand_ShouldAddNewCategoryToCategoriesList()
        {
            //Arrange
            var categoryName = "ForFemale";

            var mockedFactory = new Mock<ICosmeticsFactory>();
            var mockedShoppingCart = new Mock<IShoppingCart>();
            var mockedCommandParser = new Mock<ICommandParser>();

            var mockedCommand = new Mock<ICommand>();
            var mockedCategory = new Mock<ICategory>();

            mockedCommand.SetupGet(x => x.Name).Returns("CreateCategory");
            mockedCommand.SetupGet(x => x.Parameters).Returns(new List<string>() { categoryName });

            mockedCommandParser.Setup(p => p.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object });

            mockedCategory.SetupGet(x => x.Name).Returns(categoryName);

            mockedFactory.Setup(x => x.CreateCategory(categoryName)).Returns(mockedCategory.Object);

            var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object);

            //Act
            engine.Start();

            //Assert
            Assert.IsTrue(engine.Categories.ContainsKey(categoryName));
            Assert.AreSame(mockedCategory.Object, engine.Categories[categoryName]);
        }
Exemplo n.º 4
0
        public void Start_WhenInputFormatIsValidCreateToothpasteCommand_ShouldAddToothpasteToProducts()
        {
            //Arrange
            var toothpasteName = "Maraslavin";
            var brandName = "Aroma";

            var mockedFactory = new Mock<ICosmeticsFactory>();
            var mockedShoppingCart = new Mock<IShoppingCart>();
            var mockedCommandParser = new Mock<ICommandParser>();

            var mockedCommand = new Mock<ICommand>();
            var mockedToothpaste = new Mock<IToothpaste>();

            mockedCommand.SetupGet(x => x.Name).Returns("CreateToothpaste");
            mockedCommand.SetupGet(x => x.Parameters).Returns(new List<string>() { toothpasteName, brandName, "2.58", "women", "sealye, fluoride" });

            mockedCommandParser.Setup(p => p.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object });

            mockedFactory.Setup(x => x.CreateToothpaste
                (toothpasteName, brandName, 2.58M, GenderType.Women,
                new List<string>() {"sealye", "fluoride"})).Returns(mockedToothpaste.Object);

            var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object);

            engine.Products.Add(toothpasteName, mockedToothpaste.Object);

            //Act
            engine.Start();

            //Assert
            Assert.IsTrue(engine.Products.ContainsKey(toothpasteName));
            Assert.AreSame(mockedToothpaste.Object, engine.Products[toothpasteName]);
        }
Exemplo n.º 5
0
        public void Start_WhenInputFormatIsValidCreateShampooCommand_ShouldAddShampooToProducts()
        {
            //Arrange
            var shampooName = "Rose";
            var brandName = "Lavera";

            var mockedFactory = new Mock<ICosmeticsFactory>();
            var mockedShoppingCart = new Mock<IShoppingCart>();
            var mockedCommandParser = new Mock<ICommandParser>();

            var mockedCommand = new Mock<ICommand>();
            var mockedShampoo = new Mock<IShampoo>();

            mockedCommand.SetupGet(x => x.Name).Returns("CreateShampoo");
            mockedCommand.SetupGet(x => x.Parameters).Returns(new List<string>() { shampooName, brandName, "5.50", "women", "250", "EveryDay"});

            mockedCommandParser.Setup(p => p.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object });

            mockedFactory.Setup(x=>x.CreateShampoo
                (shampooName, brandName, 5.50M, GenderType.Women, 250, UsageType.EveryDay )).Returns(mockedShampoo.Object);

            var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object);

            engine.Products.Add(shampooName, mockedShampoo.Object);

            //Act
            engine.Start();

            //Assert
            Assert.IsTrue(engine.Products.ContainsKey(shampooName));
            Assert.AreSame(mockedShampoo.Object, engine.Products[shampooName]);
        }
        public void Start_WhenInputStringIsValidShowCategoryCommand_RespectiveCategoryPrintMethodShouldBeInvoked()
        {
            // Arrange
            var categoryName = "ForMale";

            var mockedFactory = new Mock<ICosmeticsFactory>();
            var mockedShoppingCart = new Mock<IShoppingCart>();
            var mockedCommandParser = new Mock<ICommandParser>();

            var mockedCategory = new Mock<ICategory>();
            var mockedCommand = new Mock<ICommand>();

            mockedCommand.SetupGet(x => x.Name).Returns("ShowCategory");
            mockedCommand.SetupGet(x => x.Parameters).Returns(new List<string>() { categoryName });
            mockedCommandParser.Setup(p => p.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object });

            var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object);
            engine.Categories.Add(categoryName, mockedCategory.Object);

            // Act
            engine.Start();

            // Assert
            mockedCategory.Verify(x => x.Print(), Times.Once);
        }
        public void Start_WhenInputStringIsValidRemoveFromShoppingCartCommand_ProductShouldBeRemovedFromShoppingCart()
        {
            // Arrange
            var productName = "White+";

            var mockedFactory = new Mock<ICosmeticsFactory>();
            var mockedShoppingCart = new Mock<IShoppingCart>();
            var mockedCommandParser = new Mock<ICommandParser>();

            var mockedProduct = new Mock<IProduct>();
            var mockedCommand = new Mock<ICommand>();

            mockedCommand.SetupGet(x => x.Name).Returns("RemoveFromShoppingCart");
            mockedCommand.SetupGet(x => x.Parameters).Returns(new List<string>() { productName });
            mockedCommandParser.Setup(p => p.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object });

            mockedShoppingCart.Setup(x => x.ContainsProduct(mockedProduct.Object)).Returns(true);

            var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object);
            engine.Products.Add(productName, mockedProduct.Object);

            // Act
            engine.Start();

            // Assert
            mockedShoppingCart.Verify(x => x.RemoveProduct(mockedProduct.Object), Times.Once);
        }
        public void Start_WhenInputStringIsValidCreateShampooCommand_ShampooShouldBeAddedToProducts()
        {
            // Arrange
            var shampooName = "Cool";
            var shampooBrand = "Nivea";

            var mockedFactory = new Mock<ICosmeticsFactory>();
            var mockedShoppingCart = new Mock<IShoppingCart>();
            var mockedCommandParser = new Mock<ICommandParser>();

            var mockedCommand = new Mock<ICommand>();
            var mockedShampoo = new Mock<IShampoo>();

            mockedCommand.SetupGet(x => x.Name).Returns("CreateShampoo");
            mockedCommand.SetupGet(x => x.Parameters).Returns(new List<string>() { shampooName, shampooBrand, "0.50", "men", "500", "everyday" });
            mockedCommandParser.Setup(p => p.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object });

            mockedFactory
                .Setup(x => x.CreateShampoo(shampooName, shampooBrand, 0.50M, GenderType.Men, 500, UsageType.EveryDay))
                .Returns(mockedShampoo.Object);

            var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object);

            // Act
            engine.Start();

            // Assert
            Assert.IsTrue(engine.Products.ContainsKey(shampooName));
            Assert.AreSame(mockedShampoo.Object, engine.Products[shampooName]);
        }
        public void Start_WhenInputStringIsValidCreateCreateToothpasteCommand_ToothpasteShouldBeAddedToProducts()
        {
            // Arrange
            var toothpasteName = "White+";
            var toothpasteBrand = "Colgate";

            var mockedFactory = new Mock<ICosmeticsFactory>();
            var mockedShoppingCart = new Mock<IShoppingCart>();
            var mockedCommandParser = new Mock<ICommandParser>();

            var mockedCommand = new Mock<ICommand>();
            var mockedToothpaste = new Mock<IToothpaste>();

            mockedCommand.SetupGet(x => x.Name).Returns("CreateToothpaste");
            mockedCommand.SetupGet(x => x.Parameters).Returns(new List<string>() { toothpasteName, toothpasteBrand, "15.50", "men", "fluor,bqla,golqma" });
            mockedCommandParser.Setup(p => p.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object });

            mockedFactory
                .Setup(x => x.CreateToothpaste(toothpasteName, toothpasteBrand, 15.50M, GenderType.Men, new List<string>() { "fluor", "bqla", "golqma" }))
                .Returns(mockedToothpaste.Object);

            var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object);

            // Act
            engine.Start();

            // Assert
            Assert.IsTrue(engine.Products.ContainsKey(toothpasteName));
            Assert.AreSame(mockedToothpaste.Object, engine.Products[toothpasteName]);
        }