public void ANoteIsCreated() { int createdNoteId = 0; UnProcessableEntityException couldNotCreateNoteException = null; try { var userId = _fixture.LandmarkContext.Users.First().Id; var command = new CreateNoteCommand { UserId = userId, Text = "a sample note", Latitude = 50, Longitude = 50 }; createdNoteId = new CreateNoteCommandHandler(_fixture.LandmarkContext, new FakeDatetimeProvider()).Handle(command, CancellationToken.None).GetAwaiter().GetResult(); } catch (UnProcessableEntityException ex) { couldNotCreateNoteException = ex; } couldNotCreateNoteException.ShouldBeNull(); createdNoteId.ShouldBeGreaterThan(0); }
public IResult <INoteReturn> AddNote(string notebookKey, ICreateNoteParameters parameters) { if (notebookKey == null) { throw new ArgumentNullException("notebookKey"); } var keyResult = KeyParserHelper.ParseResult <INotebookKey>(notebookKey); if (!keyResult.Success) { return(keyResult.ConvertTo <INoteReturn>()); } var key = new NotebookKey(keyResult.ResultingObject); var createNoteResult = new CreateNoteCommand(_notebookUnitOfWork).Execute(key, _timeStamper.CurrentTimeStamp, parameters); if (!createNoteResult.Success) { return(createNoteResult.ConvertTo <INoteReturn>()); } _notebookUnitOfWork.Commit(); return(SyncParameters.Using(new SuccessResult <INoteReturn>(new[] { createNoteResult.ResultingObject }.Select(NoteProjectors.Select().Compile()).FirstOrDefault()), key)); }
public async Task Notes_ShouldBe_Saved() { var faker = new Faker(); var command = new CreateNoteCommand { Id = Guid.NewGuid(), Name = faker.Lorem.Sentence(), Content = faker.Lorem.Paragraph(), Latitude = faker.Address.Latitude(), Longitude = faker.Address.Longitude() }; await _backendFixture.LoginAsync(UserSeeder.TestEmail, UserSeeder.TestPassword); var noteDto = await _backendFixture.SendAsync <NoteDto>(HttpMethod.Post, Endpoints.Notes._, command); noteDto.Id.Should().Be(command.Id); noteDto.Name.Should().Be(command.Name); noteDto.Content.Should().Be(command.Content); noteDto.CreatedAt.Should().NotBe(new DateTime()); noteDto.UserId.Should().Be(UserSeeder.TestId); noteDto = await _backendFixture.SendAsync <NoteDto>(HttpMethod.Get, Endpoints.Notes._ + command.Id); noteDto.Id.Should().Be(command.Id); noteDto.Name.Should().Be(command.Name); noteDto.Content.Should().Be(command.Content); noteDto.CreatedAt.Should().NotBe(new DateTime()); noteDto.UserId.Should().Be(UserSeeder.TestId); }
static void Main(string[] args) { InitializeENodeFramework(); var commandService = ObjectContainer.Resolve <ICommandService>(); var noteId = ObjectId.GenerateNewStringId(); var command1 = new CreateNoteCommand { AggregateRootId = noteId, Title = "Sample Title1" }; var command2 = new ChangeNoteTitleCommand { AggregateRootId = noteId, Title = "Sample Title2" }; Console.WriteLine(string.Empty); commandService.ExecuteAsync(command1, CommandReturnType.EventHandled).Wait(); commandService.ExecuteAsync(command2, CommandReturnType.EventHandled).Wait(); Console.WriteLine(string.Empty); _logger.Info("Press Enter to exit..."); Console.ReadLine(); _configuration.ShutdownEQueue(); }
public void ExceptionIsThrownWithCorrectDetaisl() { int createdNoteId = 0; UnProcessableEntityException couldNotCreateNoteException = null; try { var userId = _fixture.LandmarkContext.Users.First().Id; var command = new CreateNoteCommand { UserId = userId, Text = "a sample note", Latitude = 150, Longitude = 50 }; createdNoteId = new CreateNoteCommandHandler(_fixture.LandmarkContext, new FakeDatetimeProvider()).Handle(command, CancellationToken.None).GetAwaiter().GetResult(); } catch (UnProcessableEntityException ex) { couldNotCreateNoteException = ex; } couldNotCreateNoteException.ShouldNotBeNull(); couldNotCreateNoteException.ModelStateErrors.Count().ShouldBe(1); var modelStateError = couldNotCreateNoteException.ModelStateErrors.First(); modelStateError.PropertyName.ShouldBe(nameof(CreateNoteCommand.Latitude)); }
public HttpResponseMessage Insert([FromBody] NoteModel noteModel) { var command = new CreateNoteCommand(noteModel); _commandDispatcher.Handle(command); return(Request.CreateResponse(HttpStatusCode.OK)); }
static void create_and_concurrent_update_aggregate_test() { Console.WriteLine(""); Console.WriteLine("----create_and_concurrent_update_aggregate_test start."); var noteId = ObjectId.GenerateNewStringId(); var command = new CreateNoteCommand { AggregateRootId = noteId, Title = "Sample Note" }; //执行创建聚合根的命令 var asyncResult = _commandService.ExecuteAsync(command).Result; Assert.NotNull(asyncResult); Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status); var commandResult = asyncResult.Data; Assert.NotNull(commandResult); Assert.AreEqual(CommandStatus.Success, commandResult.Status); var note = _memoryCache.Get <Note>(noteId); Assert.NotNull(note); Assert.AreEqual("Sample Note", note.Title); Assert.AreEqual(1, ((IAggregateRoot)note).Version); //并发执行修改聚合根的命令 var totalCount = 100; var finishedCount = 0; var waitHandle = new ManualResetEvent(false); for (var i = 0; i < totalCount; i++) { _commandService.ExecuteAsync(new ChangeNoteTitleCommand { AggregateRootId = noteId, Title = "Changed Note" }).ContinueWith(t => { var result = t.Result; Assert.NotNull(result); Assert.AreEqual(AsyncTaskStatus.Success, result.Status); Assert.NotNull(result.Data); Assert.AreEqual(CommandStatus.Success, result.Data.Status); var current = Interlocked.Increment(ref finishedCount); if (current == totalCount) { note = _memoryCache.Get <Note>(noteId); Assert.NotNull(note); Assert.AreEqual("Changed Note", note.Title); Assert.AreEqual(totalCount + 1, ((IAggregateRoot)note).Version); waitHandle.Set(); } }); } waitHandle.WaitOne(); Console.WriteLine("----create_and_concurrent_update_aggregate_test end."); }
private void CreateNoteImpl(CreateNoteCommand command) { NoteModel noteModel = Model.AddNoteInternal(command, null); CurrentSpace.RecordCreatedModel(noteModel); UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); }
public async Task <IActionResult> AddNoteAsync(CreateNoteRequest model, CancellationToken token) { var command = new CreateNoteCommand(model.UserId, model.Text, User.GetIdClaim()); await _commandBus.DispatchAsync(command, token); return(Ok(User.Identity.Name)); }
public async Task <IActionResult> CreateAsync([FromBody] CreateNoteCommand command) { await DispatchAsync(command); var created = GetDto <NoteDto>(command.Id); return(Ok(created)); }
/// <summary> /// Call this static method to reconstruct a RecordableCommand-derived /// object given an XmlElement that was previously saved with Serialize /// method. This method simply redirects the XmlElement to respective /// RecordableCommand-derived classes based on its type. /// </summary> /// <param name="element">The XmlElement from which the RecordableCommand /// can be reconstructed.</param> /// <returns>Returns the reconstructed RecordableCommand object. If a /// RecordableCommand cannot be reconstructed, this method throws a /// relevant exception.</returns> /// internal static RecordableCommand Deserialize(XmlElement element) { if (string.IsNullOrEmpty(element.Name)) { throw new ArgumentException("XmlElement without name"); } RecordableCommand command = null; switch (element.Name) { case "CreateNodeCommand": command = CreateNodeCommand.DeserializeCore(element); break; case "SelectModelCommand": command = SelectModelCommand.DeserializeCore(element); break; case "CreateNoteCommand": command = CreateNoteCommand.DeserializeCore(element); break; case "SelectInRegionCommand": command = SelectInRegionCommand.DeserializeCore(element); break; case "DragSelectionCommand": command = DragSelectionCommand.DeserializeCore(element); break; case "MakeConnectionCommand": command = MakeConnectionCommand.DeserializeCore(element); break; case "DeleteModelCommand": command = DeleteModelCommand.DeserializeCore(element); break; case "UndoRedoCommand": command = UndoRedoCommand.DeserializeCore(element); break; case "UpdateModelValueCommand": command = UpdateModelValueCommand.DeserializeCore(element); break; } if (null != command) { command.IsInPlaybackMode = true; return(command); } string message = string.Format("Unknown command: {0}", element.Name); throw new ArgumentException(message); }
public async Task <IActionResult> Add([FromBody] CreateNoteCommand createNote) { var result = await Mediator.Send(createNote); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public async Task AddAsync(CreateNoteCommand command) { if (string.IsNullOrEmpty(command.Title) || string.IsNullOrEmpty(command.Text)) { throw new InternalSystemException("Title and note content can't be empty."); } var query = $"INSERT INTO \"Notes\" (\"Title\", \"Text\") VALUES ('{command.Title}', '{command.Text}');"; await _context.Database.ExecuteSqlCommandAsync(query); }
static void create_and_concurrent_update_aggregate_test() { Console.WriteLine(""); Console.WriteLine("----create_and_concurrent_update_aggregate_test start."); var noteId = ObjectId.GenerateNewStringId(); var command = new CreateNoteCommand { AggregateRootId = noteId, Title = "Sample Note" }; //执行创建聚合根的命令 var asyncResult = _commandService.ExecuteAsync(command).Result; Assert.NotNull(asyncResult); Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status); var commandResult = asyncResult.Data; Assert.NotNull(commandResult); Assert.AreEqual(CommandStatus.Success, commandResult.Status); var note = _memoryCache.Get<Note>(noteId); Assert.NotNull(note); Assert.AreEqual("Sample Note", note.Title); Assert.AreEqual(1, ((IAggregateRoot)note).Version); //并发执行修改聚合根的命令 var totalCount = 100; var finishedCount = 0; var waitHandle = new ManualResetEvent(false); for (var i = 0; i < totalCount; i++) { _commandService.ExecuteAsync(new ChangeNoteTitleCommand { AggregateRootId = noteId, Title = "Changed Note" }).ContinueWith(t => { var result = t.Result; Assert.NotNull(result); Assert.AreEqual(AsyncTaskStatus.Success, result.Status); Assert.NotNull(result.Data); Assert.AreEqual(CommandStatus.Success, result.Data.Status); var current = Interlocked.Increment(ref finishedCount); if (current == totalCount) { note = _memoryCache.Get<Note>(noteId); Assert.NotNull(note); Assert.AreEqual("Changed Note", note.Title); Assert.AreEqual(totalCount + 1, ((IAggregateRoot)note).Version); waitHandle.Set(); } }); } waitHandle.WaitOne(); Console.WriteLine("----create_and_concurrent_update_aggregate_test end."); }
public async Task <IActionResult> CreateNote([FromBody] CreateNoteCommand command) { try { return(Ok(await _mediator.Send(command))); } catch { return(BadRequest()); } }
void CreateNoteImpl(CreateNoteCommand command) { NoteModel noteModel = CurrentWorkspace.AddNote( command.DefaultPosition, command.X, command.Y, command.NoteText, command.NodeId); CurrentWorkspace.RecordCreatedModel(noteModel); }
public async Task <IActionResult> Index(CreateNoteCommand command) { try { await _noteService.AddAsync(command); return(RedirectToAction("List", "Home")); } catch (InternalSystemException ex) { return(View()); } }
public async Task <Guid> CreateDefaultNoteAsync(NoteOptions options) { var spaceId = await GetOrCreateDefaultSpaceAsync(); var command = new CreateNoteCommand { SpaceId = spaceId, Title = ".Net 6", Content = ".Net 6 new feature", Status = options.Status }; return(await GetService <IMediator>().Send(command)); }
private void CreateNoteImpl(CreateNoteCommand command) { NoteModel noteModel = Model.CurrentWorkspace.AddNote( command.DefaultPosition, command.X, command.Y, command.NoteText, command.NodeId); CurrentSpace.RecordCreatedModel(noteModel); UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); }
static void duplicate_update_aggregate_command_test() { Console.WriteLine(""); Console.WriteLine("----duplicate_update_aggregate_command_test start."); var noteId = ObjectId.GenerateNewStringId(); var command1 = new CreateNoteCommand { AggregateRootId = noteId, Title = "Sample Note" }; //先创建一个聚合根 var status = _commandService.ExecuteAsync(command1).Result.Data.Status; Assert.AreEqual(CommandStatus.Success, status); var command2 = new ChangeNoteTitleCommand { AggregateRootId = noteId, Title = "Changed Note" }; //执行修改聚合根的命令 var asyncResult = _commandService.ExecuteAsync(command2).Result; Assert.NotNull(asyncResult); Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status); var commandResult = asyncResult.Data; Assert.NotNull(commandResult); Assert.AreEqual(CommandStatus.Success, commandResult.Status); var note = _memoryCache.Get <Note>(noteId); Assert.NotNull(note); Assert.AreEqual("Changed Note", note.Title); Assert.AreEqual(2, ((IAggregateRoot)note).Version); //在用重复执行该命令 asyncResult = _commandService.ExecuteAsync(command2).Result; Assert.NotNull(asyncResult); Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status); commandResult = asyncResult.Data; Assert.NotNull(commandResult); Assert.AreEqual(CommandStatus.Success, commandResult.Status); note = _memoryCache.Get <Note>(noteId); Assert.NotNull(note); Assert.AreEqual("Changed Note", note.Title); Assert.AreEqual(2, ((IAggregateRoot)note).Version); Console.WriteLine("----duplicate_update_aggregate_command_test end."); }
public void CreateNoteCommand_Constructor() { //Arrange Guid newNoteGuid = Guid.NewGuid(); //Act var noteCommand = new CreateNoteCommand(newNoteGuid.ToString(), "This is a note text", 100, 50, true); //Assert //This just validates the some properties inside the CreateNoteCommand class Assert.AreEqual(noteCommand.NoteText, "This is a note text"); Assert.AreEqual(noteCommand.X, 100); Assert.AreEqual(noteCommand.Y, 50); }
public async Task <IActionResult> PostAsync([FromBody] CreateNoteCommand 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 noteResource = _mapper.Map <Note, NoteResource>(result.Note); return(Ok(noteResource)); }
public async Task Handle_ShouldAddNoteCorrectly() { // Arrange var notebook = await _wolkDbContext.CreateAndSaveNotebook(); var request = new CreateNoteCommand { Content = "bladibla", Title = "Note title", NotebookId = notebook.Id }; // Act var result = await _handler.Handle(request, CancellationToken.None); // Assert var note = await _wolkDbContext.Notes.SingleAsync(); ShouldBeEqual(note, result); }
static void Main(string[] args) { ConfigSettings.Initialize(); InitializeENodeFramework(); var commandService = ObjectContainer.Resolve <ICommandService>(); var noteId = ObjectId.GenerateNewStringId(); var command1 = new CreateNoteCommand { AggregateRootId = noteId, Title = "Sample Title1" }; var command2 = new ChangeNoteTitleCommand { AggregateRootId = noteId, Title = "Sample Title2" }; System.Console.WriteLine(string.Empty); _logger.Info("Creating Note..."); commandService.ExecuteAsync(command1, CommandReturnType.EventHandled).Wait(); _logger.Info("Note create success."); System.Console.WriteLine(string.Empty); _logger.Info("Updating Note"); commandService.ExecuteAsync(command2, CommandReturnType.EventHandled).Wait(); _logger.Info("Note update success."); System.Console.WriteLine(string.Empty); using (var connection = new SqlConnection(ConfigSettings.ConnectionString)) { var note = connection.QueryList(new { Id = noteId }, ConfigSettings.NoteTable).Single(); _logger.InfoFormat("Note from ReadDB, id: {0}, title: {1}, version: {2}", note.Id, note.Title, note.Version); } System.Console.WriteLine(string.Empty); _logger.Info("Press Enter to exit..."); System.Console.ReadLine(); //_configuration.ShutdownEQueue(); System.Console.ReadKey(); }
public async Task Validate_NoValidationErrors() { // Arrange var notebook = await _wolkDbContext.CreateAndSaveNotebook(); var command = new CreateNoteCommand { 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()); }
static void create_and_update_aggregate_test() { Console.WriteLine(""); Console.WriteLine("----create_and_update_aggregate_test start."); var noteId = ObjectId.GenerateNewStringId(); var command = new CreateNoteCommand { AggregateRootId = noteId, Title = "Sample Note" }; //执行创建聚合根的命令 var asyncResult = _commandService.ExecuteAsync(command).Result; Assert.NotNull(asyncResult); Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status); var commandResult = asyncResult.Data; Assert.NotNull(commandResult); Assert.AreEqual(CommandStatus.Success, commandResult.Status); var note = _memoryCache.Get<Note>(noteId); Assert.NotNull(note); Assert.AreEqual("Sample Note", note.Title); Assert.AreEqual(1, ((IAggregateRoot)note).Version); //执行修改聚合根的命令 var command2 = new ChangeNoteTitleCommand { AggregateRootId = noteId, Title = "Changed Note" }; asyncResult = _commandService.ExecuteAsync(command2).Result; Assert.NotNull(asyncResult); Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status); commandResult = asyncResult.Data; Assert.NotNull(commandResult); Assert.AreEqual(CommandStatus.Success, commandResult.Status); note = _memoryCache.Get<Note>(noteId); Assert.NotNull(note); Assert.AreEqual("Changed Note", note.Title); Assert.AreEqual(2, ((IAggregateRoot)note).Version); Console.WriteLine("----create_and_update_aggregate_test end."); }
static void Main(string[] args) { InitializeENodeFramework(); var commandService = ObjectContainer.Resolve<ICommandService>(); var noteId = Guid.NewGuid(); var command1 = new CreateNoteCommand(noteId, "Sample Title1"); var command2 = new ChangeNoteTitleCommand(noteId, "Sample Title2"); Console.WriteLine(string.Empty); commandService.Execute(command1).Wait(); commandService.Execute(command2).Wait(); Console.WriteLine(string.Empty); Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); }
static void Main(string[] args) { InitializeENodeFramework(); var commandService = ObjectContainer.Resolve<ICommandService>(); var noteId = ObjectId.GenerateNewStringId(); var command1 = new CreateNoteCommand { AggregateRootId = noteId, Title = "Sample Title1" }; var command2 = new ChangeNoteTitleCommand { AggregateRootId = noteId, Title = "Sample Title2" }; Console.WriteLine(string.Empty); commandService.ExecuteAsync(command1, CommandReturnType.EventHandled).Wait(); commandService.ExecuteAsync(command2, CommandReturnType.EventHandled).Wait(); Console.WriteLine(string.Empty); _logger.Info("Press Enter to exit..."); Console.ReadLine(); _configuration.ShutdownEQueue(); }
private IResult <Notebook> CreateNotebook(DateTime timestamp, Employee employee, string comment) { var createNotebookResult = new CreateNotebookCommand(_inventoryUnitOfWork).Execute(timestamp); if (!createNotebookResult.Success) { return(createNotebookResult.ConvertTo((Notebook)null)); } var notebook = createNotebookResult.ResultingObject; if (!string.IsNullOrWhiteSpace(comment)) { var createNoteResult = new CreateNoteCommand(_inventoryUnitOfWork).Execute(notebook, timestamp, employee, comment); if (!createNoteResult.Success) { return(createNoteResult.ConvertTo((Notebook)null)); } } return(new SuccessResult <Notebook>(notebook)); }
public async Task Validate_ValidationErrors() { // Arrange var notebook = await _wolkDbContext.CreateAndSaveNotebook(); var command = new CreateNoteCommand { 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")); }
static void Main(string[] args) { ConfigSettings.Initialize(); InitializeENodeFramework(); var commandService = ObjectContainer.Resolve<ICommandService>(); var noteId = ObjectId.GenerateNewStringId(); var command1 = new CreateNoteCommand { AggregateRootId = noteId, Title = "Sample Title1" }; var command2 = new ChangeNoteTitleCommand { AggregateRootId = noteId, Title = "Sample Title2" }; Console.WriteLine(string.Empty); _logger.Info("Creating Note..."); commandService.ExecuteAsync(command1, CommandReturnType.EventHandled).Wait(); _logger.Info("Note create success."); Console.WriteLine(string.Empty); _logger.Info("Updating Note"); commandService.ExecuteAsync(command2, CommandReturnType.EventHandled).Wait(); _logger.Info("Note update success."); Console.WriteLine(string.Empty); using (var connection = new SqlConnection(ConfigSettings.ConnectionString)) { var note = connection.QueryList(new { Id = noteId }, ConfigSettings.NoteTable).Single(); _logger.InfoFormat("Note from ReadDB, id: {0}, title: {1}, version: {2}", note.Id, note.Title, note.Version); } Console.WriteLine(string.Empty); _logger.Info("Press Enter to exit..."); Console.ReadLine(); _configuration.ShutdownEQueue(); }
/// <summary> /// Call this static method to reconstruct a RecordableCommand-derived /// object given an XmlElement that was previously saved with Serialize /// method. This method simply redirects the XmlElement to respective /// RecordableCommand-derived classes based on its type. /// </summary> /// <param name="element">The XmlElement from which the RecordableCommand /// can be reconstructed.</param> /// <returns>Returns the reconstructed RecordableCommand object. If a /// RecordableCommand cannot be reconstructed, this method throws a /// relevant exception.</returns> /// internal static RecordableCommand Deserialize(XmlElement element) { if (string.IsNullOrEmpty(element.Name)) { throw new ArgumentException("XmlElement without name"); } switch (element.Name) { case "CreateNodeCommand": return(CreateNodeCommand.DeserializeCore(element)); case "SelectModelCommand": return(SelectModelCommand.DeserializeCore(element)); case "CreateNoteCommand": return(CreateNoteCommand.DeserializeCore(element)); case "SelectInRegionCommand": return(SelectInRegionCommand.DeserializeCore(element)); case "DragSelectionCommand": return(DragSelectionCommand.DeserializeCore(element)); case "MakeConnectionCommand": return(MakeConnectionCommand.DeserializeCore(element)); case "DeleteModelCommand": return(DeleteModelCommand.DeserializeCore(element)); case "UndoRedoCommand": return(UndoRedoCommand.DeserializeCore(element)); } string message = string.Format("Unknown command: {0}", element.Name); throw new ArgumentException(message); }
public async Task Create_IsSuccessful(NoteStatus status) { var spaceId = await _fixture.GetOrCreateDefaultSpaceAsync(); var command = new CreateNoteCommand { SpaceId = spaceId, Title = ".Net 6", Content = ".Net 6 new feature", Status = status }; var noteId = await _mediator.Send(command); var note = await _noteQuery.GetNoteAsync(noteId); Assert.Equal(command.SpaceId, note.SpaceId); Assert.Equal(command.Title, note.Title); Assert.Equal(command.Content, note.Content); Assert.Equal(command.Status, note.Status); if (status == NoteStatus.Draft) { Assert.Equal(0, note.Version); Assert.Equal(Visibility.Private, note.Visibility); } else { Assert.Equal(1, note.Version); Assert.Equal(Visibility.Public, note.Visibility); var noteHistories = await _noteQuery.GetHistoriesAsync(noteId); Assert.Single(noteHistories); } }
/// <summary> /// Call this static method to reconstruct a RecordableCommand-derived /// object given an XmlElement that was previously saved with Serialize /// method. This method simply redirects the XmlElement to respective /// RecordableCommand-derived classes based on its type. /// </summary> /// <param name="element">The XmlElement from which the RecordableCommand /// can be reconstructed.</param> /// <returns>Returns the reconstructed RecordableCommand object. If a /// RecordableCommand cannot be reconstructed, this method throws a /// relevant exception.</returns> /// internal static RecordableCommand Deserialize(XmlElement element) { if (string.IsNullOrEmpty(element.Name)) { throw new ArgumentException("XmlElement without name"); } RecordableCommand command = null; switch (element.Name) { case "OpenFileCommand": command = OpenFileCommand.DeserializeCore(element); break; case "PausePlaybackCommand": command = PausePlaybackCommand.DeserializeCore(element); break; case "RunCancelCommand": command = RunCancelCommand.DeserializeCore(element); break; case "CreateNodeCommand": command = CreateNodeCommand.DeserializeCore(element); break; case "SelectModelCommand": command = SelectModelCommand.DeserializeCore(element); break; case "CreateNoteCommand": command = CreateNoteCommand.DeserializeCore(element); break; case "SelectInRegionCommand": command = SelectInRegionCommand.DeserializeCore(element); break; case "DragSelectionCommand": command = DragSelectionCommand.DeserializeCore(element); break; case "MakeConnectionCommand": command = MakeConnectionCommand.DeserializeCore(element); break; case "DeleteModelCommand": command = DeleteModelCommand.DeserializeCore(element); break; case "UndoRedoCommand": command = UndoRedoCommand.DeserializeCore(element); break; case "ModelEventCommand": command = ModelEventCommand.DeserializeCore(element); break; case "UpdateModelValueCommand": command = UpdateModelValueCommand.DeserializeCore(element); break; case "ConvertNodesToCodeCommand": command = ConvertNodesToCodeCommand.DeserializeCore(element); break; case "CreateCustomNodeCommand": command = CreateCustomNodeCommand.DeserializeCore(element); break; case "SwitchTabCommand": command = SwitchTabCommand.DeserializeCore(element); break; } if (null != command) { command.IsInPlaybackMode = true; command.Tag = element.GetAttribute("Tag"); return(command); } string message = string.Format("Unknown command: {0}", element.Name); throw new ArgumentException(message); }
public async Task <IActionResult> CreateAsync([FromBody] CreateNoteCommand command) { return(Ok(await _mediator.Send(command))); }
private void CreateNoteImpl(CreateNoteCommand command) { NoteModel noteModel = Model.AddNoteInternal(command, null); CurrentSpace.RecordCreatedModel(noteModel); }