Ejemplo n.º 1
0
        public void CreateTest()
        {
            var            mockS = new Mock <IGuestService>();
            GuestViewModel guest = new GuestViewModel {
                LastName = "Hasan", FirstName = "Test", Address = "test", PostCode = "44", Country = "nl", Town = "grt", PhoneNumber = "123", Email = "nnn"
            };

            mockS.Setup(p => p.AddGuest(guest)).Returns(7);
            GuestController guestController = new GuestController(mockS.Object);

            var result = guestController.Create(guest).Result as ViewResult;

            Assert.IsTrue(result.ViewData.Values.Contains("The guest Hasan has registered succesfully!"));
        }
        public void Create__NotNull_ViewResultIsNotNull()
        {
            //Arrange
            var guest = new GuestViewModel();
            var mock  = new Mock <IGuestService>();

            mock.Setup(g => g.AddGuest(guest));
            var controller = new GuestController(mock.Object);
            //Act
            ViewResult result = controller.Create() as ViewResult;


            Assert.IsNotNull(result);
        }
        public void Create_Success_ReturnsARedirectToActionResut()
        {
            // Arrange
            var testGuest  = new GuestViewModel();
            var guestsRepo = new Mock <IGuestService>();

            guestsRepo.Setup(g => g.AddGuest(It.IsAny <GuestViewModel>()));
            var controller = new GuestController(guestsRepo.Object);

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

            // Assert
            var redirectToActionResult = result as RedirectToActionResult;

            Assert.AreEqual("Index", redirectToActionResult.ActionName);
        }
        public void Create_Error_ReturnsAViewResut()
        {
            // Arrange
            var testGuest  = new GuestViewModel();
            var guestsRepo = new Mock <IGuestService>();

            guestsRepo.Setup(g => g.AddGuest(It.IsAny <GuestViewModel>()));
            var controller = new GuestController(guestsRepo.Object);

            controller.ModelState.AddModelError("", "");

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

            // Assert

            Assert.That(result, Is.InstanceOf <ViewResult>());
        }