public IActionResult PutModel(Guid manufactuerId, Guid modelId, [FromBody] PutModelName model)
        {
            if (ModelState.IsValid)
            {
                var command = new UpdateModelName(modelId, manufactuerId, model.ModelName);
                commandBus.AddCommand(command);
                commandBus.InvokeCommandsQueue();

                return(GetModel(manufactuerId, command.Id));
            }

            return(BadRequest(ModelState));
        }
Example #2
0
        public void ValidatorThrowsException_HandlerThrowsException()
        {
            var manufacturerId         = InsertManufacturerToDatabase();
            var modelId                = InsertModelToDatabase();
            var updateModelNameCommand = new UpdateModelName(modelId, manufacturerId, "UpdatedName");

            A.CallTo(() => updateModelNameValidator.Validate(updateModelNameCommand)).Throws <Exception>();

            Assert.ThrowsAny <Exception>(() => updateModelNameHandler.Handle(updateModelNameCommand));
            A.CallTo(() => updateModelNameValidator.Validate(updateModelNameCommand)).MustHaveHappened(Repeated.Exactly.Once);

            context.SaveChanges();
            var result = context.ModelName.FirstOrDefault(m => m.Id == updateModelNameCommand.Id);

            Assert.NotNull(result);
            Assert.Equal(modelId, result.Id);
            Assert.Equal(expectedModelName, result.Name);
        }
Example #3
0
        public void CommandValid_ModelNameUpdated()
        {
            var manufacturerId         = InsertManufacturerToDatabase();
            var modelId                = InsertModelToDatabase();
            var updateModelNameCommand = new UpdateModelName(modelId, manufacturerId, "UpdatedName");

            A.CallTo(() => updateModelNameValidator.Validate(updateModelNameCommand)).DoesNothing();

            updateModelNameHandler.Handle(updateModelNameCommand);

            context.SaveChanges();
            var result = context.ModelName.FirstOrDefault(m => m.Id == updateModelNameCommand.Id);

            A.CallTo(() => updateModelNameValidator.Validate(updateModelNameCommand)).MustHaveHappened(Repeated.Exactly.Once);
            Assert.NotNull(result);
            Assert.Equal(result.Id, updateModelNameCommand.Id);
            Assert.Equal(result.Name, updateModelNameCommand.Name);
        }