Ejemplo n.º 1
0
        public ActionResult Edit(ShopContactViewModel model)
        {
            if (!ModelState.IsValid)
            {
                TempData["ModelIsNotValid"] = "Wystąpił błąd w formularzu, spróbuj ponownie.";
                return(RedirectToAction("Index"));
            }
            var shopContact = _mappper.Map <ShopContactViewModel, ShopContact>(model);

            _xmlManager.CreateXmlFile <ShopContact>(GlobalXmlManager.ContactFileName, shopContact);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public void Get_Edit_Ajax_Request()
        {
            // Arrange
            var shopContact = new ShopContact()
            {
                Address = new Address()
                {
                    DeliveryContact = "111 111 111", Email = "*****@*****.**", InformationContact = "000 000 000"
                },
                Contact = new Contact()
                {
                    City = "FakeCisty", PostalCode = "22-333", Street = "ul. fake 111"
                }
            };
            var shopContactViewModel = new ShopContactViewModel()
            {
                DeliveryContact    = "111 111 111",
                Email              = "*****@*****.**",
                InformationContact = "000 000 000",
                City       = "FakeCisty",
                PostalCode = "22-333",
                Street     = "ul. fake 111"
            };

            var xmlManager = Substitute.For <IXmlManager>();
            var mapper     = Substitute.For <IMapper>();

            var fakeController = new FakeController();

            fakeController.PrepareFakeAjaxRequest();
            var controller = new ContactController(xmlManager, mapper);

            controller.ControllerContext = fakeController.
                                           GetControllerContext <ContactController>(new RouteData(), controller);

            xmlManager.GetXmlModel <ShopContact>(GlobalXmlManager.ContactFileName).Returns(shopContact);
            mapper.Map <ShopContact, ShopContactViewModel>(shopContact).Returns(shopContactViewModel);

            // Act
            var result      = controller.Edit() as PartialViewResult;
            var ajaxRequest = controller.Request.IsAjaxRequest();
            var viewName    = result.ViewName;
            var model       = result.Model;

            // Assert
            Assert.IsTrue(ajaxRequest);
            Assert.IsNotNull(result);
            Assert.AreEqual("_EditPartial", viewName);
            Assert.IsNotNull(model);
        }
Ejemplo n.º 3
0
        public void Post_Edit_Model_Is_Not_Valid()
        {
            // Arrange
            var shopContactViewModel = new ShopContactViewModel()
            {
                DeliveryContact    = "111 111 111",
                Email              = "*****@*****.**",
                InformationContact = "000 000 000",
                City       = "FakeCisty",
                PostalCode = "22-333" /*,
                                       * Street = "ul. fake 111"*/// field is required
            };
            var shopContact = new ShopContact()
            {
                Address = new Address()
                {
                    DeliveryContact = "111 111 111", Email = "*****@*****.**", InformationContact = "000 000 000"
                },
                Contact = new Contact()
                {
                    City = "FakeCisty", PostalCode = "22-333", Street = "ul. fake 111"
                }
            };
            var xmlManager = Substitute.For <IXmlManager>();
            var mapper     = Substitute.For <IMapper>();

            mapper.Map <ShopContactViewModel, ShopContact>(shopContactViewModel).Returns(shopContact);
            xmlManager.CreateXmlFile <ShopContact>(GlobalXmlManager.ContactFileName, shopContact);

            var controller = new ContactController(xmlManager, mapper);
            var validator  = new ModelValidator <ShopContactViewModel>(shopContactViewModel);

            //Act
            var valid = validator.IsValid();

            validator.AddToModelError(controller);
            var result   = controller.Edit(shopContactViewModel) as RedirectToRouteResult;
            var viewName = result.RouteValues.Values.ElementAt(0);
            var tempData = controller.TempData["ModelIsNotValid"];

            //Assert
            Assert.That(result, !Is.Null);
            Assert.That("Index", Is.EqualTo(viewName));
            Assert.That("Wystąpił błąd w formularzu, spróbuj ponownie.", Is.EqualTo(tempData));
            Assert.That(valid, Is.False);
        }
Ejemplo n.º 4
0
        public void Post_Edit_Model_Is_Valid()
        {
            // Arrange
            var shopContactViewModel = new ShopContactViewModel()
            {
                DeliveryContact    = "111 111 111",
                Email              = "*****@*****.**",
                InformationContact = "000 000 000",
                City       = "FakeCisty",
                PostalCode = "22-333",
                Street     = "ul. fake 111",
            };
            var shopContact = new ShopContact()
            {
                Address = new Address()
                {
                    DeliveryContact = "111 111 111", Email = "*****@*****.**", InformationContact = "000 000 000"
                },
                Contact = new Contact()
                {
                    City = "FakeCisty", PostalCode = "22-333", Street = "ul. fake 111"
                }
            };
            var xmlManager = Substitute.For <IXmlManager>();
            var mapper     = Substitute.For <IMapper>();

            mapper.Map <ShopContactViewModel, ShopContact>(shopContactViewModel).Returns(shopContact);
            xmlManager.CreateXmlFile <ShopContact>(GlobalXmlManager.ContactFileName, shopContact);

            var controller = new ContactController(xmlManager, mapper);
            var validator  = new ModelValidator <ShopContactViewModel>(shopContactViewModel);

            //Act
            var result       = controller.Edit(shopContactViewModel) as RedirectToRouteResult;
            var actionName   = result.RouteValues.Values.ElementAt(0);
            var modelIsValid = validator.IsValid();

            //Assert
            Assert.That(result, !Is.Null);
            Assert.That("Index", Is.EqualTo(actionName));
            Assert.That(modelIsValid, Is.True);
        }