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);
        }
Example #2
0
        /// <summary>
        /// Updates the data of the postal operator
        /// </summary>
        /// <param name="postOperatorDto">Instance Dto the postal operator</param>
        public void UpdatePostOperator(PostOperatorDto postOperatorDto)
        {
            var          mapper       = new MapperConfiguration(cfg => cfg.CreateMap <PostOperatorDto, PostOperator>()).CreateMapper();
            PostOperator postOperator = mapper.Map <PostOperator>(postOperatorDto);

            var results = postOperatorsValidator.Validate(postOperator);

            if (results.IsValid)
            {
                postOperatorsRepository.Update(postOperator);
            }
            else
            {
                throw new Exception("Помилка валідації поштового оператора: " + Environment.NewLine +
                                    ValidationResultsHelper.GetValidationErrors(results));
            }
        }
Example #3
0
        public void GetById_ShouldReturn_PostOperatorDto()
        {
            // Arrange
            int id = 1;

            mockPostOperatorsRepo.Setup(po => po.GetById(id)).Returns(new PostOperator());
            PostOperatorService postOperatorService = new PostOperatorService(connString, mockPostOperatorsRepo.Object);

            PostOperatorDto postOperatorDto = null;

            try
            {
                // Act
                postOperatorDto = postOperatorService.GetById(id);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsNotNull(postOperatorDto, errorMessage);
        }
Example #4
0
        public ActionResult Edit(int?id)
        {
            try
            {
                if (id == null)
                {
                    throw new Exception("Не обрано поштового оператора для оновлення активності.");
                }
                PostOperatorDto postOperatorDto = postOperatorService.GetById((int)id);
                if (postOperatorDto == null)
                {
                    throw new Exception("Поштового оператора не знайдено.");
                }

                return(View("Edit", mapper.Map <PostOperatorViewModel>(postOperatorDto)));
            }
            catch (Exception ex)
            {
                deliveryMessage.Title = "Поштові оператори";
                deliveryMessage.Body  = ex.Message;
                return(View("DeliveryMessage", deliveryMessage));
            }
        }
Example #5
0
        public void Add_ShouldReturn_Success()
        {
            //Arrange
            PostOperatorDto postOperatorDto = new PostOperatorDto
            {
                Name             = "Нова Пошта",
                LinkToSearchPage = "link123",
                PathToLogoImage  = "path123",
                IsActive         = true,
                Notes            = "notes 3"
            };
            PostOperator postOperator = new PostOperator
            {
                Name             = postOperatorDto.Name,
                LinkToSearchPage = postOperatorDto.LinkToSearchPage,
                PathToLogoImage  = postOperatorDto.PathToLogoImage,
                IsActive         = postOperatorDto.IsActive,
                Notes            = postOperatorDto.Notes
            };

            mockPostOperatorsRepo.Setup(po => po.Create(postOperator));
            PostOperatorService postOperatorService = new PostOperatorService(connString, mockPostOperatorsRepo.Object);

            try
            {
                // Act
                postOperatorService.Add(postOperatorDto);
                operationSucceded = true;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsTrue(operationSucceded, errorMessage);
        }