public ActionResult New(PublisherViewModel model)
 {
     if (ModelState.IsValid)
     {
         _publisherService.AddPublisher(Mapper.Map<PublisherViewModel, PublisherDTO>(model));
         return RedirectToAction("GetPublisherByCompanyName", new { companyName = model.CompanyName });
     }
     return View(model);
 }
        public void Test_New_Call_AddPublisher()
        {
            //arrange
            PublisherController controller = new PublisherController(_publisherService.Object, null);
            PublisherViewModel publisher = new PublisherViewModel()
            {
                CompanyName = "Name",
                Description = "Description",
                PublisherId = 1,
                HomePage = "home.page"
            };

            //act
            var result = controller.New(publisher);

            //assert
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
             _publisherService.Verify( p => p.AddPublisher(It.IsAny<PublisherDTO>()), Times.Once () );
        }
        public void Test_New_Try_Add_Publisher_With_Empty_Field()
        {
            //arrange
            PublisherController controller = new PublisherController(_publisherService.Object, null);
            PublisherViewModel publisher = new PublisherViewModel()
            {
                CompanyName = "",
                Description = "",
                PublisherId = 1,
                HomePage = "home.page"
            };

            //act
            controller.ViewData.ModelState.AddModelError("error", "error");
            var result = controller.New(publisher);

            //assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual(1, controller.ViewData.ModelState.Count);
        }