Beispiel #1
0
        public async Task ShouldCreateArticle()
        {
            // Arrange
            using var scope = Factory.Services.CreateScope();

            var postArticleModel = new PostArticleModel
            {
                BoardId = board.Id,
                Text    = "text",
                Title   = "title",
                Type    = "meta"
            };

            var sut = new AddArticleCommandHandler(unitOfWork, mediator, mapper, currentUserServiceMock.Object);

            // Act
            GetArticleModel sutResult = await sut.Handle(new AddArticleCommand(postArticleModel), new CancellationToken(false));

            // Assert
            Assert.NotNull(sutResult);

            var addedArticle = await unitOfWork.Articles.GetEntityAsync(sutResult.Id);

            Assert.NotNull(addedArticle);
            Assert.False(addedArticle.Deleted);
            Assert.Equal(addedArticle.UserId, user.Id);
            Assert.Equal(addedArticle.BoardId, board.Id);
        }
        public async Task ShouldUpdateArticle()
        {
            // Arrange
            using var scope = Factory.Services.CreateScope();

            var updateArticleModel = new PostArticleModel
            {
                BoardId = -1,                 // make sure board id can't be updated
                Text    = "updated text",
                Title   = "updated title",
                Type    = "meta"
            };

            var sut = new UpdateArticleHandler(unitOfWork, mediator, mapper, currentUserServiceMock.Object, articleOperationValidatorMock.Object);

            // Act
            GetArticleModel sutResult = await sut.Handle(new UpdateArticleCommand(article.Id, updateArticleModel), new CancellationToken(false));

            // Assert
            Assert.NotNull(sutResult);

            var updatedArticle = await unitOfWork.Articles.GetEntityAsync(sutResult.Id);

            Assert.NotNull(updatedArticle);
            Assert.False(updatedArticle.Deleted);
            Assert.Equal(updatedArticle.UserId, user.Id);
            Assert.Equal(updatedArticle.BoardId, board.Id);

            Assert.Equal(updatedArticle.Text, updateArticleModel.Text);
            Assert.Equal(updatedArticle.Title, updateArticleModel.Title);
        }
        private async Task UpdateArticleWithUpdateModel(Article article, PostArticleModel updateModel)
        {
            Article sourceArticle = MapPostModelToArticle(updateModel);

            var updatedArticle = ApplyUpdatedSourceProperties(article, sourceArticle);

            await UpdateArticleAndSave(updatedArticle);
        }
        private async Task <Article> CreateArticle(PostArticleModel postArticleModel)
        {
            var user = await UnitOfWork.Users.GetEntityAsync(_currentUserService.UserId);

            Article article = Mapper.Map <Article>(postArticleModel);

            article.PostDate = DateTime.Now;
            article.UserId   = user.Id;
            return(article);
        }
        public HttpResponseMessage PostArticle(PostArticleModel dataToPost)
        {
            ArticleEditModel model = new ArticleEditModel(_context, dataToPost);

            model.AddNew();

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            return(response);
        }
        private static void TestArticles(int goodsOwnerId, ArticlesClient articlesClient)
        {
            Console.WriteLine("Running article examples...");
            Console.WriteLine("");

            // Define a new article.
            var article = new PostArticleModel()
            {
                GoodsOwnerId  = goodsOwnerId,
                ArticleNumber = "12345",
                ArticleName   = "Test article",
                Weight        = 1.7m, // Unit is kilograms.
                BarCodeInfo   = new PostArticleBarCodeInfo()
                {
                    BarCode = "733123"
                }
            };

            // Send the new article to the warehouse, thus creating it.
            var createResponse = articlesClient.Put3(article);

            // Update the barcode to something else.
            article.BarCodeInfo.BarCode = "507543";
            var updateResponse = articlesClient.Put3(article);

            // You may query for articles using various ways. The response will include various article data (including stock balances).
            var getArticleByArticleSystemId = articlesClient.Get(createResponse.ArticleSystemId.Value);
            var getArticleByArticleNumber   = articlesClient.GetAll(goodsOwnerId, "12345", null, null);

            // If you have a file (such as an image), you may attach it to the article.
            var imagePath = @"C:\WMS\12345.png";

            if (System.IO.File.Exists(imagePath))
            {
                var fileBase64 = Convert.ToBase64String(System.IO.File.ReadAllBytes(imagePath));
                var file       = new PostFileModel()
                {
                    FileName = "12345.png", FileDataBase64 = fileBase64, MimeType = "image/png"
                };
                articlesClient.Post(createResponse.ArticleSystemId.Value, file);
            }
        }
Beispiel #7
0
        public ArticleEditModel(SuvaLinesContext context, PostArticleModel model)
        {
            _context = context;

            if (model == null)
            {
                throw new NoNullAllowedException("Null not allowed");
            }

            ArticleId   = 0;
            UserId      = 1;
            Title       = model.Title;
            ArticleText = model.ArticleText;
            GroupId     = model.GroupId;

            if (model.ArticleId == 0)
            {
                DateCreated = DateTime.Now;
            }

            DateUpdated = DateTime.Now;
            LongTitle   = model.LongTitle;
            ImgUrl      = model.ImgUrl;
        }
Beispiel #8
0
 public async Task <ActionResult <GetArticleModel> > Put(int key, [FromBody] PostArticleModel updateModel)
 {
     // Throws some type of validation error
     return(Ok(await Mediator.Send(new UpdateArticleCommand(key, updateModel))));
 }
Beispiel #9
0
 public async Task <ActionResult <GetArticleModel> > PostAsync([FromBody] PostArticleModel postModel)
 {
     return(Ok(await Mediator.Send(new AddArticleCommand(postModel))));
 }
 public AddArticleCommand(PostArticleModel postArticleModel)
 {
     PostArticleModel = postArticleModel;
 }
 public UpdateArticleCommand(int articleId, PostArticleModel postArticleModel)
 {
     ArticleId        = articleId;
     PostArticleModel = postArticleModel;
 }
 private Article MapPostModelToArticle(PostArticleModel updateModel)
 {
     return(Mapper.Map <Article>(updateModel));
 }
Beispiel #13
0
 public IActionResult PostArticle([FromBody] PostArticleModel data)
 {
     Models.Article.Pocos.Commit c = new Models.Article.Pocos.Commit();
     //var a = Json(c);
     return(Ok(new { Name = "Chinna", Email = "*****@*****.**" }));
 }