Exemplo n.º 1
0
        public void Update(UpdateWorkCommand work)
        {
            if (string.IsNullOrEmpty(work.Title) || string.IsNullOrEmpty(work.Content))
            {
                throw new LogicException(LogicExceptionMessage.LoginNameOrPasswordIsNull);
            }
            var info = _articleRepository.Get(work.Id);

            info.Title    = work.Title;
            info.Category = work.Category;
            info.Content  = work.Content;
            info.EditUser = LoginUserSection.CurrentUser.LoginName;
            info.EditDate = _currentTimeProvider.CurrentTime();
            _articleRepository.Update(info);
        }
Exemplo n.º 2
0
        public void Update_blogarticle_when_title_is_having_and_content_is_having_should_update_blogarticle()
        {
            //Arrange
            var articleRepositoryMocker   = new Mock <IBlogArticleRepository>();
            var currentTimeProviderMocker = new Mock <ICurrentTimeProvider>();
            var unitOfWorkFactoryMocker   = new Mock <IUnitOfWorkFactory>();
            var work = new UpdateWorkCommand
            {
                Id       = 6,
                Title    = "3",
                Category = Enums.Category.Web前段,
                Content  = "3"
            };

            LoginUserSection.Start(new LoginUserInformationForCodeSection
            {
                LoginName = "yzuhao"
            });

            var datetime = new DateTime(2018, 01, 01);

            currentTimeProviderMocker.Setup(x => x.CurrentTime()).Returns(datetime);

            var info = new BlogArticle
            {
                Id         = 6,
                Title      = "1",
                Category   = Enums.Category.Web前段,
                Content    = "2",
                CreateUser = "******",
                CreateDate = datetime
            };

            articleRepositoryMocker.Setup(x => x.Get(It.IsAny <int>())).Returns(info);

            var blogArticleLogic = new BlogArticleLogic(articleRepositoryMocker.Object,
                                                        currentTimeProviderMocker.Object, unitOfWorkFactoryMocker.Object);

            //Act
            blogArticleLogic.Update(work);

            //Assert
            info.Title.Should().Be("3");
            info.Category.Should().Be(Enums.Category.Web前段);
            info.Content.Should().Be("3");
        }
Exemplo n.º 3
0
        public void Update_blogarticle_when_title_is_having_and_content_is_none_should_throw_exception()
        {
            //Arrange
            var articleRepositoryMocker   = new Mock <IBlogArticleRepository>();
            var currentTimeProviderMocker = new Mock <ICurrentTimeProvider>();
            var unitOfWorkFactoryMocker   = new Mock <IUnitOfWorkFactory>();
            var work = new UpdateWorkCommand
            {
                Id       = 6,
                Title    = "3",
                Category = Enums.Category.Web前段,
                Content  = ""
            };

            var blogArticleLogic = new BlogArticleLogic(articleRepositoryMocker.Object,
                                                        currentTimeProviderMocker.Object, unitOfWorkFactoryMocker.Object);

            //Act
            //Assert
            Assert.Throws <LogicException>(() => blogArticleLogic.Update(work));
        }
Exemplo n.º 4
0
 public ActionResult Update(UpdateWorkCommand work)
 {
     _blogArticleLogic.Update(work);
     return(Json(new { Success = true }));
 }