コード例 #1
0
ファイル: Startup.cs プロジェクト: ririyad/TaskCat
        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public static void ConfigureApp(IAppBuilder app, IContainer container)
        {
            var version = Assembly.GetExecutingAssembly().GetName().Version;

            app.Properties["host.AppName"] = ConfigurationManager.AppSettings["AppName"];
            app.Properties["host.AppMode"] = ConfigurationManager.AppSettings["ENV"];

            //FIXME: We need a module to load development/production mode so error pages can be turned on/off
            //Better have a global configuration module like Asp.net 5, that looked awesome!
            switch (app.Properties["host.AppMode"].ToString())
            {
            case ("development"):
            case ("mock"):
                app.UseErrorPage();
                break;
            }

            SetupMongoConventions();
            SetupJobTaskExtensions();

            app.UseAutofacMiddleware(container);
            app.Use(typeof(PreflightRequestsHandler));
            app.UseForwardHeaders(options: default(ForwardedHeadersOptions));

            var webApiDependencyResolver = new AutofacWebApiDependencyResolver(container);


            var config = new HttpConfiguration();


            BsonSerializerConfig.Configure();

            // INFO: This is not done either
            ConfigureResourceOAuth(app, container);

            WebApiConfig.Register(config, webApiDependencyResolver);
            config.Filters.Add(new ErrorDocumentFilter());


            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            app.UseWebApi(config);
            app.UseAutofacWebApi(config);

            EmailTemplatesConfig.Configure();

            //FIXME: Can be a small middleware. No? Alright!
            app.Run(context =>
            {
                context.Response.ContentType = "text/plain";
                return(context.Response.WriteAsync(string.Format($"Welcome to TaskCat '{version}', proudly baked by NerdCats")));
            });
        }
コード例 #2
0
        public void BsonSerializerAdapter_should_use_configured_JsonConverters()
        {
            var fakeConverter = new FakeDateTimeConverter();
            var config        = new BsonSerializerConfig(new []
            {
                fakeConverter
            });

            var serializerAdapter = new BsonSerializerAdapter(config);

            var dateToSerialize = DateTime.Today;
            var raw             = serializerAdapter.Serialize(dateToSerialize);

            Assert.NotEqual(0, fakeConverter.WriteCount);

            var deserializedDate = serializerAdapter.Deserialize <DateTime>(raw);

            Assert.Equal(dateToSerialize, deserializedDate);
        }