예제 #1
0
        public void TestCreateWithEmptyLogin()
        {
            //Arrange
            var dbContext       = new RestaurantContext();
            var menuManager     = new MenuManager(dbContext);
            var menusController = new MenusController(menuManager);

            menusController.UserID = string.Empty;
            var menu = new Menu {
                Name = Guid.NewGuid().ToString(), UserID = menusController.UserID
            };

            //Act
            var result = menusController.Create(menu);

            //Assert
            Assert.IsInstanceOfType(result, typeof(UnauthorizedResult));
        }
예제 #2
0
        public void TestCreateWithFullData()
        {
            //Arrange
            var dbContext       = new RestaurantContext();
            var menuManager     = new MenuManager(dbContext);
            var menusController = new MenusController(menuManager);

            menusController.UserID = "8774f57e-f0c7-450a-b17e-09e30668eddc";
            var menu = new Menu {
                Name = Guid.NewGuid().ToString(), UserID = "8774f57e-f0c7-450a-b17e-09e30668eddc"
            };

            //Act
            menusController.Create(menu);
            var menus   = menuManager.GetAllMenus(menu.UserID);
            var newMenu = menus.SingleOrDefault(m => m.Name == menu.Name && m.UserID == menu.UserID);

            //Assert
            Assert.IsNotNull(newMenu);
            dbContext.Remove(newMenu);
            dbContext.SaveChanges();
        }
예제 #3
0
        public void TestCreateWithDuplicateName()
        {
            //Arrange
            var dbContext       = new RestaurantContext();
            var menuManager     = new MenuManager(dbContext);
            var menusController = new MenusController(menuManager);
            var userID          = "8774f57e-f0c7-450a-b17e-09e30668eddc";

            menusController.UserID = userID;
            var dupMenu = new Menu {
                Name = "Dinner Menu", UserID = userID
            };

            //Act
            menusController.Create(dupMenu);
            var allMenus      = menuManager.GetAllMenus(userID);
            var selectedMenus = allMenus.Where(m => m.Name == dupMenu.Name);
            var countMenu     = selectedMenus.Count();

            //Assert
            Assert.AreEqual(1, countMenu);
        }
예제 #4
0
        public async Task Create_WhenCalled_CreateMenuAndRedirectionToDetails()
        {
            // Arrange
            var model = new MenuCreateViewModel
            {
                Name         = "Spice Curry",
                Description  = "Absolute Yum",
                Available    = true,
                Category     = MenuCategory.Thailand,
                Price        = 19.99m,
                Special      = true,
                SpecialPrice = 15,
                ImageFile    = null
            };

            // Act
            var result = await controller.Create(model) as RedirectToActionResult;

            // Assert
            repository.Verify(r => r.AddSync(It.IsAny <Menu>()), Times.Once);
            unitOfWork.Verify(u => u.CompleteAsync(), Times.Once());
            Assert.That(result.ActionName, Is.EqualTo("details").IgnoreCase);
        }
        public void Create_CreatesNewInstanceOfMenu_True()
        {
            ActionResult createPost = _controller.Create("TestTheme");

            Assert.IsInstanceOfType(createPost, typeof(ActionResult));
        }