Ejemplo n.º 1
0
        public async Task CallsUpdateWithRegularConfig()
        {
            var config = new SampleConfig
            {
                LlamaCapacity = 23
            };
            var existingInstance = new ConfigInstance <SampleConfig>(new SampleConfig(), expectedIdentity);
            var input            = new UpdateConfigurationFromJsonUploadCommand(expectedIdentity, typeof(SampleConfig), JsonConvert.SerializeObject(config));

            var result = await target.Handle(input);

            Assert.True(result.IsSuccessful);
            configRepository.Verify(repo => repo.UpdateConfigAsync(It.Is <ConfigInstance>(c => c.ConfigurationIdentity == existingInstance.ConfigurationIdentity && config.LlamaCapacity == ((ConfigInstance <SampleConfig>)c).Configuration.LlamaCapacity)));
        }
Ejemplo n.º 2
0
        public async Task RaisesEvent()
        {
            var config = new SampleConfig
            {
                LlamaCapacity = 23
            };
            var existingInstance = new ConfigInstance <SampleConfig>(new SampleConfig(), expectedIdentity);
            var input            = new UpdateConfigurationFromJsonUploadCommand(expectedIdentity, typeof(SampleConfig), JsonConvert.SerializeObject(config));

            configurationService.Setup(r => r.GetAsync(input.ConfigurationType, input.Identity))
            .ReturnsAsync(() => existingInstance);

            var result = await target.Handle(input);

            eventService.Verify(repo => repo.Publish(It.Is <ConfigurationUpdatedEvent>(c => c.ConfigurationType == existingInstance.ConfigType && c.Identity == expectedIdentity)));
        }
Ejemplo n.º 3
0
        public async Task CallsUpdateWithCollectionConfig()
        {
            var config = new List <Option>
            {
                new Option {
                    Id = 1, Description = "One"
                }
            };
            var existingInstance = new ConfigCollectionInstance <Option>(expectedIdentity);
            var input            = new UpdateConfigurationFromJsonUploadCommand(expectedIdentity, typeof(Option), JsonConvert.SerializeObject(config));

            var result = await target.Handle(input);

            Assert.True(result.IsSuccessful);
            configRepository.Verify(repo => repo.UpdateConfigAsync(It.Is <ConfigInstance>(c => c.ConfigurationIdentity == existingInstance.ConfigurationIdentity && config.Count == ((ConfigCollectionInstance <Option>)c).Configuration.Count)));
        }
Ejemplo n.º 4
0
        public async Task DoesNotCallsUpdateIfValidationFailed()
        {
            var config = new SampleConfig
            {
                LlamaCapacity = 23
            };
            var existingInstance = new ConfigInstance <SampleConfig>(new SampleConfig(), expectedIdentity);
            var input            = new UpdateConfigurationFromJsonUploadCommand(expectedIdentity, typeof(SampleConfig), JsonConvert.SerializeObject(config));

            configurationService.Setup(r => r.GetAsync(input.ConfigurationType, input.Identity))
            .ReturnsAsync(() => existingInstance);
            configurationValidator.Setup(v => v.Validate(It.IsAny <object>(), It.IsAny <ConfigurationModel>(), expectedIdentity))
            .ReturnsAsync(() => new ValidationResult("Error"));
            var result = await target.Handle(input);

            configRepository.Verify(repo => repo.UpdateConfigAsync(It.IsAny <ConfigInstance>()), Times.Never);
        }
Ejemplo n.º 5
0
        public async Task ReturnFailedIfValidationFailed()
        {
            var config = new SampleConfig
            {
                LlamaCapacity = 23
            };
            var existingInstance = new ConfigInstance <SampleConfig>(new SampleConfig(), expectedIdentity);
            var input            = new UpdateConfigurationFromJsonUploadCommand(expectedIdentity, typeof(SampleConfig), JsonConvert.SerializeObject(config));
            var validationResult = new ValidationResult(new[] { "Error", "Error2" });

            configurationService.Setup(r => r.GetAsync(input.ConfigurationType, input.Identity))
            .ReturnsAsync(() => existingInstance);
            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, validationResult.Errors), result.ErrorMessage);
        }