public async Task ReturnFailedIfValidationFailed()
        {
            var config = new SampleConfig
            {
                LlamaCapacity = 23
            };
            var options = new List <OptionFromConfigSet>
            {
                new OptionFromConfigSet {
                    Id = 1, Description = "One"
                }
            };

            var input = new UpdateConfigurationSetFromJsonUploadCommand(expectedIdentity, typeof(SampleConfigSet), jsonPayload);

            configurationSetUploadMapper.Setup(r => r.MapConfigurationSetUpload(input.JsonUpload, model))
            .Returns(() => BuildConfigs(config, options));
            var validationResult = new ValidationResult(new[] { "Error", "Error2" });

            configurationValidator.Setup(v => v.Validate(It.IsAny <object>(), It.IsAny <ConfigurationModel>(), expectedIdentity))
            .ReturnsAsync(() => validationResult);
            var result = await target.Handle(input);

            Assert.False(result.IsSuccessful);
            Assert.Equal(string.Join(Environment.NewLine, new ValidationResult(new[] { validationResult, validationResult }).Errors), result.ErrorMessage);
        }
        public async Task RaisesEvent()
        {
            var config = new SampleConfig
            {
                LlamaCapacity = 23
            };
            var options = new List <OptionFromConfigSet>
            {
                new OptionFromConfigSet {
                    Id = 1, Description = "One"
                }
            };

            var input = new UpdateConfigurationSetFromJsonUploadCommand(expectedIdentity, typeof(SampleConfigSet), jsonPayload);

            configurationSetUploadMapper.Setup(r => r.MapConfigurationSetUpload(input.JsonUpload, model))
            .Returns(() => BuildConfigs(config, options));

            var result = await target.Handle(input);

            eventService.Verify(repo => repo.Publish(It.Is <ConfigurationUpdatedEvent>(c => c.ConfigurationType == typeof(SampleConfig) && c.Identity == expectedIdentity)));
        }
        public async Task CallsUpdateWithRegularConfig()
        {
            var config = new SampleConfig
            {
                LlamaCapacity = 23
            };
            var options = new List <OptionFromConfigSet>
            {
                new OptionFromConfigSet {
                    Id = 1, Description = "One"
                }
            };

            var input = new UpdateConfigurationSetFromJsonUploadCommand(expectedIdentity, typeof(SampleConfigSet), jsonPayload);

            configurationSetUploadMapper.Setup(r => r.MapConfigurationSetUpload(input.JsonUpload, model))
            .Returns(() => BuildConfigs(config, options));

            var result = await target.Handle(input);

            Assert.True(result.IsSuccessful);
            configRepository.Verify(repo => repo.UpdateConfigAsync(It.Is <ConfigInstance>(c => DoesMatch(c, config))));
        }
        public async Task DoesNotPublishEventIfValidationFailed()
        {
            var config = new SampleConfig
            {
                LlamaCapacity = 23
            };
            var options = new List <OptionFromConfigSet>
            {
                new OptionFromConfigSet {
                    Id = 1, Description = "One"
                }
            };

            var input = new UpdateConfigurationSetFromJsonUploadCommand(expectedIdentity, typeof(SampleConfigSet), jsonPayload);

            configurationSetUploadMapper.Setup(r => r.MapConfigurationSetUpload(input.JsonUpload, model))
            .Returns(() => BuildConfigs(config, options));
            configurationValidator.Setup(v => v.Validate(It.IsAny <object>(), It.IsAny <ConfigurationModel>(), expectedIdentity))
            .ReturnsAsync(() => new ValidationResult("Error"));
            var result = await target.Handle(input);

            eventService.Verify(ev => ev.Publish(It.IsAny <ConfigurationUpdatedEvent>()), Times.Never);
        }