public ConfigEndpointTests() { clients = new List <ConfigurationClient> { new ConfigurationClient { ClientId = " AplicationId-1" } }; repository = new Mock <IConfigurationClientService>(); repository.Setup(s => s.GetClientOrDefault(It.IsAny <string>())) .Returns((string value) => Task.FromResult(clients.SingleOrDefault(s => string.Equals(value, s.ClientId, StringComparison.OrdinalIgnoreCase)))); configSetConfig = new ConfigurationModelRegistry(); var configSetDef = new ConfigurationSetModel <SimpleConfigSet>(); configSetDef.GetOrInitialize(c => c.Config); configSetConfig.AddConfigurationSet(configSetDef); defaultConfig = new ConfigInstance <SimpleConfig>(new SimpleConfig { IntProperty = 43 }, new ConfigurationIdentity(clients[0], new Version(1, 0))); configurationService = new Mock <IConfigurationService>(); configurationService.Setup(r => r.GetAsync(typeof(SimpleConfig), It.Is <ConfigurationIdentity>(arg => arg.Client == clients[0]))).ReturnsAsync(defaultConfig); responseFactory = new Mock <IHttpResponseFactory>(); responseFactory.Setup(r => r.BuildJsonResponse(It.IsAny <HttpContext>(), defaultConfig.Configuration)) .Returns(Task.FromResult(true)); responseFactory = new Mock <IHttpResponseFactory>(); options = new ConfigServerOptions(); target = new ConfigEndpoint(new ConfigInstanceRouter(repository.Object, configurationService.Object, configSetConfig), repository.Object, responseFactory.Object); }
public async Task CorrectlyMapsAnomynousAccess() { var context = TestHttpContextBuilder.CreateForPath("") .TestContext; UserPermissions permission = null; factory.Setup(f => f.BuildJsonResponse(context, It.IsAny <UserPermissions>())) .Returns((HttpContext c, UserPermissions p) => { permission = p; return(Task.FromResult(true)); }); var anomynousOption = new ConfigServerOptions { AllowManagerAnomynousAccess = false, AllowAnomynousAccess = true, ClientAdminClaimType = string.Empty, ClientReadClaimType = string.Empty, ClientConfiguratorClaimType = string.Empty }; await target.Handle(context, anomynousOption); Assert.NotNull(permission); Assert.False(permission.CanAccessClientAdmin); Assert.False(permission.CanEditClients); Assert.False(permission.CanEditGroups); Assert.False(permission.CanDeleteArchives); }
// GET Gets All // POST Update Client // /{ClientId} GET public ConfigClientEndPointTests() { configurationClientService = new Mock <IConfigurationClientService>(); factory = new Mock <IHttpResponseFactory>(); commandBus = new Mock <ICommandBus>(); target = new ConfigClientEndPoint(configurationClientService.Object, factory.Object, commandBus.Object); options = new ConfigServerOptions(); }
// GET: Gets all configuration set summaries public ConfigurationSetEnpointTests() { responseFactory = new Mock <IHttpResponseFactory>(); configCollection = new ConfigurationModelRegistry(); var configSetModel = new ConfigurationSetModel <SampleConfigSet>("Sample", "Sample description"); configSetModel.GetOrInitialize(set => set.SampleConfig); configCollection.AddConfigurationSet(configSetModel); target = new ConfigurationSetEndpoint(responseFactory.Object, configCollection); options = new ConfigServerOptions(); }
public PermisionEndpointTest() { options = new ConfigServerOptions(); factory = new Mock <IHttpResponseFactory>(); clientService = new Mock <IConfigurationClientService>(); clientService.Setup(s => s.GetClientOrDefault(clientId)) .ReturnsAsync(expectedClient); target = new PermissionEndpoint(factory.Object, clientService.Object); expectedClient = new ConfigurationClient { ClientId = clientId, ConfiguratorClaim = "Configurator" }; }
public ConfigArchiveEndPointTests() { expectedClient = new ConfigurationClient(clientId); configClientService = new Mock <IConfigurationClientService>(); configClientService.Setup(s => s.GetClientOrDefault(clientId)) .ReturnsAsync(() => expectedClient); configArchive = new Mock <IConfigArchive>(); httpResponseFactory = new Mock <IHttpResponseFactory>(); var registry = new ConfigurationModelRegistry(); registry.SetVersion(version); target = new ConfigArchiveEndPoint(configClientService.Object, registry, configArchive.Object, httpResponseFactory.Object); options = new ConfigServerOptions(); }
public SnapshotEndpointTests() { httpResponseFactory = new Mock <IHttpResponseFactory>(); snapShotRepository = new Mock <IConfigurationSnapshotRepository>(); client = new ConfigurationClient { ClientId = clientId }; commandBus = new Mock <ICommandBus>(); configurationClientService = new Mock <IConfigurationClientService>(); configurationClientService.Setup(c => c.GetClientOrDefault(clientId)) .ReturnsAsync(client); options = new ConfigServerOptions(); target = new SnapshotEndpoint(snapShotRepository.Object, commandBus.Object, configurationClientService.Object, httpResponseFactory.Object); }
// Model/{ Client Id}/{ Configuration Set} // GET: Model for configuration set public ConfigurationSetModelEnpointTests() { expectedClient = new ConfigurationClient(clientId); responseFactory = new Mock <IHttpResponseFactory>(); modelPayloadMapper = new Mock <IConfigurationSetModelPayloadMapper>(); configCollection = new ConfigurationModelRegistry(); var configSetModel = new ConfigurationSetModel <SampleConfigSet>("Sample", "Sample description"); configSetModel.GetOrInitialize(set => set.SampleConfig); configCollection.AddConfigurationSet(configSetModel); configClientService = new Mock <IConfigurationClientService>(); configClientService.Setup(s => s.GetClientOrDefault(clientId)) .ReturnsAsync(expectedClient); target = new ConfigurationSetModelEndpoint(responseFactory.Object, modelPayloadMapper.Object, configCollection, configClientService.Object); options = new ConfigServerOptions(); }
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); }
// /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 TagEndpointTests() { tagOne = new Tag { Value = "Tag One" }; tagTwo = new Tag { Value = "Tag Two" }; registry = new ConfigurationModelRegistry(); registry.AddConfigurationSet(Create <ConfigSetWithTagOne>(tagOne)); registry.AddConfigurationSet(Create <ConfigSetWithTagTwo>(tagTwo)); registry.AddConfigurationSet(Create <ConfigSetWithTagOneAgain>(tagOne)); registry.AddConfigurationSet(Create <ConfigSetWithNoTag>(null)); options = new ConfigServerOptions(); responseFactory = new Mock <IHttpResponseFactory>(); responseFactory.Setup(r => r.BuildJsonResponse(It.IsAny <HttpContext>(), It.IsAny <IEnumerable <Tag> >())) .Returns(Task.FromResult(true)); target = new TagEndpoint(responseFactory.Object, registry); }
public ResourceEndpointTests() { expectedClient = new ConfigurationClient(clientId) { ConfiguratorClaim = clientConfiguratorClaim.Value, ReadClaim = clientReadClaim.Value }; expectedTargetClient = new ConfigurationClient(targetClientId) { ConfiguratorClaim = "SecondWriteClaim", ReadClaim = clientReadClaim.Value }; configClientService = new Mock <IConfigurationClientService>(); configClientService.Setup(s => s.GetClientOrDefault(clientId)) .ReturnsAsync(() => expectedClient); configClientService.Setup(s => s.GetClientOrDefault(targetClientId)) .ReturnsAsync(() => expectedTargetClient); resourceStore = new Mock <IResourceStore>(); httpResponseFactory = new Mock <IHttpResponseFactory>(); var registry = new ConfigurationModelRegistry(); registry.SetVersion(version); option = new ConfigServerOptions(); target = new ResourceEndpoint(configClientService.Object, registry, resourceStore.Object, httpResponseFactory.Object); }