Пример #1
0
        public void Cannot_Save_Invalid_Edited_Client()
        {
            // ARRANGE: given a repository and an existing key contact...
            var mockRepository = new Mock<IClientRepository>();

            KeyContact[] existingKeyContact = new KeyContact[]
            {
                new KeyContact { KeyContactID = 1, FirstName = "Bill", LastName = "Cowher" }
            };

            // create data to change key contact to
            mockRepository.Setup(x => x.KeyContacts).Returns(existingKeyContact.AsQueryable());
            var keyContactForm = new KeyContactFormViewModel { KeyContactID = 1, FirstName = "Mike", LastName = "Tomlin" };

            // ACT: ...when a user tries to save changes to the invalid key contact...
            var controller = new KeyContactsController(mockRepository.Object);
            controller.ModelState.AddModelError("SomeProperty", "Got invalid data");
            var result = controller.Edit(keyContactForm) as ViewResult;

            // ASSERT: then the values of the key contact are not changed and the edit page is redisplayed
            Assert.NotNull(result);
            var clientFormResult = (KeyContactFormViewModel)result.ViewData.Model;
            clientFormResult.FirstName.ShouldEqual("Mike");
            clientFormResult.LastName.ShouldEqual("Tomlin");
            result.ViewName.ShouldEqual("Edit");
        }
Пример #2
0
        public void Cannot_Save_Invalid_New_KeyContact()
        {
            // ARRANGE: given a repository and a key contact to save...
            var mockRepository = new Mock<IClientRepository>();

            // create key contact to save
            KeyContactFormViewModel keyContact = new KeyContactFormViewModel {
                FirstName = "Bill", LastName = "Cowher"
            };

            // ACT: ...when a user tries to save the invalid key contact...
            var controller = new KeyContactsController(mockRepository.Object);
            controller.ModelState.AddModelError("SomeProperty", "Got invalid data");
            var result = controller.Edit(keyContact) as ViewResult;

            // ASSERT: ...the key contact is not saved and the edit page is redisplayed
            Assert.NotNull(result);
            var keyContactFormResult = (KeyContactFormViewModel)result.ViewData.Model;
            keyContactFormResult.FirstName.ShouldEqual("Bill");
            keyContactFormResult.LastName.ShouldEqual("Cowher");
            result.ViewName.ShouldEqual("Edit");
        }
Пример #3
0
        public void Can_Save_Valid_New_KeyContact()
        {
            // ARRANGE: given a repository and a key contact to save...
            var mockRepository = new Mock<IClientRepository>();

            // create key contact to save
            KeyContactFormViewModel keyContact = new KeyContactFormViewModel {
                FirstName = "Bill", LastName = "Cowher"
            };

            // ACT: ... when a user tries to save the valid key contact
            var controller = new KeyContactsController(mockRepository.Object);
            var result = controller.Edit(keyContact);

            // ASSERT: then the key contact is saved, user is redirected to the detail page,
            //         and a confirmation message is displayed
            result.ShouldBeRedirectionTo(new { action = "Detail" });
            controller.TempData["message"].ShouldEqual("Key Contact Bill Cowher has been saved.");
        }
Пример #4
0
        public void Can_Save_Valid_Edited_KeyContact()
        {
            // ARRANGE: given a repository and an existing key contact...
            var mockRepository = new Mock<IClientRepository>();

            KeyContact[] existingKeyContact = new KeyContact[]
            {
                new KeyContact { KeyContactID = 1, FirstName = "Bill", LastName = "Cowher" }
            };

            // create data to change key contact to
            mockRepository.Setup(x => x.KeyContacts).Returns(existingKeyContact.AsQueryable());
            var keyContactForm = new KeyContactFormViewModel { KeyContactID = 1, FirstName = "Mike", LastName = "Tomlin" };

            // ACT: ...when a user tries to save changes to the key contact...
            var controller = new KeyContactsController(mockRepository.Object);
            var result = controller.Edit(keyContactForm);

            // ASSERT: then the key contact is saved, user is redirected to the detail page,
            //         values are changed, and a confirmation message is displayed
            result.ShouldBeRedirectionTo(new { action = "Detail" });
            controller.TempData["message"].ShouldEqual("Key Contact Mike Tomlin has been saved.");
        }