Example #1
0
 public ConfigurationSetUploadMapperTests()
 {
     model = new ConfigurationSetModel <TestConfigurationSet>();
     model.GetOrInitialize(c => c.ConfigOne);
     model.GetOrInitialize(c => c.ConfigTwo);
     target = new ConfigurationSetUploadMapper(new ConfigurationUploadMapper());
 }
        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);
        }
Example #3
0
        private ConfigurationSetModel <TModel> Create <TModel>(Tag tag) where TModel : ConfigurationSet
        {
            var model = new ConfigurationSetModel <TModel>();

            model.RequiredClientTag = tag;
            return(model);
        }
Example #4
0
        public ConfigRouterTests()
        {
            clients = new List <ConfigurationClient>
            {
                new ConfigurationClient {
                    ClientId = " AplicationId-1"
                }
            };
            repository = new Mock <IConfigRepository>();
            repository.Setup(s => s.GetClientsAsync())
            .ReturnsAsync(clients);

            configSetConfig = new ConfigurationSetRegistry();
            var configSetDef = new ConfigurationSetModel <SimpleConfigSet>();

            configSetDef.GetOrInitialize(c => c.Config);
            configSetConfig.AddConfigurationSet(configSetDef);

            defaultConfig = new ConfigInstance <SimpleConfig>(new SimpleConfig {
                IntProperty = 43
            }, clients[0].ClientId);
            configurationService = new Mock <IConfigurationService>();
            configurationService.Setup(r => r.GetAsync(typeof(SimpleConfig), It.Is <ConfigurationIdentity>(arg => arg.ClientId == clients[0].ClientId))).ReturnsAsync(defaultConfig);

            responseFactory = new Mock <IConfigHttpResponseFactory>();
            responseFactory.Setup(r => r.BuildResponse(It.IsAny <HttpContext>(), defaultConfig.Configuration))
            .Returns(Task.FromResult(true));

            responseFactory = new Mock <IConfigHttpResponseFactory>();

            target = new ConfigEnpoint(new ConfigInstanceRouter(repository.Object, configurationService.Object, configSetConfig), responseFactory.Object);
        }
 public ConfigurationSetUploadMapperTests()
 {
     model = new ConfigurationSetModel(typeof(TestConfigurationSet));
     model.GetOrInitialize(nameof(TestConfigurationSet.ConfigOne), typeof(TestConfigOne));
     model.GetOrInitialize(nameof(TestConfigurationSet.ConfigTwo), typeof(TestConfigTwo));
     target = new ConfigurationSetUploadMapper();
 }
Example #6
0
        public ConfigurationEditPayloadMapperTests()
        {
            target     = new ConfigurationEditPayloadMapper(new TestOptionSetFactory(), new PropertyTypeProvider());
            definition = new SampleConfigSet().BuildConfigurationSetModel();
            sample     = new SampleConfig
            {
                Choice        = Choice.OptionThree,
                IsLlamaFarmer = true,
                Decimal       = 0.23m,
                StartDate     = new DateTime(2013, 10, 10),
                LlamaCapacity = 47,
                Name          = "Name 1",
                Option        = OptionProvider.OptionOne,
                MoarOptions   = new List <Option> {
                    OptionProvider.OptionOne, OptionProvider.OptionThree
                },
                ListOfConfigs = new List <ListConfig> {
                    new ListConfig {
                        Name = "One", Value = 23
                    }
                }
            };

            updatedSample = new SampleConfig
            {
                Choice        = Choice.OptionTwo,
                IsLlamaFarmer = false,
                Decimal       = 0.213m,
                StartDate     = new DateTime(2013, 10, 11),
                LlamaCapacity = 147,
                Name          = "Name 2",
                Option        = OptionProvider.OptionTwo,
                MoarOptions   = new List <Option> {
                    OptionProvider.OptionTwo, OptionProvider.OptionThree
                },
                ListOfConfigs = new List <ListConfig> {
                    new ListConfig {
                        Name = "Two plus Two", Value = 5
                    }
                }
            };
            dynamic updatedValue = new ExpandoObject();

            updatedValue.Choice        = updatedSample.Choice;
            updatedValue.IsLlamaFarmer = updatedSample.IsLlamaFarmer;
            updatedValue.Decimal       = updatedSample.Decimal;
            updatedValue.StartDate     = updatedSample.StartDate;
            updatedValue.LlamaCapacity = updatedSample.LlamaCapacity;
            updatedValue.Name          = updatedSample.Name;
            updatedValue.Option        = updatedSample.Option.Id;
            updatedValue.MoarOptions   = updatedSample.MoarOptions.Select(s => s.Id).ToList();
            updatedValue.ListOfConfigs = updatedSample.ListOfConfigs;
            var serilaisationSetting = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var json = JsonConvert.SerializeObject(updatedValue, serilaisationSetting);

            updatedObject = JObject.Parse(json);
        }
        public void CanGetOrInitializeByPropertyInfo()
        {
            var result   = new ConfigurationSetModel <SimpleConfigSet>();
            var gotValue = result.GetOrInitialize(typeof(SimpleConfigSet).GetProperty(nameof(SimpleConfigSet.Config)));

            Assert.Equal(1, result.Configs.Count());
            Assert.Equal(result.Configs.Single(), gotValue);
        }
        public void CanGetOrInitializeByGenericType()
        {
            var result   = new ConfigurationSetModel <SimpleConfigSet>();
            var gotValue = result.GetOrInitialize <SimpleConfig>(c => c.Config);

            Assert.Equal(1, result.Configs.Count());
            Assert.Equal(result.Configs.Single(), gotValue);
        }
        public void CanGetExistingType_Generic()
        {
            var result    = new ConfigurationSetModel <SimpleConfigSet>();
            var gotValue  = result.GetOrInitialize(c => c.Config);
            var gotValue2 = result.Get <SimpleConfig>();

            Assert.True(ReferenceEquals(gotValue, gotValue2));
        }
Example #10
0
        public void CanGetExistingType()
        {
            var result    = new ConfigurationSetModel(defaultType);
            var gotValue  = result.GetOrInitialize(nameof(SimpleConfig), typeof(SimpleConfig));
            var gotValue2 = result.Get(typeof(SimpleConfig));

            Assert.True(ReferenceEquals(gotValue, gotValue2));
        }
Example #11
0
        public void CanGetOrInitializeByType()
        {
            var result   = new ConfigurationSetModel(defaultType);
            var gotValue = result.GetOrInitialize(nameof(SimpleConfig), typeof(SimpleConfig));

            Assert.Equal(1, result.Configs.Count());
            Assert.Equal(result.Configs.Single(), gotValue);
        }
        public void CanGetOrInitializeByTypeDoesNotDuplicateInitialization()
        {
            var result    = new ConfigurationSetModel <SimpleConfigSet>();
            var gotValue  = result.GetOrInitialize(c => c.Config);
            var gotValue2 = result.GetOrInitialize(c => c.Config);

            Assert.Equal(1, result.Configs.Count());
            Assert.True(ReferenceEquals(gotValue, gotValue2));
        }
        public void GetOrInitializePopulatesModelProperties()
        {
            var result   = new ConfigurationSetModel <SimpleConfigSet>();
            var gotValue = result.GetOrInitialize(c => c.Config);

            Assert.Equal(1, result.Configs.Count());
            Assert.Equal(typeof(int), gotValue.ConfigurationProperties[nameof(SimpleConfig.IntProperty)].PropertyType);
            Assert.Equal("Int Property", gotValue.ConfigurationProperties[nameof(SimpleConfig.IntProperty)].PropertyDisplayName);
            Assert.Equal(nameof(SimpleConfig.IntProperty), gotValue.ConfigurationProperties[nameof(SimpleConfig.IntProperty)].ConfigurationPropertyName);
        }
Example #14
0
        // 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();
        }
Example #15
0
        protected ConfigurationSetModel BuildValidConfigurationSetModel()
        {
            var model = new ConfigurationSetModel()
            {
                Id    = ContentIdForConfigurationSetUpdate,
                Etag  = Guid.NewGuid().ToString(),
                Title = "an-article",
                Url   = new Uri("https://localhost"),
            };

            return(model);
        }
Example #16
0
        public void WebhooksServiceTryValidateModelForUpdateReturnsFailure()
        {
            // Arrange
            const bool expectedResponse = false;
            var        expectedValidConfigurationSetModel = new ConfigurationSetModel();
            var        service = BuildWebhooksService();

            // Act
            var result = service.TryValidateModel(expectedValidConfigurationSetModel);

            // Assert
            Assert.Equal(expectedResponse, result);
        }
        public UpdateConfigurationSetFromJsonUploadCommandHandlerTests()
        {
            expectedIdentity = new ConfigurationIdentity(new ConfigurationClient(clientId), new Version(1, 0));
            var configSet = new SampleConfigSet();

            registry = new ConfigurationModelRegistry();
            model    = configSet.BuildConfigurationSetModel();
            registry.AddConfigurationSet(model);
            configurationSetUploadMapper = new Mock <IConfigurationSetUploadMapper>();
            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 UpdateConfigurationSetFromJsonUploadCommandHandler(registry, configurationSetUploadMapper.Object, configRepository.Object, configurationValidator.Object, eventService.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 async Task PagesControllerCallsContentPageServiceUsingPagesDocumentRouteForOkResult(string route, Guid documentId, string actionMethod, int configurationSetCount)
        {
            // Arrange
            var controller = BuildController(route);
            var expectedConfigurationSetResult = new ConfigurationSetModel()
            {
                PhoneNumber = "1234", LinesOpenText = "lines are open"
            };

            A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedConfigurationSetResult);

            // Act
            var result = await RunControllerAction(controller, documentId, actionMethod).ConfigureAwait(false);

            // Assert
            Assert.IsType <OkObjectResult>(result);
            A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappened(configurationSetCount, Times.Exactly);

            controller.Dispose();
        }
Example #20
0
        public UpdateConfigurationFromEditorCommandHandlerTests()
        {
            command = new UpdateConfigurationFromEditorCommand(new ConfigurationIdentity(new ConfigurationClient(clientId), new Version(1, 0)), typeof(SampleConfig), "{}");
            var configSetModel = new ConfigurationSetModel <SampleConfigSet>();

            configSetModel.GetOrInitialize(set => set.SampleConfig);
            model            = configSetModel;
            configRepository = new Mock <IConfigRepository>();
            configurationUpdatePayloadMapper = new Mock <IConfigurationUpdatePayloadMapper>();
            configurationUpdatePayloadMapper.Setup(m => m.UpdateConfigurationInstance(It.IsAny <ConfigInstance>(), It.IsAny <string>(), It.IsAny <ConfigurationSetModel>()))
            .ReturnsAsync(() => new ConfigInstance <SampleConfig>());
            configSetRegistry = new Mock <IConfigurationModelRegistry>();
            configSetRegistry.Setup(r => r.GetConfigSetForConfig(typeof(SampleConfig)))
            .Returns(() => model);
            configurationService = new Mock <IConfigurationService>();
            eventService         = new Mock <IEventService>();
            validator            = new Mock <IConfigurationValidator>();
            validator.Setup(v => v.Validate(It.IsAny <object>(), It.IsAny <ConfigurationModel>(), It.IsAny <ConfigurationIdentity>()))
            .ReturnsAsync(() => ValidationResult.CreateValid());
            target = new UpdateConfigurationFromEditorCommandHandler(configurationService.Object, configurationUpdatePayloadMapper.Object, configSetRegistry.Object, validator.Object, configRepository.Object, eventService.Object);
        }
Example #21
0
        public async Task WebhooksServiceProcessConfigurationSetAsyncForUpdateReturnsBadRequest()
        {
            // Arrange
            const HttpStatusCode expectedResponse         = HttpStatusCode.BadRequest;
            var expectedValidConfigurationSetApiDataModel = BuildValidConfigurationSetApiDataModel();
            var expectedValidConfigurationSetModel        = new ConfigurationSetModel();
            var url     = new Uri("https://somewhere.com");
            var service = BuildWebhooksService();

            A.CallTo(() => FakeCmsApiService.GetItemAsync <ConfigurationSetApiDataModel>(A <Uri> .Ignored)).Returns(expectedValidConfigurationSetApiDataModel);
            A.CallTo(() => FakeMapper.Map <ConfigurationSetModel>(A <ConfigurationSetApiDataModel> .Ignored)).Returns(expectedValidConfigurationSetModel);

            // Act
            var result = await service.ProcessConfigurationSetAsync(url).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCmsApiService.GetItemAsync <ConfigurationSetApiDataModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <ConfigurationSetModel>(A <ConfigurationSetApiDataModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeConfigurationSetDocumentService.UpsertAsync(A <ConfigurationSetModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeConfigurationSetDocumentService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }
        public ConfigurationUpdatePayloadMapperTests()
        {
            configurationSet = new Mock <IConfigurationSetService>();
            configurationSet.Setup(r => r.GetConfigurationSet(typeof(SampleConfigSet), It.IsAny <ConfigurationIdentity>()))
            .ReturnsAsync(() => new SampleConfigSet {
                Options = new OptionSet <Option>(OptionProvider.Options, o => o.Id.ToString(), o => o.Description)
            });

            target     = new ConfigurationUpdatePayloadMapper(new TestOptionSetFactory(), new PropertyTypeProvider(), configurationSet.Object);
            definition = new SampleConfigSet().BuildConfigurationSetModel();
            sample     = new SampleConfig
            {
                Choice        = Choice.OptionThree,
                IsLlamaFarmer = true,
                Decimal       = 0.23m,
                StartDate     = new DateTime(2013, 10, 10),
                LlamaCapacity = 47,
                Name          = "Name 1",
                Option        = OptionProvider.OptionOne,
                MoarOptions   = new List <Option> {
                    OptionProvider.OptionOne, OptionProvider.OptionThree
                },
                ListOfConfigs = new List <ListConfig> {
                    new ListConfig {
                        Name = "One", Value = 23
                    }
                }
            };

            updatedSample = new SampleConfig
            {
                Choice        = Choice.OptionTwo,
                IsLlamaFarmer = false,
                Decimal       = 0.213m,
                StartDate     = new DateTime(2013, 10, 11),
                LlamaCapacity = 147,
                Name          = "Name 2",
                Option        = OptionProvider.OptionTwo,
                MoarOptions   = new List <Option> {
                    OptionProvider.OptionTwo, OptionProvider.OptionThree
                },
                ListOfConfigs = new List <ListConfig> {
                    new ListConfig {
                        Name = "Two plus Two", Value = 5
                    }
                }
            };
            dynamic updatedValue = new ExpandoObject();

            updatedValue.Choice        = updatedSample.Choice;
            updatedValue.IsLlamaFarmer = updatedSample.IsLlamaFarmer;
            updatedValue.Decimal       = updatedSample.Decimal;
            updatedValue.StartDate     = updatedSample.StartDate;
            updatedValue.LlamaCapacity = updatedSample.LlamaCapacity;
            updatedValue.Name          = updatedSample.Name;
            updatedValue.Option        = updatedSample.Option.Id;
            updatedValue.MoarOptions   = updatedSample.MoarOptions.Select(s => s.Id).ToList();
            updatedValue.ListOfConfigs = updatedSample.ListOfConfigs;
            var serilaisationSetting = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var json = JsonConvert.SerializeObject(updatedValue, serilaisationSetting);

            updatedObject = JObject.Parse(json);
        }
Example #23
0
        public void NewConfiguarationSetDefinition_ContainsNoDefinitions()
        {
            var result = new ConfigurationSetModel(defaultType);

            Assert.Equal(0, result.Configs.Count());
        }
Example #24
0
        public void NewConfiguarationSetDefinition_ContainsNoDefinitions()
        {
            var result = new ConfigurationSetModel <SimpleConfigSet>();

            Assert.Empty(result.Configs);
        }
        public void Throws_IfConfigTYpeNotFound()
        {
            var target = new ConfigurationSetModel <SimpleConfigSet>();

            Assert.Throws(typeof(ConfigurationModelNotFoundException), () => target.Get <SimpleConfig>());
        }
        public void NewConfiguarationSetDefinition_ContainsNoDefinitions()
        {
            var result = new ConfigurationSetModel <SimpleConfigSet>();

            Assert.Equal(0, result.Configs.Count());
        }