public void Should_validate_command_and_update_app()
        {
            var command = new UpdateAppDetails
            {
                Id          = Guid.NewGuid(),
                Name        = "Name",
                Description = "Description",
                Folder      = "Folder"
            };

            var repositoryMock = new Mock <IAppRepository>();

            repositoryMock.Setup(x => x.GetById(command.Id)).Returns(new App());

            var validatorMock = new Mock <IValidator <UpdateAppDetails> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var createAppHandler = new UpdateAppDetailsHandler(repositoryMock.Object, validatorMock.Object);

            createAppHandler.Handle(command);

            validatorMock.Verify(x => x.Validate(command));
            repositoryMock.Verify(x => x.Update(It.IsAny <App>()));
        }
예제 #2
0
        public void UpdateDetails(UpdateAppDetails cmd, IValidator <UpdateAppDetails> validator)
        {
            validator.ValidateCommand(cmd);

            AddEvent(new AppDetailsUpdated
            {
                AggregateRootId = Id,
                Name            = cmd.Name,
                Description     = cmd.Description,
                Folder          = cmd.Folder
            });
        }
예제 #3
0
 public void Setup()
 {
     _app     = AppFactory.App();
     _command = new UpdateAppDetails
     {
         Id          = _app.Id,
         Name        = "New Name",
         Description = "New Description",
         Folder      = "New Folder"
     };
     _validatorMock = new Mock <IValidator <UpdateAppDetails> >();
     _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());
     _app.UpdateDetails(_command, _validatorMock.Object);
     _event = _app.Events.OfType <AppDetailsUpdated>().SingleOrDefault();
 }
예제 #4
0
        public void Should_throw_validation_exception_when_validation_fails()
        {
            var command = new UpdateAppDetails
            {
                Id          = Guid.NewGuid(),
                Name        = "Name",
                Description = "Description",
                Folder      = "Folder"
            };

            var appRepositoryMock = new Mock <IAppRepository>();

            var validatorMock = new Mock <IValidator <UpdateAppDetails> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult(new List <ValidationFailure> {
                new ValidationFailure("Id", "Id Error")
            }));

            var createAppHandler = new UpdateAppDetailsHandler(appRepositoryMock.Object, validatorMock.Object);

            Assert.Throws <ValidationException>(() => createAppHandler.Handle(command));
        }
예제 #5
0
        public async Task <IActionResult> UpdateDetails([FromBody] UpdateAppDetails model)
        {
            await Task.Run(() => _commandSender.Send <UpdateAppDetails, App>(model));

            return(new NoContentResult());
        }
예제 #6
0
 public IActionResult UpdateDetails([FromBody] UpdateAppDetails model)
 {
     _commandSender.Send <UpdateAppDetails, App>(model);
     return(new NoContentResult());
 }
예제 #7
0
 public IActionResult Update(UpdateAppDetails model)
 {
     _dispatcher.SendAndPublish <UpdateAppDetails, App>(model);
     return(new NoContentResult());
 }