public void Should_Convert_Post_Text_To_String() { var text = "this is my text"; string sut = PostText.Create(text).Value; sut.Should().Be(text); }
public void Different_Strings_Should_Create_Different_Post_Texts() { var text1 = PostText.Create("this is my text").Value; var text2 = PostText.Create("this is my other text").Value; using (new AssertionScope()) { text1.Should().NotBe(text2); text1.GetHashCode().Equals(text2.GetHashCode()).Should().BeFalse(); } }
public void Same_String_Should_Create_The_Same_Post_Text() { var text1 = PostText.Create("this is my text").Value; var text2 = PostText.Create("this is my text").Value; using (new AssertionScope()) { text1.Should().Be(text2); text1.GetHashCode().Equals(text2.GetHashCode()).Should().BeTrue(); } }
public async Task <Result <int> > Handle(EditPostCommand request, CancellationToken cancellationToken) { using (var tx = _session.BeginTransaction()) { var editor = await _session.LoadAsync <User>(request.UserID, cancellationToken); var postToEdit = await _session.QueryOver <Post>() .Fetch(SelectMode.ChildFetch, p => p.Author) .Where(p => p.ID == request.PostID) .SingleOrDefaultAsync(cancellationToken); if (!postToEdit.CanBeEditedBy(editor)) { _logger.Warning("User [{NickName}({UserID})] tried to edit post {PostID} but he wasn't allowed to.", editor.Nickname, request.UserID, request.PostID); return(Result.Failure <int>($"You're not allowed to edit post {postToEdit.ID}.")); } postToEdit.UpdateText(PostText.Create(request.Text).Value); postToEdit.UpdatePicture(Picture.Create(request.PictureRawBytes, postToEdit.Picture.Identifier).Value); try { await _session.SaveAsync(postToEdit, cancellationToken); await tx.CommitAsync(cancellationToken); _logger.Information("User [{Nickname}({UserID})] edited post {PostID}.", editor.Nickname, request.UserID, request.PostID); return(Result.Success(postToEdit.ID)); } catch (ADOException ex) { await tx.RollbackAsync(cancellationToken); _logger.Error("Failed to edit post {PostID} for user [{Nickname}({UserID})]. Error message: {ErrorMessage}", request.PostID, editor.Nickname, request.UserID, ex.Message); return(Result.Failure <int>(ex.Message)); } } }
public void Post_Text_From_String_Too_Long_Is_Not_Valid() { var sut = new string('x', 1000); PostText.Create(sut).IsFailure.Should().BeTrue(); }
public void Empty_Post_Text_Is_Not_Valid() { PostText.Create(string.Empty).IsFailure.Should().BeTrue(); }
public void Should_Create_A_Valid_Text_For_A_Post() { PostText.Create("this is my text").IsSuccess.Should().BeTrue(); }