コード例 #1
0
        public void AddCategoryItem_ValidExample()
        {
            //Arrange Adding Menu item Category
            var category = new MoqMenuItemCategory(1, "Żarcie", "Różne");

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.AddMenuItemCategory(It.IsAny<string>(), It.IsAny<string>())).Returns(category);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.AddCategoryItem("Żarcie", "Różne");

            //Assert
            Assert.AreEqual(result, category);
        }
コード例 #2
0
        public void AddMenuItem_ExceptionFromDataAccess()
        {
            //Arrange Adding Menu item Category
            var category = new MoqMenuItemCategory(1, "Żarcie", "Różne");

            //Arrange Exception
            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.AddMenuItem(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<Money>())).Throws(new Exception());

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.AddMenuItem("Schabowy", category, 20, "Bardzo dobry schabowy");

            //Assert
            Assert.IsNull(result);
        }
コード例 #3
0
        public void AddMenuItem_FailedAddinToDataBase()
        {
            //Arrange Adding Menu item Category
            var category = new MoqMenuItemCategory(1, "Żarcie", "Różne");

            //Arrange ManagerDataAccess
            MenuItem menuItem = null;

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.AddMenuItem(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<Money>())).Returns(menuItem);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.AddMenuItem("Schabowy", category, 20, "Bardzo dobry schabowy");

            //Assert
            Assert.IsNull(result);
        }
コード例 #4
0
        public void GetAllMenuItems_ValidExample()
        {
            //Arrange List of Categories
            var MenuItems = new List<MoqMenuItem>();

            var e1 = new MoqMenuItemCategory(1, "Żarcie", "Schabowe i inne");
            var e2 = new MoqMenuItemCategory(2, "Napoje", "Wódka i inne");
            var e3 = new MoqMenuItemCategory(3, "Przystawki", "Mało tego");

            var f1 = new MoqMenuItem(1, "Schabowy", "Bardzo dobry Schabowy", e1, new Money() { Amount = 20, Currency = "PLN" });
            var f2 = new MoqMenuItem(2, "Wódka", "Bardzo wykwintna wódka", e2, new Money() { Amount = 30, Currency = "PLN" });
            var f3 = new MoqMenuItem(3, "Frytki", "3 frytki na krzyż", e3, new Money() { Amount = 5, Currency = "PLN" });

            MenuItems.Add(f1);
            MenuItems.Add(f2);
            MenuItems.Add(f3);

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.GetMenuItems()).Returns(MenuItems);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var ReturnedMenuItems = BarDataModel.GetAllMenuItems();
            var ReturnedMenuItemsCast = ReturnedMenuItems.Cast<MoqMenuItem>().ToList();

            //Asserts
            Assert.IsNotNull(ReturnedMenuItemsCast);

            Assert.AreEqual(ReturnedMenuItemsCast[0].Id, f1.Id);
            Assert.AreEqual(ReturnedMenuItemsCast[0].Name, f1.Name);
            Assert.AreEqual(ReturnedMenuItemsCast[0].Description, f1.Description);
            Assert.AreEqual(ReturnedMenuItemsCast[0].Category, e1);
            Assert.AreEqual(ReturnedMenuItemsCast[0].Price.Amount, 20);
            Assert.AreEqual(ReturnedMenuItemsCast[0].Price.Currency, "PLN");

            Assert.AreEqual(ReturnedMenuItemsCast[1].Id, f2.Id);
            Assert.AreEqual(ReturnedMenuItemsCast[1].Name, f2.Name);
            Assert.AreEqual(ReturnedMenuItemsCast[1].Description, f2.Description);
            Assert.AreEqual(ReturnedMenuItemsCast[1].Category, e2);
            Assert.AreEqual(ReturnedMenuItemsCast[1].Price.Amount, 30);
            Assert.AreEqual(ReturnedMenuItemsCast[1].Price.Currency, "PLN");

            Assert.AreEqual(ReturnedMenuItemsCast[2].Id, f3.Id);
            Assert.AreEqual(ReturnedMenuItemsCast[2].Name, f3.Name);
            Assert.AreEqual(ReturnedMenuItemsCast[2].Description, f3.Description);
            Assert.AreEqual(ReturnedMenuItemsCast[2].Category, e3);
            Assert.AreEqual(ReturnedMenuItemsCast[2].Price.Amount, 5);
            Assert.AreEqual(ReturnedMenuItemsCast[2].Price.Currency, "PLN");
        }
コード例 #5
0
        public void GetAllCategories_ValidExample()
        {
            //Arrange List of Categories
            var Categories = new List<MoqMenuItemCategory>();

            var e1 = new MoqMenuItemCategory(1, "Żarcie", "Schabowe i inne");
            var e2 = new MoqMenuItemCategory(2, "Napoje", "Wódka i inne");
            var e3 = new MoqMenuItemCategory(3, "Przystawki", "Mało tego");

            Categories.Add(e1);
            Categories.Add(e2);
            Categories.Add(e3);

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.GetMenuItemCategories()).Returns(Categories);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var ReturnedCategories = BarDataModel.GetAllCategories();
            var ReturnedCategoriesCast = ReturnedCategories.Cast<MoqMenuItemCategory>().ToList();

            //Asserts
            Assert.IsNotNull(ReturnedCategoriesCast);

            Assert.AreEqual(ReturnedCategoriesCast[0].Id, e1.Id);
            Assert.AreEqual(ReturnedCategoriesCast[0].Name, e1.Name);
            Assert.AreEqual(ReturnedCategoriesCast[0].Description, e1.Description);

            Assert.AreEqual(ReturnedCategoriesCast[1].Id, e2.Id);
            Assert.AreEqual(ReturnedCategoriesCast[1].Name, e2.Name);
            Assert.AreEqual(ReturnedCategoriesCast[1].Description, e2.Description);

            Assert.AreEqual(ReturnedCategoriesCast[2].Id, e3.Id);
            Assert.AreEqual(ReturnedCategoriesCast[2].Name, e3.Name);
            Assert.AreEqual(ReturnedCategoriesCast[2].Description, e3.Description);
        }
コード例 #6
0
        public void EditMenuItem_ValidExample()
        {
            //Arrange Menu item Categories
            var category1 = new MoqMenuItemCategory(1, "Żarcie", "Różne");
            var category2 = new MoqMenuItemCategory(2, "Picie", "Owocowe i nie");

            //Arrange other changes
            var newName = "Wódka";
            var newDescription = "Smakowa";
            var newPrice = (double)30;

            //Arrange Menu Item
            var menuItem = new MoqMenuItem(1, "Schabowy", "Bardzo dobry schabowy", category1, new Money() { Amount = 20, Currency = "PLN" });

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.EditMenuItem(It.IsAny<MenuItem>())).Returns(true);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.EditMenuItem(menuItem, newName, newPrice, category2, newDescription);

            //Assert
            Assert.IsTrue(result);
            Assert.AreEqual(menuItem.Name, newName);
            Assert.AreEqual(menuItem.Price.Amount, newPrice);
            Assert.AreEqual(menuItem.Category, category2);
            Assert.AreEqual(menuItem.Description, newDescription);
        }
コード例 #7
0
        public void EditMenuItem_ExceptionFromDataAccess()
        {
            //Arrange Menu item Categories
            var category1 = new MoqMenuItemCategory(1, "Żarcie", "Różne");
            var category2 = new MoqMenuItemCategory(2, "Picie", "Owocowe i nie");

            //Arrange other changes
            var oldName = "Schabowy";
            var oldDescription = "Bardzo dobry schabowy";
            var oldPrice = 20;

            var newName = "Wódka";
            var newDescription = "Smakowa";
            var newPrice = (double)30;

            //Arrange Menu Item
            var menuItem = new MoqMenuItem(1, oldName, oldDescription, category1, new Money() { Amount = oldPrice, Currency = "PLN" });

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.EditMenuItem(It.IsAny<MenuItem>())).Throws(new Exception());

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.EditMenuItem(menuItem, newName, newPrice, category2, newDescription);

            //Assert
            Assert.IsFalse(result);
            Assert.AreEqual(menuItem.Name, oldName);
            Assert.AreEqual(menuItem.Price.Amount, oldPrice);
            Assert.AreEqual(menuItem.Category, category1);
            Assert.AreEqual(menuItem.Description, oldDescription);
        }
コード例 #8
0
        public void AddMenuItem_ValidExample()
        {
            //Arrange Adding Menu item Category
            var category = new MoqMenuItemCategory(1, "Żarcie", "Różne");

            //Arrange Menu Item
            var menuItem = new MoqMenuItem(1, "Schabowy", "Bardzo dobry schabowy", category, new Money() { Amount = 20, Currency = "PLN" });

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.AddMenuItem(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<Money>())).Returns(menuItem);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.AddMenuItem("Schabowy", category, 20, "Bardzo dobry schabowy");

            //Assert
            Assert.AreEqual(result, menuItem);
        }