public void PostCommentStoresAndSetsDates() { //Given var now = DateTime.Now; var todosRepository = new TestTodosRepository { Todos = new Dictionary <int, Todo> { { 5, new Todo { Id = 5, TodoComments = new List <TodoComment>() } } } }; var todosController = new TodosController(todosRepository); var todoComment = new TodoComment { Id = 1, Text = "A comment" }; //When var rc = todosController.PostComment(5, todoComment); //Then Assert.True(1 == rc.Count(), "Count is wrong"); Assert.True(5 == rc.First().Id, "Id is wrong"); Assert.True(1 == rc.First().TodoComments.First().Id, "TodoComment.Id is wrong"); Assert.True(now <= rc.First().TodoComments.First().UpdatedOn, "UpdatedOn should have been set"); Assert.True(5 == rc.First().TodoComments.First().TodoId, "TodoId is wrong"); }
public IEnumerable <string> Create(string word = "") { var article = "A"; if (Regex.IsMatch(word, "^[aeiouAEIoU]")) { article = "An"; } var todo = new Todo { Task = $"{article} {word} todo", IsComplete = false, CreateDate = DateTime.Now.ToUniversalTime(), DueDate = DateTime.Now.ToUniversalTime().Add(TimeSpan.FromDays(1.0)), CompleteDate = null }; todosRepository.Add(todo); // Make sure the Id gets generated var comments = new[] { "Comment 1", "Comment 2" }; foreach (var c in comments) { var comment = new TodoComment { Text = $"{c} for {todo.Id}", UpdatedOn = DateTime.Now.ToUniversalTime(), TodoId = todo.Id }; todosRepository.AddComment(todo, comment); } return(new [] { "todo created" }); }
private bool CouldNotDelete(TodoComment domainModel) { var result = !_repository.MarkForDelete(domainModel.Id); _repository.Persist(); return(result); }
public void AddComment(Todo todo, TodoComment todoComment) { var thisTodo = Todos[todo.Id]; todoComment = todoComment.Clone(); thisTodo.TodoComments.Add(todoComment); TodoComments[todoComment.Id] = todoComment; }
public void IsCommentValid_WhenNotNullOrWhitespace_ShouldReturnTrue() { //---------------Arrange------------------- var comment = new TodoComment { Comment = "a comment" }; //---------------Act---------------------- var result = comment.IsCommentValid(); //---------------Assert----------------------- Assert.IsTrue(result); }
public void IsIdValid_WhenNonEmptyGuid_ShouldReturnTrue() { //---------------Arrange------------------- var comment = new TodoComment { Id = Guid.NewGuid() }; //---------------Act---------------------- var result = comment.IsIdValid(); //---------------Assert----------------------- Assert.IsTrue(result); }
async Task IVsTypeScriptTodoCommentService.ReportTodoCommentsAsync( Document document, ImmutableArray <TodoComment> todoComments, CancellationToken cancellationToken) { using var _ = ArrayBuilder <TodoCommentData> .GetInstance(out var converted); var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); await TodoComment.ConvertAsync(document, todoComments, converted, cancellationToken).ConfigureAwait(false); await ReportTodoCommentDataAsync( document.Id, converted.ToImmutable(), cancellationToken).ConfigureAwait(false); }
public void IsCommentValid_WhenNullOrWhitespace_ShouldReturnFalse(string text) { //---------------Arrange------------------- var comment = new TodoComment { Comment = text }; //---------------Act---------------------- var result = comment.IsCommentValid(); //---------------Assert----------------------- Assert.IsFalse(result); }
public void IsIdValid_WhenEmptyGuid_ShouldReturnFalse() { //---------------Arrange------------------- var comment = new TodoComment { Id = Guid.Empty }; //---------------Act---------------------- var result = comment.IsIdValid(); //---------------Assert----------------------- Assert.IsFalse(result); }
public async Task <TodoComment> PostComment(TodoCommentDto todoCommentDto) { var comment = new TodoComment { AuthorName = _currentUser.Username, AuthorId = _currentUser.Id, CommentBody = todoCommentDto.CommentBody, ParentTodoId = todoCommentDto.ParentTodoId, }; await _dbRepository.AddAsync(comment); return(comment); }
protected async Task TestAsync(string codeWithMarker) { using var workspace = CreateWorkspace(codeWithMarker); var hostDocument = workspace.Documents.First(); var initialTextSnapshot = hostDocument.GetTextBuffer().CurrentSnapshot; var documentId = hostDocument.Id; var document = workspace.CurrentSolution.GetDocument(documentId); var service = document.GetLanguageService <ITodoCommentService>(); var todoComments = await service.GetTodoCommentsAsync( document, TodoCommentDescriptor.Parse( workspace.Options.GetOption(TodoCommentOptions.TokenList) ), CancellationToken.None ); using var _ = ArrayBuilder <TodoCommentData> .GetInstance(out var converted); await TodoComment.ConvertAsync( document, todoComments, converted, CancellationToken.None ); var expectedLists = hostDocument.SelectedSpans; Assert.Equal(converted.Count, expectedLists.Count); var sourceText = await document.GetTextAsync(); var tree = await document.GetSyntaxTreeAsync(); for (var i = 0; i < converted.Count; i++) { var todo = converted[i]; var span = expectedLists[i]; var line = initialTextSnapshot.GetLineFromPosition(span.Start); var text = initialTextSnapshot.GetText(span.ToSpan()); Assert.Equal(todo.MappedLine, line.LineNumber); Assert.Equal(todo.MappedColumn, span.Start - line.Start); Assert.Equal(todo.Message, text); } }
public IEnumerable <Todo> PostComment(int id, [FromBody] TodoComment todoComment) { var todos = Get(id); if (todos.Count() > 0) { foreach (var todo in todos) { todoComment.UpdatedOn = DateTime.Now.ToUniversalTime(); todoComment.TodoId = todo.Id; todosRepository.AddComment(todo, todoComment); break; } } return(Get()); }
public void PutWithCommentStoresAndSetsDates() { //Given var now = DateTime.Now; var todoCommentWithChange = new TodoComment { Id = 1, Text = "A Comment", UpdatedOn = now }; var todoCommentWithoutChange = new TodoComment { Id = 2, Text = "Unchanged", UpdatedOn = now }; var todo = new Todo { Id = 5, TodoComments = new List <TodoComment> { todoCommentWithChange, todoCommentWithoutChange } }; var todosRepository = new TestTodosRepository(); var todosController = new TodosController(todosRepository); //When todosRepository.Add(todo); todoCommentWithChange.Text = "Changed comment"; // Change the comment var rc = todosController.Put(todo); //Then Assert.True(1 == rc.Count(), "Count is wrong"); Assert.True(5 == rc.First().Id, "Todo Id is wrong"); var cChanged = rc.First().TodoComments.First(); Assert.True(1 == cChanged.Id, "TodoComment.Id is wrong"); Assert.True(now < cChanged.UpdatedOn, "UpdatedOn should have been set"); var cUnchanged = rc.First().TodoComments.Skip(1).First(); Assert.True(2 == cUnchanged.Id, "Second TodoComment.Id is wrong"); Assert.True(now == cUnchanged.UpdatedOn, "UpdatedOn should not have been set"); }
private ITaskItem CreateItem(Document document, SourceText text, SyntaxTree tree, TodoComment comment) { var textSpan = new TextSpan(comment.Position, 0); var location = tree == null ? Location.Create(document.FilePath, textSpan, text.Lines.GetLinePositionSpan(textSpan)) : tree.GetLocation(textSpan); var originalLineInfo = location.GetLineSpan(); var mappedLineInfo = location.GetMappedLineSpan(); return new TodoTaskItem( comment.Descriptor.Priority, comment.Message, document.Project.Solution.Workspace, document.Id, mappedLine: mappedLineInfo.StartLinePosition.Line, originalLine: originalLineInfo.StartLinePosition.Line, mappedColumn: mappedLineInfo.StartLinePosition.Character, originalColumn: originalLineInfo.StartLinePosition.Character, mappedFilePath: mappedLineInfo.HasMappedPath ? mappedLineInfo.Path : null, originalFilePath: document.FilePath); }
private bool InvalidCommentId(TodoComment domainModel) { return(!domainModel.IsIdValid()); }
private ITaskItem CreateItem(Document document, SourceText text, SyntaxTree tree, TodoComment comment) { var textSpan = new TextSpan(comment.Position, 0); var location = tree == null?Location.Create(document.FilePath, textSpan, text.Lines.GetLinePositionSpan(textSpan)) : tree.GetLocation(textSpan); var originalLineInfo = location.GetLineSpan(); var mappedLineInfo = location.GetMappedLineSpan(); return(new TodoTaskItem( comment.Descriptor.Priority, comment.Message, document.Project.Solution.Workspace, document.Id, mappedLine: mappedLineInfo.StartLinePosition.Line, originalLine: originalLineInfo.StartLinePosition.Line, mappedColumn: mappedLineInfo.StartLinePosition.Character, originalColumn: originalLineInfo.StartLinePosition.Character, mappedFilePath: mappedLineInfo.GetMappedFilePathIfExist(), originalFilePath: document.FilePath)); }
private TodoItem CreateItem(Document document, SourceText text, SyntaxTree tree, TodoComment comment) { // make sure given position is within valid text range. var textSpan = new TextSpan(Math.Min(text.Length, Math.Max(0, comment.Position)), 0); var location = tree == null?Location.Create(document.FilePath, textSpan, text.Lines.GetLinePositionSpan(textSpan)) : tree.GetLocation(textSpan); var originalLineInfo = location.GetLineSpan(); var mappedLineInfo = location.GetMappedLineSpan(); return(new TodoItem( comment.Descriptor.Priority, comment.Message, document.Project.Solution.Workspace, document.Id, mappedLine: mappedLineInfo.StartLinePosition.Line, originalLine: originalLineInfo.StartLinePosition.Line, mappedColumn: mappedLineInfo.StartLinePosition.Character, originalColumn: originalLineInfo.StartLinePosition.Character, mappedFilePath: mappedLineInfo.GetMappedFilePathIfExist(), originalFilePath: document.FilePath)); }
private TodoItem CreateItem(Document document, SourceText text, SyntaxTree tree, TodoComment comment) { // make sure given position is within valid text range. var textSpan = new TextSpan(Math.Min(text.Length, Math.Max(0, comment.Position)), 0); var location = tree == null ? Location.Create(document.FilePath, textSpan, text.Lines.GetLinePositionSpan(textSpan)) : tree.GetLocation(textSpan); var originalLineInfo = location.GetLineSpan(); var mappedLineInfo = location.GetMappedLineSpan(); return new TodoItem( comment.Descriptor.Priority, comment.Message, document.Project.Solution.Workspace, document.Id, mappedLine: mappedLineInfo.StartLinePosition.Line, originalLine: originalLineInfo.StartLinePosition.Line, mappedColumn: mappedLineInfo.StartLinePosition.Character, originalColumn: originalLineInfo.StartLinePosition.Character, mappedFilePath: mappedLineInfo.GetMappedFilePathIfExist(), originalFilePath: document.FilePath); }
private bool InvalidTodoItemId(TodoComment domainModel) { return(!domainModel.IsTodoItemIdValid() || CannotLocateTodoItem(domainModel)); }
private bool CannotLocateTodoItem(TodoComment domainModel) { var item = _todoItemRepository.FindById(domainModel.TodoItemId); return(item == null); }