Пример #1
0
        public HttpResponseMessage Update([FromBody] NoteModel noteModel)
        {
            var command = new UpdateNoteCommand(noteModel);

            _commandDispatcher.Handle(command);
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public IResult UpdateNote(string noteKey, IUpdateNoteParameters parameters)
        {
            if (noteKey == null)
            {
                throw new ArgumentNullException("noteKey");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var keyResult = KeyParserHelper.ParseResult <INoteKey>(noteKey);

            if (!keyResult.Success)
            {
                return(keyResult);
            }
            var parsedNoteKey = new NoteKey(keyResult.ResultingObject);

            var updateNoteResult = new UpdateNoteCommand(_notebookUnitOfWork).Execute(parsedNoteKey, _timeStamper.CurrentTimeStamp, parameters);

            if (!updateNoteResult.Success)
            {
                return(updateNoteResult);
            }

            _notebookUnitOfWork.Commit();

            return(SyncParameters.Using(new SuccessResult(), new NotebookKey(parsedNoteKey)));
        }
        public async Task HandleAsync(UpdateNoteCommand command)
        {
            var existingNote = await _noteMeContext.Notes
                               .AsTracking()
                               .FirstOrDefaultAsync(x => x.Id == command.Id);

            var oldNote = new Note
            {
                Id           = Guid.NewGuid(),
                ActualNoteId = existingNote.Id,
                Name         = existingNote.Name,
                Tags         = existingNote.Tags,
                Content      = existingNote.Content,
                Location     = existingNote.Location,
                Status       = StatusEnum.Historical,
                UserId       = existingNote.UserId
            };

            await _noteMeContext.AddAsync(oldNote);

            existingNote.Content  = command.Content;
            existingNote.Name     = command.Name;
            existingNote.Location = NoteMeGeometryFactory.CreatePoint(command.Longitude, command.Latitude);

            var noteDto = _mapper.Map <NoteDto>(existingNote);

            _cacheService.Set(noteDto);
        }
Пример #4
0
        public async Task <IActionResult> UpdateAsync(Guid id, [FromBody] UpdateNoteCommand command)
        {
            command.Id = id;
            await DispatchAsync(command);

            var updated = GetDto <NoteDto>(command.Id);

            return(Ok(updated));
        }
Пример #5
0
        public async Task <IActionResult> UpdateAsync([FromBody] UpdateNoteCommand command)
        {
            command.UserId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);
            var result = await _mediator.Send(command);

            if (!result.Success)
            {
                return(BadRequest(new ErrorResource(result.Message)));
            }

            var notesResource = _mapper.Map <Note, NoteResource>(result.Note);

            return(Ok(notesResource));
        }
Пример #6
0
        public void UpdateNoteCommandHandler_InvalidNoteId_ThrowsNotFoundException()
        {
            // Given
            var command = new UpdateNoteCommand {
                Id = 1, Text = "HEY!"
            };
            var handler = new UpdateNoteCommandHandler(this.Context, Substitute.For <IMediator>(), Substitute.For <ISecurityValidator>(), Substitute.For <ITextAnonymizingService>());

            // When
            TestDelegate action = () => handler.Handle(command, CancellationToken.None).GetAwaiter().GetResult();

            // Then
            Assert.That(action, Throws.InstanceOf <NotFoundException>());
        }
Пример #7
0
        public async Task Handle_NoteNotFound_ShouldThrowNotFoundException()
        {
            // Arrange
            var notebook = await _wolkDbContext.CreateAndSaveNotebook();

            var note = await _wolkDbContext.CreateAndSaveNote(notebook);

            var request = new UpdateNoteCommand
            {
                Id = note.Id + 1, Content = "bladibla", Title = "Note title", NotebookId = notebook.Id
            };

            // Act / Assert
            await Assert.ThrowsExceptionAsync <NotFoundException>(() =>
                                                                  _handler.Handle(request, CancellationToken.None));
        }
Пример #8
0
        public async Task Handle_ShouldUpdateNoteCorrectly()
        {
            // Arrange
            var notebook = await _wolkDbContext.CreateAndSaveNotebook();

            var note = await _wolkDbContext.CreateAndSaveNote();

            var request = new UpdateNoteCommand {
                Id = note.Id, Content = "bladibla", Title = "Note title", NotebookId = notebook.Id
            };

            // Act
            await _handler.Handle(request, CancellationToken.None);

            // Assert
            ShouldBeEqual(note, request);
        }
        public async Task Validate_NoValidationErrors()
        {
            // Arrange
            var notebook = await _wolkDbContext.CreateAndSaveNotebook();

            var command = new UpdateNoteCommand
            {
                Content    = "Note contents",
                Title      = new string('a', 199),
                NotebookId = notebook.Id,
                NoteType   = NoteType.PlainText
            };

            // Act
            var result = await _validator.ValidateAsync(command);

            // Assert
            Assert.IsFalse(result.Errors.Any());
        }
        public async Task Validate_ValidationErrors()
        {
            // Arrange
            var notebook = await _wolkDbContext.CreateAndSaveNotebook();

            var command = new UpdateNoteCommand
            {
                Content    = string.Empty,
                Title      = new string('a', 201),
                NotebookId = notebook.Id + 1,
                NoteType   = NoteType.NotSet
            };

            // Act
            var result = await _validator.ValidateAsync(command);

            // Assert
            Assert.AreEqual(3, result.Errors.Count);
            Assert.IsTrue(result.Errors.ElementAt(0).ErrorMessage.Contains("200 characters or fewer"));
            Assert.IsTrue(result.Errors.ElementAt(1).ErrorMessage.Contains("must not be equal to"));
            Assert.IsTrue(result.Errors.ElementAt(2).ErrorMessage.Contains("Notebook with ID"));
        }
Пример #11
0
        public async Task UpdateNoteCommandHandler_UpdatesNoteAndBroadcast_OnRequest()
        {
            // Given
            var note = new Note {
                Retrospective = new Retrospective {
                    FacilitatorHashedPassphrase = "whatever",
                    CurrentStage = RetrospectiveStage.Writing,
                    Title        = this.GetType().FullName
                },
                Participant = new Participant {
                    Name = "Tester"
                },
                Lane = this.Context.NoteLanes.FirstOrDefault(),
                Text = "Derp"
            };

            TestContext.WriteLine(note.Retrospective.UrlId);
            this.Context.Notes.Add(note);
            await this.Context.SaveChangesAsync();

            var updateCommand = new UpdateNoteCommand {
                Id = note.Id, Text = "Updated note"
            };
            var mediator          = Substitute.For <IMediator>();
            var securityValidator = Substitute.For <ISecurityValidator>();

            var handler = new UpdateNoteCommandHandler(this.Context, mediator, securityValidator, Substitute.For <ITextAnonymizingService>());

            // When
            await handler.Handle(updateCommand, CancellationToken.None);

            // Then
            this.Context.Entry(note).Reload();
            Assert.That(note.Text, Is.EqualTo("Updated note"));

            await securityValidator.Received().EnsureOperation(Arg.Any <Retrospective>(), SecurityOperation.AddOrUpdate, Arg.Is <Note>(n => n.Id == note.Id));

            await mediator.Received().Publish(Arg.Any <NoteUpdatedNotification>());
        }