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_WhenInputStringIsValid_RemoveFromShoppingCartCommand_ShouldCallRemoveProductMethodOnce() { var productName = "White+"; var mockedFactory = new Mock <ICosmeticsFactory>(); var mockedShoppingCart = new Mock <IShoppingCart>(); var mockedCommandParser = new Mock <ICommandParser>(); var mockedProduct = new Mock <IToothpaste>(); var mockedCommand = new Mock <ICommand>(); mockedCommand.SetupGet(x => x.Name).Returns("RemoveFromShoppingCart"); mockedCommand.SetupGet(x => x.Parameters).Returns(new List <string>() { productName }); mockedCommandParser.Setup(x => x.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); engine.Start(); mockedShoppingCart.Verify(x => x.RemoveProduct(mockedProduct.Object), Times.Once); }
public void Start_WhenInputStringIsValidRemoveFromCategoryCommand_ShouldCallRemoveProductMethodOnce() { 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 mockedProduct = new Mock <IProduct>(); var mockedCommand = new Mock <ICommand>(); mockedCommand.SetupGet(x => x.Name).Returns("RemoveFromCategory"); mockedCommand.SetupGet(x => x.Parameters).Returns(new List <string>() { categoryName, productName }); mockedCommandParser.Setup(x => x.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, mockedProduct.Object); engine.Start(); mockedCategory.Verify(x => x.RemoveProduct(mockedProduct.Object), Times.Once); }
public void TestStart_PassValidCreateShampoo_ShouldCreateSHampoo(string name, string brand) { 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>() { name, brand, "0.50", "men", "500", "everyday" }); mockedCommandParser .Setup(x => x.ReadCommands()).Returns(() => new List <ICommand>() { mockedCommand.Object }); mockedFactory .Setup(x => x.CreateShampoo(name, brand, 0.50M, GenderType.Men, 500, UsageType.EveryDay)) .Returns(mockedShampoo.Object); var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object); engine.Start(); Assert.IsTrue(engine.Products.ContainsKey(name)); Assert.AreSame(mockedShampoo.Object, engine.Products[name]); }
public void Start_WhenInputStringIsValidRemoveFromCategoryCommand_ProductShouldBeRemovedFromCategory() { // 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("RemoveFromCategory"); 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.RemoveProduct(mockedShampoo.Object), Times.Once); }
public void TestStart_PassValidCreateCategory_ShouldCreateCategory(string categoryName) { 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(x => x.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); engine.Start(); Assert.IsTrue(engine.Categories.ContainsKey(categoryName)); Assert.AreSame(mockedCategory.Object, engine.Categories[categoryName]); }
public void TestStart_PassValidCreateToothpaste_ShouldCreateToothpaste(string name, string brand) { 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>() { name, brand, "15.50", "men", "fluor,bqla,golqma" }); mockedCommandParser .Setup(x => x.ReadCommands()).Returns(() => new List <ICommand>() { mockedCommand.Object }); mockedFactory .Setup(x => x.CreateToothpaste(name, brand, 15.50M, GenderType.Men, new List <string>() { "fluor", "bqla", "golqma" })) .Returns(mockedToothpaste.Object); var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object); engine.Start(); Assert.IsTrue(engine.Products.ContainsKey(name)); Assert.AreSame(mockedToothpaste.Object, engine.Products[name]); }
public void TestStart_PassValidRemoveFromShoppingCart_ShouldRemoveFromCart(string name) { 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("RemoveFromShoppingCart"); mockedCommand .SetupGet(x => x.Parameters).Returns(new List <string>() { name }); mockedCommandParser .Setup(x => x.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(name, mockedProduct.Object); engine.Start(); mockedShoppingCart.Verify(x => x.RemoveProduct(mockedProduct.Object), Times.Once); }
public void TestStart_PassValidRemoveFromCategory_ShouldRemoveFromCategory(string categoryName, string productName) { 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>(); var mockedCategory = new Mock <ICategory>(); mockedCommand.SetupGet(x => x.Name).Returns("RemoveFromCategory"); mockedCommand.SetupGet(x => x.Parameters).Returns(new List <string>() { categoryName, productName }); mockedCommandParser.Setup(x => x.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); engine.Start(); mockedCategory.Verify(x => x.RemoveProduct(mockedShampoo.Object), Times.Once); }
public void Start_WhenInputFormatIsValidRemoveFromShoppingCartCommand_ShouldRemoveProductFromTheShoppingCart() { //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("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_WhenInputStringIsValidCreateCategoryCommand_CategoryShouldBeAddedToList() { // Arrange var categoryName = "ForMale"; 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]); }
public void Start_WhenInputStringIsValidAddToShoppingCartCommand_ProductShouldBeAddedToShoppingCart() { // 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("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 RemoveFromCategory_WhenInputStrignIsValidRemoveFromCategoryFormat_ShouldRemoveProductFromCategory() { string commandName = "RemoveFromCategory"; string categoryName = "ForMale"; string productName = "Shamponachetuu"; var factoryStub = new Mock <ICosmeticsFactory>(); var commandParserStub = new Mock <ICommandParser>(); var shoppingCartStub = new Mock <IShoppingCart>(); var commandStub = new Mock <ICommand>(); var categoryMock = new Mock <ICategory>(); var shampooStub = new Mock <IShampoo>(); // setting fake product shampooStub.SetupGet(x => x.Name).Returns(productName); // setting fake category categoryMock.Setup(x => x.Name).Returns(categoryName); categoryMock.Setup(x => x.AddProduct(It.IsAny <IProduct>())).Verifiable(); // setting fake command commandStub.SetupGet(x => x.Name).Returns(commandName); commandStub.SetupGet(x => x.Parameters) .Returns(new List <string>() { categoryName, productName }); // setting fakse commandParser commandParserStub.Setup(x => x.ReadCommands()) .Returns(new List <ICommand>() { commandStub.Object }); var engine = new MockedCosmeticsEngine( factoryStub.Object, shoppingCartStub.Object, commandParserStub.Object ); engine.Products.Add(productName, shampooStub.Object); engine.Categories.Add(categoryName, categoryMock.Object); // engine.Categories[categoryName].AddProduct(shampooStub.Object); engine.Start(); categoryMock.Verify(x => x.RemoveProduct(It.IsAny <IProduct>()), Times.Once); }
public void Start_WhenInputStringIsValid_CreateToothpasteCommand_ShouldAddNewToothpasteToListOfProducts() { var toothpasteName = "White+"; var toothpasteBrand = "Nivea"; var toothpastePrice = "0.5"; var toothpasteGender = "men"; var toothpasteIngredients = "fluor,bqla,golqma"; var mockedFactory = new Mock <ICosmeticsFactory>(); var mockedShoppingCart = new Mock <IShoppingCart>(); var mockedCommandParser = new Mock <ICommandParser>(); var mockedtoothpaste = new Mock <IToothpaste>(); var mockedCommand = new Mock <ICommand>(); mockedCommand.SetupGet(x => x.Name).Returns("CreateToothpaste"); mockedCommand.SetupGet(x => x.Parameters).Returns(new List <string>() { toothpasteName, toothpasteBrand, toothpastePrice, toothpasteGender, toothpasteIngredients }); mockedCommandParser.Setup(x => x.ReadCommands()).Returns(new List <ICommand>() { mockedCommand.Object }); mockedFactory.Setup( x => x.CreateToothpaste(toothpasteName, toothpasteBrand, 0.5M, GenderType.Men, new List <string>() { "fluor", "bqla", "golqma" })) .Returns(mockedtoothpaste.Object); var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object); engine.Start(); mockedFactory.Verify( x => x.CreateToothpaste(toothpasteName, toothpasteBrand, 0.5M, GenderType.Men, new List <string>() { "fluor", "bqla", "golqma" }), Times.Once); Assert.IsTrue(engine.Products.ContainsKey(toothpasteName)); Assert.AreSame(mockedtoothpaste.Object, engine.Products[toothpasteName]); }
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]); }
public void CreateShampoo_WhenInputStringIsInCorrectCreateShampooFormat_ShouldAddShampooInProducts() { // arrange string commandName = "CreateShampoo"; var factoryStub = new Mock <ICosmeticsFactory>(); var commandParserStub = new Mock <ICommandParser>(); var shoppingCartStub = new Mock <IShoppingCart>(); var commandStub = new Mock <ICommand>(); var shampooStub = new Mock <IShampoo>(); shampooStub.SetupGet(x => x.Name).Returns("ShampoanchetoBrat"); commandStub.SetupGet(x => x.Name).Returns(commandName); commandStub.SetupGet(x => x.Parameters) .Returns(new List <string> { "Cool", "Nivea", "0.50", "men", "500", "everyday" }); commandParserStub.Setup(x => x.ReadCommands()) .Returns(new List <ICommand>() { commandStub.Object }); factoryStub.Setup(x => x.CreateShampoo("Cool", "Nivea", 0.50M, GenderType.Men, 500, UsageType.EveryDay)) .Returns(shampooStub.Object); var engine = new MockedCosmeticsEngine( factoryStub.Object, shoppingCartStub.Object, commandParserStub.Object ); // act engine.Start(); // assert Assert.AreEqual(1, engine.Products.Count); Assert.AreSame(shampooStub.Object, engine.Products.First().Value); }
public void Start_WhenInputStringIsInValidCreateToothPasteFormat_ShouldAddToothpasteToProducts() { // arrange string commandName = "CreateToothpaste"; var factoryStub = new Mock <ICosmeticsFactory>(); var commandParserStub = new Mock <ICommandParser>(); var shoppingCartStub = new Mock <IShoppingCart>(); var commandStub = new Mock <ICommand>(); var toothpasteStub = new Mock <IToothpaste>(); commandStub.SetupGet(x => x.Name).Returns(commandName); commandStub.SetupGet(x => x.Parameters) .Returns(new List <string>() { "White+", "Colgate", "15.50", "men", "fluor,bqla,golqma" }); commandParserStub.Setup(x => x.ReadCommands()) .Returns(new List <ICommand>() { commandStub.Object }); factoryStub.Setup(x => x.CreateToothpaste("White+", "Colgate", 15.50M, GenderType.Men, new List <string> { "fluor", "bqla", "golqma" })) .Returns(toothpasteStub.Object); var engine = new MockedCosmeticsEngine( factoryStub.Object, shoppingCartStub.Object, commandParserStub.Object ); // act engine.Start(); Assert.AreEqual(1, engine.Products.Count); Assert.AreSame(toothpasteStub.Object, engine.Products.First().Value); }
public void Start_WhenInputStringIsInCreateCAtegoryFormat_ShouldAddCategoryToList() { var factoryStub = new Mock <ICosmeticsFactory>(); var cartStub = new Mock <IShoppingCart>(); var commandStub = new Mock <ICommand>(); var categoryStub = new Mock <ICategory>(); categoryStub.SetupGet(c => c.Name).Returns("TestCategory"); commandStub.SetupGet(c => c.Name).Returns("CreateCategory"); commandStub.SetupGet(c => c.Parameters).Returns(new List <string>() { "TestCategory" }); factoryStub.Setup(f => f.CreateCategory(It.IsAny <string>())).Returns(categoryStub.Object); var commandParsersStub = new Mock <ICommandParser>(); commandParsersStub.Setup( cp => cp.ReadCommands()) .Returns(new List <ICommand>() { commandStub.Object }); var engine = new MockedCosmeticsEngine( factoryStub.Object, cartStub.Object, commandParsersStub.Object ); engine.Start(); var resultCategory = engine.Categories["TestCategory"]; // Assert.IsInstanceOf<Category>(engine.Categories["TestCategory"]); Assert.AreSame(resultCategory, categoryStub.Object); Assert.AreEqual(resultCategory.Name, categoryStub.Object.Name); }
public void Start_WhenInputStringIsInValidShowCategoryFormat_ShouldInvokeCategoryPrintMethod() { // arrange string commandName = "ShowCategory"; string categoryName = "TestCategory"; var factoryStub = new Mock <ICosmeticsFactory>(); var commandParserStub = new Mock <ICommandParser>(); var shoppingCartStub = new Mock <IShoppingCart>(); var commandStub = new Mock <ICommand>(); var categoryMock = new Mock <ICategory>(); var shampooStub = new Mock <IShampoo>(); commandStub.SetupGet(x => x.Name).Returns(commandName); commandStub.SetupGet(x => x.Parameters).Returns(new List <string> { categoryName }); commandParserStub.Setup(x => x.ReadCommands()) .Returns(new List <ICommand>() { commandStub.Object }); categoryMock.Setup(x => x.Print()).Verifiable(); var engine = new MockedCosmeticsEngine( factoryStub.Object, shoppingCartStub.Object, commandParserStub.Object ); engine.Categories.Add(categoryName, categoryMock.Object); // act engine.Start(); // assert categoryMock.Verify(x => x.Print(), Times.Once); }
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]); }
public void Start_WhenInputStringIsValidRemoveFromCartFormat_ShouldInvokeCartRemoveProduct() { // arrange var factoryStub = new Mock <ICosmeticsFactory>(); var commandParserStub = new Mock <ICommandParser>(); var shoppingCartMock = new Mock <IShoppingCart>(); var commandStub = new Mock <ICommand>(); var toothpasteStub = new Mock <IToothpaste>(); commandStub.SetupGet(x => x.Name).Returns("RemoveFromShoppingCart"); commandStub.SetupGet(x => x.Parameters) .Returns(new List <string>() { "TestName" }); commandParserStub.Setup(x => x.ReadCommands()) .Returns(new List <ICommand>() { commandStub.Object }); shoppingCartMock.Setup(x => x.ContainsProduct(It.IsAny <IProduct>())) .Returns(true); var engine = new MockedCosmeticsEngine( factoryStub.Object, shoppingCartMock.Object, commandParserStub.Object ); engine.Products.Add("TestName", toothpasteStub.Object); // act engine.Start(); // assert shoppingCartMock.Verify(x => x.RemoveProduct(toothpasteStub.Object), Times.Once); }
public void TestStart_PassValidAddToShoppingCart_ShouldAddToCart(string name) { 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>() { name }); mockedCommandParser .Setup(x => x.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object }); var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object); engine.Products.Add(name, mockedProduct.Object); engine.Start(); mockedShoppingCart.Verify(x => x.AddProduct(mockedProduct.Object), Times.Once); }
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_WhenInputStringIsValid_CreateShampooCommand_ShouldAddNewShampooToListOfProducts() { var shampooName = "White+"; var shampooBrand = "Nivea"; var shampooPrice = "0.5"; var shampooGender = "men"; var shampooMilliliters = "500"; var shampooUsage = "everyday"; var mockedFactory = new Mock <ICosmeticsFactory>(); var mockedShoppingCart = new Mock <IShoppingCart>(); var mockedCommandParser = new Mock <ICommandParser>(); var mockedShampoo = new Mock <IShampoo>(); var mockedCommand = new Mock <ICommand>(); mockedCommand.SetupGet(x => x.Name).Returns("CreateShampoo"); mockedCommand.SetupGet(x => x.Parameters).Returns(new List <string>() { shampooName, shampooBrand, shampooPrice, shampooGender, shampooMilliliters, shampooUsage }); mockedCommandParser.Setup(x => x.ReadCommands()).Returns(new List <ICommand>() { mockedCommand.Object }); mockedFactory.Setup( x => x.CreateShampoo(shampooName, shampooBrand, 0.5M, GenderType.Men, 500, UsageType.EveryDay)) .Returns(mockedShampoo.Object); var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object); engine.Start(); mockedFactory.Verify( x => x.CreateShampoo(shampooName, shampooBrand, 0.5M, GenderType.Men, 500, UsageType.EveryDay), Times.Once); Assert.IsTrue(engine.Products.ContainsKey(shampooName)); Assert.AreSame(mockedShampoo.Object, engine.Products[shampooName]); }
public void Start_WhenInputStringIsValidCreateAddToShoppingCartFormat_ShouldResultInAddingProductToCart() { // arrange var factoryStub = new Mock <ICosmeticsFactory>(); var commandParserStub = new Mock <ICommandParser>(); var shoppingCartMock = new Mock <IShoppingCart>(); var commandStub = new Mock <ICommand>(); var toothpasteStub = new Mock <IToothpaste>(); commandStub.SetupGet(x => x.Name).Returns("AddToShoppingCart"); commandStub.SetupGet(x => x.Parameters) .Returns(new List <string>() { "TestName" }); commandParserStub.Setup(x => x.ReadCommands()) .Returns(new List <ICommand>() { commandStub.Object }); var engine = new MockedCosmeticsEngine( factoryStub.Object, shoppingCartMock.Object, commandParserStub.Object ); engine.Products.Add("TestName", toothpasteStub.Object); // act engine.Start(); // assert shoppingCartMock.Verify(x => x.AddProduct(toothpasteStub.Object), Times.Once); }
public void Start_WhenInputFormatIsValidShowCategoryCommand_ShouldCallPrintOfThisCategory() { //Arrange var categoryName = "ForFemale"; 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 mockedCategory = new Mock <ICategory>(); var mockedShampoo = new Mock <IShampoo>(); 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); engine.Products.Add(productName, mockedShampoo.Object); //Act engine.Start(); //Assert mockedCategory.Verify(x => x.Print(), 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 TestStart_PassValidCreateShampoo_ShouldCreateSHampoo(string name, string brand) { 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>() { name, brand, "0.50", "men", "500", "everyday" }); mockedCommandParser .Setup(x => x.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object }); mockedFactory .Setup(x => x.CreateShampoo(name, brand, 0.50M, GenderType.Men, 500, UsageType.EveryDay)) .Returns(mockedShampoo.Object); var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object); engine.Start(); Assert.IsTrue(engine.Products.ContainsKey(name)); Assert.AreSame(mockedShampoo.Object, engine.Products[name]); }
public void TestStart_PassValidCreateToothpaste_ShouldCreateToothpaste(string name, string brand) { 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>() { name, brand, "15.50", "men", "fluor,bqla,golqma" }); mockedCommandParser .Setup(x => x.ReadCommands()).Returns(() => new List<ICommand>() { mockedCommand.Object }); mockedFactory .Setup(x => x.CreateToothpaste(name, brand, 15.50M, GenderType.Men, new List<string>() { "fluor", "bqla", "golqma" })) .Returns(mockedToothpaste.Object); var engine = new MockedCosmeticsEngine(mockedFactory.Object, mockedShoppingCart.Object, mockedCommandParser.Object); engine.Start(); Assert.IsTrue(engine.Products.ContainsKey(name)); Assert.AreSame(mockedToothpaste.Object, engine.Products[name]); }
public void TestStart_PassValidCreateCategory_ShouldCreateCategory(string categoryName) { 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(x => x.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); engine.Start(); Assert.IsTrue(engine.Categories.ContainsKey(categoryName)); Assert.AreSame(mockedCategory.Object, engine.Categories[categoryName]); }
public void TestStart_PassValidShowCategory_ShouldCallPrint(string categoryName, string productName) { 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>(); var mockedCategory = new Mock<ICategory>(); mockedCommand.SetupGet(x => x.Name).Returns("ShowCategory"); mockedCommand.SetupGet(x => x.Parameters).Returns(new List<string>() { categoryName, productName }); mockedCommandParser.Setup(x => x.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); engine.Start(); mockedCategory.Verify(x => x.Print(), Times.Once); }