Exemplo n.º 1
0
        public void CreatePost_SaveThroughRepository_WhenModelStateIsValid()
        {
            // Arrange
            var mockRepo     = new Mock <IMadmenuRepository>();
            var mockMenuRepo = new Mock <IMadbestillingRepository>();

            mockRepo.Setup(repo => repo.Save(It.IsAny <MadMenu>()))
            //.Returns(Task.CompletedTask)
            .Verifiable();
            var     controller = new MadMenuController(mockMenuRepo.Object, mockRepo.Object);
            MadMenu s          = new MadMenu()
            {
                MenuId = 1,
                Menu   = "Rødkålssalat med appelsin, valnød og salatost"
            };

            // Act
            var result = controller.Create(s);

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
            mockRepo.Verify();
        }
Exemplo n.º 2
0
        public void TestIndexMethodReturnsObjects()
        {
            // Arrange
            var mockRepo     = new Mock <IMadmenuRepository>();
            var mockMenuRepo = new Mock <IMadbestillingRepository>();

            mockRepo.Setup(repo => repo.Get())
            .Returns(DataTestService.GetTestMadmenu());
            var controller = new MadMenuController(mockMenuRepo.Object, mockRepo.Object);

            // Act
            var result = controller.Index();

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <MadMenu> >(
                viewResult.ViewData.Model);

            Assert.Equal(2, model.Count());
        }
Exemplo n.º 3
0
        public void CreatePost_ReturnsViewWithSpecies_WhenModelStateIsInvalid() //madmenu
        {
            // Arrange
            var mockRepo     = new Mock <IMadmenuRepository>();
            var mockMenuRepo = new Mock <IMadbestillingRepository>();
            var controller   = new MadMenuController(mockMenuRepo.Object, mockRepo.Object);

            controller.ModelState.AddModelError("Name", "Required");
            var madmenu = new MadMenu()
            {
                MenuId = 1, Menu = "Råmarineret laks med beder og rygeost"
            };

            // Act
            var result = controller.Create(madmenu);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <MadMenu>(viewResult.ViewData.Model);

            Assert.IsType <MadMenu>(model);
        }