public async Task Get_Returns403_IfNoClaim() { var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{nameof(SampleConfigSet)}/{nameof(SampleConfig)}.json") .WithClaims() .TestContext; var configSet = new SampleConfigSet { SampleConfig = new Config <SampleConfig>(new SampleConfig { LlamaCapacity = 23 }) }; await target.Handle(testContext, option); responseFactory.Verify(f => f.BuildStatusResponse(testContext, 403)); }
public UpdateConfigurationFromJsonUploadCommandHandlerTests() { expectedIdentity = new ConfigurationIdentity(new ConfigurationClient(clientId), new Version(1, 0)); var configSet = new SampleConfigSet(); registry = new ConfigurationModelRegistry(); registry.AddConfigurationSet(configSet.BuildConfigurationSetModel()); configurationService = new Mock <IConfigurationService>(); configRepository = new Mock <IConfigRepository>(); configurationValidator = new Mock <IConfigurationValidator>(); configurationValidator.Setup(v => v.Validate(It.IsAny <object>(), It.IsAny <ConfigurationModel>(), expectedIdentity)) .ReturnsAsync(() => ValidationResult.CreateValid()); eventService = new Mock <IEventService>(); target = new UpdateConfigurationFromJsonUploadCommandHandler(registry, configurationService.Object, configRepository.Object, configurationValidator.Object, eventService.Object, new ConfigurationUploadMapper()); }
public DownloadEndpointTests() { var testconfigSet = new SampleConfigSet(); var definition = testconfigSet.BuildConfigurationSetModel(); configCollection = new ConfigurationModelRegistry(); configCollection.AddConfigurationSet(definition); responseFactory = new Mock <IHttpResponseFactory>(); configurationSetService = new Mock <IConfigurationSetService>(); expectedClient = new ConfigurationClient(clientId); configClientService = new Mock <IConfigurationClientService>(); configClientService.Setup(s => s.GetClientOrDefault(clientId)) .ReturnsAsync(() => expectedClient); option = new ConfigServerOptions(); target = new DownloadEndpoint(responseFactory.Object, configCollection, configurationSetService.Object, configClientService.Object); }
public async Task Get_GetsConfigAsJsonFile() { var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{nameof(SampleConfigSet)}/{nameof(SampleConfig)}.json") .WithClaims(readClaim) .TestContext; var configSet = new SampleConfigSet { SampleConfig = new Config <SampleConfig>(new SampleConfig { LlamaCapacity = 23 }) }; configurationSetService.Setup(s => s.GetConfigurationSet(typeof(SampleConfigSet), It.Is <ConfigurationIdentity>(i => i.Client.Equals(expectedClient)))) .ReturnsAsync(() => configSet); await target.Handle(testContext, option); responseFactory.Verify(f => f.BuildJsonFileResponse(testContext, configSet.SampleConfig.Value, $"{nameof(SampleConfig)}.json")); }
public async Task GetsConfigFromSets() { var config = new SampleConfig(); config.IsLlamaFarmer = true; var configSet = new SampleConfigSet(); configSet.SampleConfig = new Config <SampleConfig>(config); configSet.Instance = identity; configurationSetService.Setup(set => set.GetConfigurationSet(typeof(SampleConfigSet), identity)) .ReturnsAsync(configSet); var result = await target.GetAsync(typeof(SampleConfig), identity); var mappedConfig = (SampleConfig)result.GetConfiguration(); Assert.Equal(config, mappedConfig); Assert.Equal(config.IsLlamaFarmer, mappedConfig.IsLlamaFarmer); }
// /ConfigurationSet/{clientId}/{Configuration Set} // POST: Uploads configuration set file // /Configuration/{clientId}/{Config name} // POST: Uploads configuration file public UploadEnpointTests() { responseFactory = new Mock <IHttpResponseFactory>(); var testConfigSet = new SampleConfigSet(); configCollection = new ConfigurationModelRegistry(); configCollection.AddConfigurationSet(testConfigSet.BuildConfigurationSetModel()); commandBus = new Mock <ICommandBus>(); expectedClient = new ConfigurationClient(clientId) { ConfiguratorClaim = clientConfiguratorClaim.Value }; configClientService = new Mock <IConfigurationClientService>(); configClientService.Setup(s => s.GetClientOrDefault(clientId)) .ReturnsAsync(() => expectedClient); option = new ConfigServerOptions(); uploadToEditorMapper = new Mock <IUploadToEditorModelMapper>(); target = new UploadEnpoint(responseFactory.Object, configCollection, commandBus.Object, configClientService.Object, uploadToEditorMapper.Object); }
public async Task Get_GetsConfigSetAsJsonFile() { var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{nameof(SampleConfigSet)}.json") .WithClaims(readClaim) .TestContext; var configSet = new SampleConfigSet { SampleConfig = new Config <SampleConfig>(new SampleConfig { LlamaCapacity = 23 }), Options = new OptionSet <OptionFromConfigSet>(new[] { new OptionFromConfigSet { Id = 1, Description = "One" }, new OptionFromConfigSet { Id = 2, Description = "Two" } }, o => o.Id.ToString(), o => o.Description) }; configurationSetService.Setup(s => s.GetConfigurationSet(typeof(SampleConfigSet), It.Is <ConfigurationIdentity>(i => i.Client.Equals(expectedClient)))) .ReturnsAsync(() => configSet); dynamic payload = null; responseFactory.Setup(f => f.BuildJsonFileResponse(testContext, It.IsAny <object>(), $"{nameof(SampleConfigSet)}.json")) .Callback((HttpContext c, object p, string n) => payload = p) .Returns(() => Task.FromResult(true)); await target.Handle(testContext, option); Assert.NotNull(payload); var sampleConfig = payload.SampleConfig as SampleConfig; Assert.NotNull(sampleConfig); Assert.Equal(configSet.SampleConfig.Value.LlamaCapacity, sampleConfig.LlamaCapacity); var options = payload.Options as IEnumerable <OptionFromConfigSet>; Assert.NotNull(options); Assert.Equal(configSet.Options.Select(s => s), options); }