public void Add_blogarticle_when_title_is_having_and_content_is_having_should_add_a_record_blogarticle() { //Arrange var articleRepositoryMocker = new Mock <IBlogArticleRepository>(); var currentTimeProviderMocker = new Mock <ICurrentTimeProvider>(); var unitOfWorkFactoryMocker = new Mock <IUnitOfWorkFactory>(); var work = new AddWorkCommand { Title = "1", Category = Enums.Category.Web前段, Content = "2" }; LoginUserSection.Start(new LoginUserInformationForCodeSection { LoginName = "yzuhao" }); var datetime = new DateTime(2018, 01, 01); currentTimeProviderMocker.Setup(x => x.CurrentTime()).Returns(datetime); var blogArticleLogic = new BlogArticleLogic(articleRepositoryMocker.Object, currentTimeProviderMocker.Object, unitOfWorkFactoryMocker.Object); //Act blogArticleLogic.Add(work); //Assert articleRepositoryMocker.Verify(x => x.Add(It.IsAny <BlogArticle>()), Times.Once); }
public void Add(AddWorkCommand work) { if (string.IsNullOrEmpty(work.Title) || string.IsNullOrEmpty(work.Content)) { throw new LogicException(LogicExceptionMessage.LoginNameOrPasswordIsNull); } var info = new BlogArticle { Title = work.Title, Category = work.Category, Content = work.Content, CreateUser = LoginUserSection.CurrentUser.LoginName, CreateDate = _currentTimeProvider.CurrentTime(), Status = Enums.Status.Exist }; _articleRepository.Add(info); }
public void Add_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 AddWorkCommand { Title = "1", Category = Enums.Category.Web前段, Content = "" }; var blogArticleLogic = new BlogArticleLogic(articleRepositoryMocker.Object, currentTimeProviderMocker.Object, unitOfWorkFactoryMocker.Object); //Act //Assert Assert.Throws <LogicException>(() => blogArticleLogic.Add(work)); }
public async Task <IActionResult> AddWork([FromForm] AddWorkCommand command) { command.AuthorId = HttpContext.User.Identity.Name; uint id; try { id = await CommandAsync(command); } catch (AuthenticationException) { return(Unauthorized()); } catch (InvalidOperationException) { return(BadRequest()); } return(Created("scientific-works/", new { ScientificWorkId = id })); }
public ActionResult Add(AddWorkCommand work) { _blogArticleLogic.Add(work); return(Json(new { Success = true })); }