Example #1
0
        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();
        }
Example #2
0
        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.");
        }
Example #3
0
        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();
        }
Example #4
0
        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();
        }
Example #5
0
        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();
        }
Example #6
0
        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();
        }
Example #7
0
        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.");
        }
 public void Handle(ICommandContext context, ChangeNoteTitleCommand command)
 {
     context.Get <Note>(command.AggregateRootId).ChangeTitle(command.Title);
 }