public void Edit_Post_ShouldReturn_RedirectToAction()
        {
            // Arrange
            var postOperator = new PostOperatorViewModel {
                Id = 1
            };

            mockPostOperatorService.Setup(po => po.UpdatePostOperator(new PostOperatorDto()));
            mockPostOperatorService.Setup(po => po.GetById(postOperator.Id)).Returns(new PostOperatorDto());
            PostOperatorController controller = new PostOperatorController(new DeliveryMessage(), mockPostOperatorService.Object);

            RedirectToRouteResult redirectResult = null;

            try
            {
                // Act
                redirectResult = controller.Edit(postOperator) as RedirectToRouteResult;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsNotNull(redirectResult, errorMessage);
        }
        public void Edit_Get_ShouldReturn_ViewAndListOfInvoices()
        {
            // Arrange
            var postOperatorDto = new PostOperatorDto
            {
                Id               = 1,
                Name             = "New Post",
                LinkToSearchPage = "link1",
                PathToLogoImage  = "path1",
                IsActive         = true,
                Notes            = "notes 1"
            };

            mockPostOperatorService.Setup(po => po.GetById(postOperatorDto.Id)).Returns(postOperatorDto);
            PostOperatorController controller = new PostOperatorController(new DeliveryMessage(), mockPostOperatorService.Object);

            PostOperatorViewModel postOperator = null;

            try
            {
                // Act
                result       = controller.Edit(1) as ViewResult;
                postOperator = (PostOperatorViewModel)result.Model;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsNotNull(result, errorMessage);
            Assert.IsNotNull(postOperator, errorMessage);
        }
示例#3
0
        public ActionResult Create(PostOperatorViewModel postOperator)
        {
            try
            {
                postOperatorService.Add(mapper.Map <PostOperatorDto>(postOperator));

                return(View("Create"));
            }
            catch (Exception ex)
            {
                deliveryMessage.Title = "Поштові оператори";
                deliveryMessage.Body  = ex.Message;
                return(View("DeliveryMessage", deliveryMessage));
            }
        }
示例#4
0
        public ActionResult Edit(PostOperatorViewModel postOperator)
        {
            try
            {
                if (postOperator == null)
                {
                    throw new Exception("Поштового оператора не знайдено.");
                }
                postOperatorService.UpdatePostOperator(mapper.Map <PostOperatorDto>(postOperator));

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                deliveryMessage.Title = "Поштові оператори";
                deliveryMessage.Body  = ex.Message;
                return(View("DeliveryMessage", deliveryMessage));
            }
        }