コード例 #1
0
        public void CanCreateProductWithCommand_CallsRepository()
        {
            var commandRepoMock = new Mock <ICommandStateRepository>();
            var productsMock    = new Mock <IProductService>();
            var commandState    = new Fakes.CommandState();

            commandRepoMock.Setup(t => t.CreateCommandState()).Returns(commandState);

            var guid = Guid.NewGuid();
            var name = "New Project";

            var sut           = new CommandManager(commandRepoMock.Object, new DateTimeProvider());
            var commandConfig = new CommandConfig {
                Assembly = TestGlobals.Assembly, NameSpace = TestGlobals.Namespace, Name = CommandTypes.Create.ToString(), ProcessorName = TestGlobals.Entity, Processor = productsMock.Object
            };

            sut.AddConfig(commandConfig);

            var commandDto = new CommandDto {
                Entity = TestGlobals.Entity, EntityGuid = guid, Name = CommandTypes.Create.ToString(), ParametersJson = @"{name: '" + name + "'}"
            };
            var sutResult = sut.ProcessCommand(commandDto);

            productsMock.Verify(v => v.CreateProduct(guid, name), Times.Once);
        }
コード例 #2
0
        public ICommand Build(ICommandProcessor processor)
        {
            var commandRepoMock = new Mock <ICommandStateRepository>();
            var commandState    = new Fakes.CommandState();

            commandRepoMock.Setup(t => t.CreateCommandState()).Returns(commandState);

            ICommand cmd = new T()
            {
                CommandRepository = commandRepoMock.Object,
                EntityGuid        = Guid.NewGuid(),
                CommandProcessor  = processor
            };

            return(cmd);
        }
コード例 #3
0
        public void CommandManager_CanMergeCommandsWithNoExistingState()
        {
            Guid entityGuid            = Guid.NewGuid();
            var  existingCreateCommand = new Fakes.CommandState {
                CommandTypeId = "CreateContactCommand", EntityGuid = entityGuid, Guid = Guid.NewGuid(), CreatedOn = DateTime.Now, ExecutedOn = DateTime.Now, ReceivedOn = DateTime.Now, ParametersJson = "{'Name': 'John Smith'}"
            };
            var existingChangeEmailCommand = new Fakes.CommandState {
                CommandTypeId = "ChangeEmailForContactCommand", EntityGuid = entityGuid, Guid = Guid.NewGuid(), CreatedOn = DateTime.Now, ExecutedOn = DateTime.Now, ReceivedOn = DateTime.Now, ParametersJson = "{'Email': '*****@*****.**'}"
            };
            var existingCommands = new List <ICommandState> {
                existingCreateCommand, existingChangeEmailCommand
            };
            DateTimeProvider dateTimeProvider = new DateTimeProvider();
            var repo = new Mock <ICommandStateRepository>();

            repo.Setup(s => s.CreateCommandState()).Returns(new Fakes.CommandState());
            repo.Setup(s => s.GetCommandStates(entityGuid)).Returns(existingCommands);
            var contactRepo = new EventSourcedMainRepository();
            var processor   = new ContactService(contactRepo, dateTimeProvider);
            // todo: make builder
            var sut = new CommandManager(repo.Object, dateTimeProvider);

            var processorConfig = new ProcessorConfig();

            processorConfig.Assembly  = "SoftwareManagementCore";
            processorConfig.NameSpace = "ContactsShared";
            processorConfig.Entity    = "Contact";
            processorConfig.Processor = processor;
            sut.AddConfig(processorConfig);

            // todo: make builder
            var updateEmailCommandDto = new CommandDto {
                CreatedOn = DateTime.Now.AddTicks(1), Entity = "Contact", EntityGuid = entityGuid, Guid = Guid.NewGuid(), Name = "ChangeEmailFor", ParametersJson = @"{Email: '*****@*****.**', OriginalEmail:'*****@*****.**'}"
            };
            //            var updateNameCommandDto = new CommandDto { CreatedOn = DateTime.Now.AddTicks(2), Entity = "Contact", EntityGuid = entityGuid, Guid = Guid.NewGuid(), Name = "Rename", ParametersJson = @"{ Name: 'James Smith', OriginalName: 'John Smith'}" };
            var commandDtos = new List <CommandDto> {
                updateEmailCommandDto
            };

            sut.MergeCommands(commandDtos);

            var contact = processor.GetContact(entityGuid);

            Assert.Equal("John Smith", contact.Name);
            Assert.Equal("*****@*****.**", contact.Email);
        }