示例#1
0
        public void CallCreateArticleService_WhenModelStateIsValid()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var model      = new CreateEditArticleViewModel();
            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var controllerContext = new Mock <ControllerContext>();
            var user = new Mock <IPrincipal>();

            user.Setup(p => p.IsInRole("admin")).Returns(true);
            user.SetupGet(x => x.Identity.Name).Returns("username");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(user.Object);
            controller.ControllerContext = controllerContext.Object;

            controller.ViewData.ModelState.Clear();

            // Act
            controller.CreateArticle(model);

            // Assert
            articleServiceMock.Verify(x => x.CreateArticle(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
示例#2
0
        public void RedirectToIndexActionOnSuccess_WhenModelStateIsValid()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var model      = new CreateEditArticleViewModel();
            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var controllerContext = new Mock <ControllerContext>();
            var user = new Mock <IPrincipal>();

            user.Setup(p => p.IsInRole("admin")).Returns(true);
            user.SetupGet(x => x.Identity.Name).Returns("username");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(user.Object);
            controller.ControllerContext = controllerContext.Object;

            controller.ViewData.ModelState.Clear();

            // Act & Assert
            controller.WithCallTo(x => x.CreateArticle(model))
            .ShouldRedirectTo(x => x.Index(null, null));
        }
示例#3
0
        //public IViewComponentResult Invoke(CreateEditGoodViewModel cegvm)
        //{
        //    ViewBag.Categories = _repositoryCategory.Categories().ToList();
        //    //string[] ws = cegvm.Category.Split('/');
        //    //ViewBag.FW = ws[0];
        //    return View(cegvm);
        //}

        public async Task <IViewComponentResult> InvokeAsync(CreateEditArticleViewModel cegvm)

        {
            ViewBag.Categories = _repositoryCategory.Categories().ToList();
            //string[] ws = cegvm.Category.Split('/');
            //ViewBag.FW = ws[0];
            return(View(cegvm));
        }
        public ActionResult EditArticle(CreateEditArticleViewModel article)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(article));
            }

            this.articleService.EditArticle(article.Id, article.Title, article.City, article.Country, article.ContentMain, article.ContentMustSee, article.ContentBudgetTips, article.ContentAccomodation, article.PrimaryImageUrl, article.SecondImageUrl, article.ThirdImageUrl, article.CoverImageUrl);

            return(this.RedirectToAction("Details", new { id = article.Id }));
        }
        public ActionResult CreateArticle(CreateEditArticleViewModel article)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(article));
            }

            var userId = this.User.Identity.GetUserId();

            this.articleService.CreateArticle(userId, article.Title, article.City, article.Country, article.ContentMain, article.ContentMustSee, article.ContentBudgetTips, article.ContentAccomodation, article.PrimaryImageUrl, article.SecondImageUrl, article.ThirdImageUrl, article.CoverImageUrl);

            return(this.RedirectToAction("Index"));
        }
示例#6
0
        public void ReturnDefaultViewWithModel_WhenModelStateIsInvalid()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var model      = new CreateEditArticleViewModel();
            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            controller.ViewData.ModelState.AddModelError("myError", "error");

            // Act & Assert
            controller.WithCallTo(x => x.CreateArticle(model))
            .ShouldRenderDefaultView()
            .WithModel <CreateEditArticleViewModel>();
        }
示例#7
0
        public void RedirectToDetailsView_WhenPassedModelIsValid()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var model = new CreateEditArticleViewModel();

            var article = new Article();

            articleServiceMock.Setup(x => x.EditArticle(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));

            // Act & Assert
            controller.WithCallTo(x => x.EditArticle(model))
            .ShouldRedirectTo(x => x.Details(Guid.NewGuid()));
        }
示例#8
0
        public void RenderDefaultView_WhenPassedIdIsNull()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var id      = Guid.NewGuid();
            var article = new Article();
            var model   = new CreateEditArticleViewModel();

            articleServiceMock.Setup(x => x.GetArticleById(id)).Returns(article);
            mappingServiceMock.Setup(x => x.Map <CreateEditArticleViewModel>(article)).Returns(model);

            // Act & Assert
            controller.WithCallTo(x => x.EditArticle(id))
            .ShouldRenderDefaultView()
            .WithModel <CreateEditArticleViewModel>(x => x == model);
        }
示例#9
0
        public void CallEditArticleMethod_WhenPassedModelIsValid()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var model = new CreateEditArticleViewModel();

            var article = new Article();

            articleServiceMock.Setup(x => x.EditArticle(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));

            // Act
            controller.EditArticle(model);

            // Assert
            articleServiceMock.Verify(x => x.EditArticle(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
示例#10
0
        public void CallMappingServiceMethod_WhenPassedIdIsNull()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var id      = Guid.NewGuid();
            var article = new Article();
            var model   = new CreateEditArticleViewModel();

            articleServiceMock.Setup(x => x.GetArticleById(id)).Returns(article);
            mappingServiceMock.Setup(x => x.Map <CreateEditArticleViewModel>(article)).Returns(model);

            // Act
            controller.EditArticle(id);

            // Assert
            mappingServiceMock.Verify(x => x.Map <CreateEditArticleViewModel>(article), Times.Once);
        }
示例#11
0
        public IActionResult EditArticle(CreateEditArticleViewModel model)
        {
            if (ModelState.IsValid)
            {
                //ТЕКУЩИЙ ПОЛЬЗОВАТЕЛЬ
                var currentUser = _repositoryUser.GetCurrentUser(User.Identity.Name);

                //ПОЛУЧАЕМ КОМПАНИЮ РОДИТЕЛЯ ОПРЕДЕЛЯЕМУЮ ТЕКУЩИМ ПОЛЬЗОВАТЕЛЕМ
                Company company = new Company();
                if (currentUser != null)
                {
                    company = _repositoryCompany.GetUserCompany(currentUser);
                }
                else
                {
                    return(RedirectToAction("Articles"));
                }

                //ФОРМИРУЕМ СПИСОК ИЗОБРАЖЕНИЙ
                List <RelGoodImage> relImages = new List <RelGoodImage>();
                //если строка id изображений непуста тогда формируем список
                if (model.goodImagesIds != null)
                {
                    string[] strImgids = model.goodImagesIds.Trim().Substring(0, model.goodImagesIds.Length - 1).Split('_');
                    foreach (var strImageId in strImgids)
                    {
                        if (strImageId.Length == 0)
                        {
                            continue;                        //это случай когдау товара нет изображений, но в массив все равно попадает распарсеная пустая строка
                        }
                        relImages.Add(new RelGoodImage
                        {
                            GoodId  = model.Id,
                            ImageId = Convert.ToInt32(strImageId)
                        });
                    }
                }

                //формирование разделителей
                //model.Description = model.Description.Replace("\r\n", "[newstr]");

                _repositoryArticle.SaveArticle(new Article
                {
                    Id              = model.Id,
                    Title           = model.Title,
                    EnTitle         = model.EnTitle,
                    Description     = model.Description,
                    Link            = model.Link,
                    HashTags        = model.HashTags,
                    CategoryId      = Convert.ToInt32(model.CategoryId),
                    CategoryType    = _repositoryCategory.GetCategoryById(Convert.ToInt32(model.CategoryId)).CategoryType,
                    Images          = relImages,
                    UpdateTime      = DateTime.Now,
                    metaDescription = model.metaDescription,
                    metaKeyWords    = model.metaKeyWords
                },
                                               company);
                if (model.deletedImagesIds != null)
                {
                    int[] ids = GetIntIds.ConvertIdsToInt(model.deletedImagesIds).ToArray();
                    _repositoryImage.DeleteImages(ids);
                }
            }
            return(RedirectToAction("Articles"));
        }
示例#12
0
        public IActionResult EditArticle(int id)
        {
            CreateEditArticleViewModel cegvm = null;

            if (id != 0)
            {
                #region формирование данных статьи для отображения в интерфейсе редактирования
                Article item = _repositoryArticle.GetArticle(id);

                cegvm = new CreateEditArticleViewModel
                {
                    Title           = item.Title,
                    EnTitle         = item.EnTitle,
                    Description     = item.Description,
                    Link            = item.Link,
                    HashTags        = item.HashTags,
                    Category        = item.Category.Title,
                    CategoryId      = item.CategoryId,
                    Id              = item.Id,
                    metaDescription = item.metaDescription,
                    metaKeyWords    = item.metaKeyWords
                };
                if (item.Images.Count != 0)
                {
                    cegvm.MainImageInBase64 = FromByteToBase64Converter.GetImageBase64Src(item.Images.ToList()[0].Image);
                    foreach (var rgi in item.Images)
                    {
                        //для каждого изображения составляем соответствующую модель отображения
                        cegvm.ImageViewModels.Add(
                            new ImageViewModel
                        {
                            GoodId        = rgi.GoodId,
                            Id            = rgi.ImageId,
                            goodImageIds  = rgi.GoodId + "_" + rgi.ImageId,
                            ImageMimeType = rgi.Image.ImageMimeType,
                            ImageInBase64 = FromByteToBase64Converter.GetImageBase64Src(rgi.Image)
                        }
                            );
                        //для каждого изображения оставляем его id в input всех id изображений товара
                        cegvm.goodImagesIds += rgi.ImageId + "_";
                    }
                }
                #endregion
            }
            else
            {
                cegvm = new CreateEditArticleViewModel();
            }

            #region формирование списка ключевиков для САЙТА

            ViewBag.SiteKws = _repositoryKW.Kws(null).ToList();

            #endregion

            ViewData["Title"]       = _settings.ApplicationTitle + "Администрирование: Добавление/Редактирование статьи";
            ViewData["HeaderTitle"] = _settings.HeaderTitle;
            ViewData["FooterTitle"] = _settings.FooterTitle;
            ViewBag.ActiveSubMenu   = "Статьи";
            return(View(cegvm));
        }