Exemplo n.º 1
0
        public void OkWithOptionalJson()
        {
            var model = SettingsProcessor.Process <TestOptionAttrModel>(_jsonTest);

            CheckModel(model);
            Assert.Null(model.Test4);
            Assert.Null(model.SubObjectOptional);
        }
Exemplo n.º 2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            OAuthSettings settings = new OAuthSettings();

            if (Environment.IsProduction() && string.IsNullOrEmpty(Configuration["SettingsUrl"]))
            {
                throw new Exception("SettingsUrl is not found");
            }

            if (string.IsNullOrEmpty(Configuration["SettingsUrl"]))
            {
                Configuration.Bind(settings);
            }
            else
            {
                settings = SettingsProcessor.Process <OAuthSettings>(Configuration["SettingsUrl"].GetStringAsync().Result);
            }

            services.AddSingleton <IOAuthSettings>(settings);

            services.AddAuthentication(options => { options.SignInScheme = "ServerCookie"; });

            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.AddCors(options =>
            {
                options.AddPolicy("Lykke", builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials();
                });
            });

            services.AddMvc()
            .AddViewLocalization()
            .AddDataAnnotationsLocalization()
            .AddMvcOptions(o => { o.Filters.Add(typeof(UnhandledExceptionFilter)); });

            services.AddDistributedMemoryCache();

            services.AddAutoMapper();

            services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(30); });

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedProto;
            });

            WebDependencies.Create(services);

            return(ApiDependencies.Create(services, settings));
        }
        public static TestSettings <TValue> FormatJsonString(string value)
        {
            if (null == value)
            {
                return(SettingsProcessor.Process <TestSettings <TValue> >("{ 'value': null }"));
            }

            value = value
                    .Replace(@"\", @"\\")
                    .Replace(@"""", @"\\""")
                    .Replace(@"'", @"\\'");
            value = "\"" + value + "\"";
            return(FormatJson(value));
        }
Exemplo n.º 4
0
        public void OkJson()
        {
            var model = SettingsProcessor.Process <TestModel>(_jsonTest);

            CheckModel(model);
        }
Exemplo n.º 5
0
        public void SubFieldArrayMissJson()
        {
            var ex = Assert.Throws <RequiredFieldEmptyException>(() => SettingsProcessor.Process <TestModel>(_jsonTest.Replace(@"""test2"":24,", String.Empty)));

            Assert.Equal(ex.FieldName, "SubArray.2.Test2");
        }
Exemplo n.º 6
0
 public void IncorrectJson()
 {
     Assert.Throws <IncorrectJsonFormatException>(() => SettingsProcessor.Process <TestModel>(_jsonTest.Substring(10)));
 }
Exemplo n.º 7
0
 public void EmptyJson()
 {
     Assert.Throws <JsonStringEmptyException>(() => SettingsProcessor.Process <TestModel>(string.Empty));
 }
 public static TestSettings <TValue> FormatJson(string value)
 {
     return(null == value
         ? SettingsProcessor.Process <TestSettings <TValue> >("{ 'value': null }")
         : SettingsProcessor.Process <TestSettings <TValue> >("{ 'value': " + value + " }"));
 }