示例#1
0
        public void UpdateConfiguration(string key, string culture, string value)
        {
            var    config   = ListConfiguration.Find(c => c.Keyword == key && c.Specificulture == culture);
            string oldValue = config.Value;

            config.Value = value;
        }
        public static int GetLocalInt(string key, string culture)
        {
            var config = ListConfiguration.FirstOrDefault(c => c.Keyword == key && c.Specificulture == culture);

            int.TryParse(config?.Value, out int result);
            return(result);
        }
示例#3
0
 public static TConfiguration Add <TConfiguration>(this ListConfiguration <TConfiguration, VirtualType> source,
                                                   params Func <VirtualTypeBuilder, VirtualType>[] typeBuilders
                                                   ) => source.Add(
     typeBuilders.Select(builder =>
                         builder(BuildRoutine.VirtualType())
                         )
     );
        public IListConfiguration Create(IListDefinition source)
        {
            var configuration = new ListConfiguration(source.RequestType, source.ItemType, source.ResultType);

            var completedProperties = new List <PropertyInfo>();

            foreach (var property in source.RequestProperties)
            {
                if (!IsSearchProperty(property))
                {
                    continue;
                }

                var searchConfiguration = searchConfigurationFactory.Create(property, source);
                configuration.SearchConfigurations.Add(searchConfiguration);
                completedProperties.Add(property);
            }

            configuration.PageConfiguration = pageConfigurationFactory.Create(source);
            if (configuration.PageConfiguration?.RequestProperty != null)
            {
                completedProperties.Add(configuration.PageConfiguration.RequestProperty);
            }

            configuration.RowsConfiguration = rowsConfigurationFactory.Create(source);
            if (configuration.RowsConfiguration?.RequestProperty != null)
            {
                completedProperties.Add(configuration.RowsConfiguration.RequestProperty);
            }

            configuration.SortColumnConfiguration = sortColumnConfigurationFactory.Create(source);
            if (configuration.SortColumnConfiguration?.RequestProperty != null)
            {
                completedProperties.Add(configuration.SortColumnConfiguration.RequestProperty);
            }

            configuration.SortDirectionConfiguration = sortDirectionConfigurationFactory.Create(source);
            if (configuration.SortDirectionConfiguration?.RequestProperty != null)
            {
                completedProperties.Add(configuration.SortDirectionConfiguration.RequestProperty);
            }

            foreach (var requestProperty in source.RequestProperties.Where(x => !completedProperties.Contains(x)))
            {
                var propertyConfiguration = propertyConfigurationFactory.Create(requestProperty, source);
                if (propertyConfiguration == null)
                {
                    continue;
                }

                configuration.PropertyConfigurations.Add(propertyConfiguration);
            }

            configuration.PostRedirectGetConfiguration = postRedirectGetConfigurationFactory.Create(source);
            configuration.TransferValuesConfiguration  = transferValuesConfigurationFactory.Create(source);
            configuration.ModelActivatorConfiguration  = modelActivatorConfigurationFactory.Create(source);

            return(configuration);
        }
示例#5
0
        public void Returns_empty_list_when_no_items_are_added()
        {
            var testing = new ListConfiguration <string, string>("dummy", "test");

            var actual = testing.Get();

            Assert.AreEqual(0, actual.Count);
        }
示例#6
0
 public VirtualType()
 {
     Name              = new SingleConfiguration <VirtualType, string>(this, nameof(Name), true);
     Namespace         = new SingleConfiguration <VirtualType, string>(this, nameof(Namespace), true);
     IsInterface       = new SingleConfiguration <VirtualType, bool>(this, nameof(IsInterface));
     DefaultInstanceId = new SingleConfiguration <VirtualType, string>(this, nameof(DefaultInstanceId), true);
     ToStringMethod    = new SingleConfiguration <VirtualType, Func <VirtualObject, string> >(this, nameof(ToStringMethod));
     AssignableTypes   = new ListConfiguration <VirtualType, VirtualType>(this, nameof(AssignableTypes));
     Methods           = new ListConfiguration <VirtualType, IMethod>(this, nameof(Methods));
 }
示例#7
0
        public int GetLocalInt(string key, string culture, int defaultValue = 0)
        {
            var config = ListConfiguration.Find(c => c.Keyword == key && c.Specificulture == culture);

            if (!int.TryParse(config?.Value, out int result))
            {
                result = defaultValue;
            }
            return(result);
        }
        public ConventionBasedServiceClientConfiguration()
        {
            ServiceUrlBase = new SingleConfiguration <ConventionBasedServiceClientConfiguration, string>(this, nameof(ServiceUrlBase), true);

            RequestHeaders = new ListConfiguration <ConventionBasedServiceClientConfiguration, string>(this, nameof(RequestHeaders));

            Exception                = new ConventionBasedConfiguration <ConventionBasedServiceClientConfiguration, ExceptionResult, Exception>(this, nameof(Exception));
            RequestHeaderValue       = new ConventionBasedConfiguration <ConventionBasedServiceClientConfiguration, string, string>(this, nameof(RequestHeaderValue));
            ResponseHeaderProcessors = new ListConfiguration <ConventionBasedServiceClientConfiguration, IHeaderProcessor>(this, nameof(ResponseHeaderProcessors));
        }
 private void FillItemTypes(ListConfiguration listConfig)
 {
     foreach (ListItemConfiguration listItemConfig in listConfig.ListItemConfigurations)
     {
         if (listItemConfig.Value is ObjectConfiguration)
         {
             ObjectConfiguration referenceObject = listItemConfig.Value as ObjectConfiguration;
             listItemConfig.Type = referenceObject.Type;
         }
     }
 }
示例#10
0
        public void Facade_add_params_array()
        {
            var testing = new ListConfiguration <string, string>("dummy", "test");

            testing.Add("1", "2");
            var actual = testing.Get();

            Assert.AreEqual(2, actual.Count);
            Assert.AreEqual("1", actual[0]);
            Assert.AreEqual("2", actual[1]);
        }
示例#11
0
        public VirtualMethod(IType parentType)
        {
            this.parentType = parentType;

            Name                 = new SingleConfiguration <VirtualMethod, string>(this, nameof(Name), true);
            ReturnType           = new SingleConfiguration <VirtualMethod, IType>(this, nameof(ReturnType), true);
            Body                 = new SingleConfiguration <VirtualMethod, Func <object, object[], object> >(this, nameof(Body), true);
            TypeRetrieveStrategy = new SingleConfiguration <VirtualMethod, Func <object, IType> >(this, nameof(TypeRetrieveStrategy), true);
            Parameters           = new ListConfiguration <VirtualMethod, IParameter>(this, nameof(Parameters));

            TypeRetrieveStrategy.Set(o => o is VirtualObject vo ? vo.Type : o.GetTypeInfo());
        }
示例#12
0
        public void FactoryMethod_Succeeds()
        {
            var activator = new ModelActivator(null);
            var source    = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result))
            {
                ModelActivatorConfiguration = new ModelActivatorConfiguration(_ => new Request())
            };

            var result = activator.CreateInstance(source);

            result.Should().BeOfType <Request>();
        }
示例#13
0
        public void NoFactory_Throws()
        {
            var activator = new ModelActivator(null);
            var source    = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result))
            {
                ModelActivatorConfiguration = new ModelActivatorConfiguration(null, null, null)
            };

            activator.Invoking(x => x.CreateInstance(source))
            .Should()
            .ThrowExactly <ArgumentException>();
        }
        private IListConfiguration GetListConfiguration(string name, IContainer container)
        {
            IListConfiguration listConfig = container.Configuration.GetListConfiguration(name);

            if (listConfig == null)
            {
                listConfig      = new ListConfiguration();
                listConfig.Name = name;
                container.Configuration.AddListConfiguration(listConfig);
            }

            return(listConfig);
        }
示例#15
0
        public void Facade_when_adding_item__parent_configuration_can_be_used()
        {
            var testing = new ListConfiguration <string, string>("dummy", "test");

            testing.Add(s => s.ToCharArray().Select(c => c.ToString(CultureInfo.InvariantCulture)));
            testing.Add(s => s.Replace("d", "s").Replace("m", "n"));

            var actual = testing.Get();

            Assert.AreEqual(6, actual.Count);
            Assert.AreEqual("d", actual[0]);
            Assert.AreEqual("u", actual[1]);
            Assert.AreEqual("m", actual[2]);
            Assert.AreEqual("m", actual[3]);
            Assert.AreEqual("y", actual[4]);
            Assert.AreEqual("sunny", actual[5]);
        }
        public ConventionBasedServiceConfiguration()
        {
            RootPath = new SingleConfiguration <ConventionBasedServiceConfiguration, string>(this, nameof(RootPath), true);

            EnableTestApp = new SingleConfiguration <ConventionBasedServiceConfiguration, bool>(this, nameof(EnableTestApp), true);
            TestAppPath   = new SingleConfiguration <ConventionBasedServiceConfiguration, string>(this, nameof(TestAppPath), true);

            AllowGet = new ConventionBasedConfiguration <ConventionBasedServiceConfiguration, OperationWithObjectModel, bool>(this, nameof(AllowGet), true);

            RequestHeaders          = new ListConfiguration <ConventionBasedServiceConfiguration, string>(this, nameof(RequestHeaders));
            RequestHeaderProcessors = new ListConfiguration <ConventionBasedServiceConfiguration, IHeaderProcessor>(this, nameof(RequestHeaderProcessors));

            ResponseHeaders     = new ListConfiguration <ConventionBasedServiceConfiguration, string>(this, nameof(ResponseHeaders));
            ResponseHeaderValue = new ConventionBasedConfiguration <ConventionBasedServiceConfiguration, string, string>(this, nameof(ResponseHeaderValue));

            ExceptionResult = new ConventionBasedConfiguration <ConventionBasedServiceConfiguration, Exception, ExceptionResult>(this, nameof(ExceptionResult));
        }
示例#17
0
        public void Merges_with_other_ListConfiguration_adding_other_s_items_to_the_end()
        {
            var testing      = new ListConfiguration <string, string>("dummy", "test");
            var testingOther = new ListConfiguration <string, string>("dummy", "test");

            testing.Add("1", "2");
            testingOther.Add("3", "4");

            testing.Merge(testingOther);

            var actual = testing.Get();

            Assert.AreEqual(4, actual.Count);
            Assert.AreEqual("1", actual[0]);
            Assert.AreEqual("2", actual[1]);
            Assert.AreEqual("3", actual[2]);
            Assert.AreEqual("4", actual[3]);
        }
示例#18
0
        public bool UpdateConfiguration(string key, string culture, string value)
        {
            var    config   = ListConfiguration.Find(c => c.Keyword == key && c.Specificulture == culture);
            string oldValue = config.Value;

            config.Value = value;
            var result = ConfigurationViewModel.Repository.SaveModel(config);

            if (result.IsSucceed)
            {
                return(true);
            }
            else
            {
                config.Value = oldValue;
                return(false);
            }
        }
示例#19
0
        public void FactoryType_Service_Succeeds()
        {
            var serviceProvider = new ServiceCollection().AddSingleton <Factory>().BuildServiceProvider();
            var httpContext     = new Mock <HttpContext>();
            var hca             = new Mock <IHttpContextAccessor>();

            hca.SetupGet(x => x.HttpContext).Returns(httpContext.Object);
            httpContext.SetupGet(x => x.RequestServices).Returns(serviceProvider);

            var activator = new ModelActivator(hca.Object);
            var source    = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result))
            {
                ModelActivatorConfiguration = new ModelActivatorConfiguration(typeof(Factory))
            };

            var result = activator.CreateInstance(source);

            result.Should().BeOfType <Request>();
        }
示例#20
0
        public void Returns_added_items()
        {
            var testing = new ListConfiguration <string, string>("dummy", "test");

            testing.Add(new List <string> {
                "1", "2"
            });
            testing.Add(new List <string> {
                "3", "4"
            });

            var actual = testing.Get();

            Assert.AreEqual(4, actual.Count);
            Assert.AreEqual("1", actual[0]);
            Assert.AreEqual("2", actual[1]);
            Assert.AreEqual("3", actual[2]);
            Assert.AreEqual("4", actual[3]);
        }
示例#21
0
        public void UnableToResolveFactory_Throws()
        {
            var serviceProvider = new ServiceCollection().BuildServiceProvider();
            var httpContext     = new Mock <HttpContext>();
            var hca             = new Mock <IHttpContextAccessor>();

            hca.SetupGet(x => x.HttpContext).Returns(httpContext.Object);
            httpContext.SetupGet(x => x.RequestServices).Returns(serviceProvider);

            var activator = new ModelActivator(hca.Object);
            var source    = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result))
            {
                ModelActivatorConfiguration = new ModelActivatorConfiguration(typeof(Request))
            };

            activator.Invoking(x => x.CreateInstance(source))
            .Should()
            .ThrowExactly <NullReferenceException>();
        }
        public async Task Succeeds()
        {
            var model         = new TestRequest();
            var modelProvider = new Mock <IRequestModelProvider>();

            modelProvider.Setup(x => x.GetCurrentRequestModel()).Returns(model);
            var configurationProvider = new Mock <IListConfigurationProvider>();

            var listConfiguration = new ListConfiguration(typeof(TestRequest), typeof(TestItem), typeof(TestResult))
            {
                PostRedirectGetConfiguration = new PostRedirectGetConfiguration("Index", true),
                PageConfiguration            = new PageConfiguration("Page", 1),
                RowsConfiguration            = new RowsConfiguration("Rows", 20),
                SortColumnConfiguration      = new SortColumnConfiguration("Ordx", "Text"),
                SortDirectionConfiguration   = new SortDirectionConfiguration("Ordd", Direction.Ascending)
            };

            configurationProvider.Setup(x => x.GetConfiguration(It.IsAny <Type>())).Returns(listConfiguration);

            var actionFilter = new PostRedirectGetActionFilter(modelProvider.Object, configurationProvider.Object);

            actionFilter.Order.Should().Be(1);
            var httpContext   = new Mock <HttpContext>();
            var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ControllerActionDescriptor()
            {
                ActionName = "Index"
            });

            var httpRequest             = new Mock <HttpRequest>();
            var actionExecutionDelegate = new Mock <ActionExecutionDelegate>();

            httpRequest.SetupGet(x => x.Method).Returns("POST");
            httpContext.SetupGet(x => x.Request).Returns(httpRequest.Object);

            var controller = new Mock <Controller>();

            var actionExecutingContext = new ActionExecutingContext(actionContext, new List <IFilterMetadata>(), new RouteValueDictionary(), controller.Object);

            await actionFilter.OnActionExecutionAsync(actionExecutingContext, actionExecutionDelegate.Object);

            actionExecutingContext.Result.Should().BeOfType <RedirectToActionResult>();
        }
        public async Task Enabled_False_Fails()
        {
            var model         = new TestRequest();
            var modelProvider = new Mock <IRequestModelProvider>();

            modelProvider.Setup(x => x.GetCurrentRequestModel()).Returns(model);
            var configurationProvider = new Mock <IListConfigurationProvider>();

            var listConfiguration = new ListConfiguration(typeof(TestRequest), typeof(TestItem), typeof(TestResult))
            {
                PostRedirectGetConfiguration = new PostRedirectGetConfiguration("Index", false)
            };

            configurationProvider.Setup(x => x.GetConfiguration(It.IsAny <Type>())).Returns(listConfiguration);

            var actionFilter = new PostRedirectGetActionFilter(modelProvider.Object, configurationProvider.Object);

            actionFilter.Order.Should().Be(1);
            var httpContext   = new Mock <HttpContext>();
            var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ControllerActionDescriptor()
            {
                ActionName = "Index"
            });

            var httpRequest             = new Mock <HttpRequest>();
            var actionExecutionDelegate = new Mock <ActionExecutionDelegate>();

            httpRequest.SetupGet(x => x.Method).Returns("POST");
            httpContext.SetupGet(x => x.Request).Returns(httpRequest.Object);

            var controller = new Mock <Controller>();

            var actionExecutingContext = new ActionExecutingContext(actionContext, new List <IFilterMetadata>(), new RouteValueDictionary(), controller.Object);

            await actionFilter.OnActionExecutionAsync(actionExecutingContext, actionExecutionDelegate.Object);

            actionExecutingContext.Result.Should().BeNull();
        }
        public void Valid_Configuration_Succeeds()
        {
            var configuration = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result));

            var configurationProvider = new Mock <IListConfigurationProvider>();

            configurationProvider.Setup(x => x.GetConfiguration(It.IsAny <Type>())).Returns(configuration);
            var requestActivator         = new Mock <IModelActivator>();
            var requestPropertyActivator = new Mock <IModelPropertyActivator>();
            var modelCache = new Mock <IModelCache>();

            var httpContext = new Mock <HttpContext>();
            var accessor    = new TestHttpContextAccessor(httpContext.Object);

            var services = new ServiceCollection()
                           .AddSingleton(configurationProvider.Object)
                           .AddSingleton(requestActivator.Object)
                           .AddSingleton(requestPropertyActivator.Object)
                           .AddSingleton(modelCache.Object)
                           .AddSingleton <IHttpContextAccessor>(accessor)
                           .BuildServiceProvider();

            httpContext.SetupGet(x => x.RequestServices).Returns(services);

            var context = new TestModelBinderContext(typeof(Request), services);

            var fallbackModelBinder         = new Mock <IModelBinder>();
            var fallbackModelBinderProvider = new Mock <IModelBinderProvider>();

            fallbackModelBinderProvider.Setup(x => x.GetBinder(It.IsAny <ModelBinderProviderContext>())).Returns(fallbackModelBinder.Object);

            var provider = new GenericSearchModelBinderProvider(fallbackModelBinderProvider.Object);

            var modelBinder = provider.GetBinder(context);

            modelBinder.Should().BeOfType <GenericSearchModelBinder>();
        }
示例#25
0
        public string GetLocalString(string key, string culture = null, string defaultValue = null)
        {
            var config = ListConfiguration.Find(c => c.Keyword == key && (culture == null || c.Specificulture == culture));

            return(config != null ? config.Value : defaultValue);
        }
示例#26
0
        public string GetLocalString(string key, string culture)
        {
            var config = ListConfiguration.Find(c => c.Keyword == key && c.Specificulture == culture);

            return(config != null ? config.Value : key);
        }
示例#27
0
 public static TConfiguration Add <TConfiguration>(this ListConfiguration <TConfiguration, IMethod> source,
                                                   Func <MethodBuilder, IMethod> builder
                                                   ) where TConfiguration : IType =>
 source.Add(t => builder(BuildRoutine.Method(t)));
示例#28
0
 public static TConfiguration Add <TConfiguration>(this ListConfiguration <TConfiguration, IParameter> source,
                                                   Func <ParameterBuilder, IParameter> builder
                                                   ) where TConfiguration : IParametric =>
 source.Add(o => builder(BuildRoutine.Parameter(o)));
示例#29
0
 public static TConfiguration Add <TConfiguration>(
     this ListConfiguration <TConfiguration, IHeaderProcessor> source,
     Func <HeaderProcessorBuilder, IHeaderProcessor> builder
     ) => source.Add(builder(BuildRoutine.HeaderProcessor()));