// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAutoMapper(typeof(AutoMapperProfile).GetTypeInfo().Assembly);

            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(RequestPreProcessorBehavior <,>));
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(RequestValidationBehavior <,>));

            services.AddMediatR(typeof(CreateScriptCommandHandler).GetTypeInfo().Assembly);
            services.AddMediatR(typeof(CognitoSignUpCommand).GetTypeInfo().Assembly);

            services.AddHttpClient();

            services.AddEntityFrameworkNpgsql().AddDbContext <RsPeerContext>((provider, builder) =>
            {
                builder.UseNpgsql(Configuration.GetConnectionString("Postgres"),
                                  options => { options.MigrationsAssembly(typeof(Startup).Assembly.FullName); });
                builder.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));
            });

            services.AddSingleton <MongoContext>();
            services.AddSingleton <MongoMigrationHandler>();

            services.AddHangfire(config =>
                                 config.UsePostgreSqlStorage(Configuration.GetConnectionString("Postgres")));

            services.AddMemoryCache();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <CreateScriptCommandHandler>());

            services.Configure <ApiBehaviorOptions>(options => { options.SuppressModelStateInvalidFilter = true; });

            EntityMapperExtensions.AddEntityMappers();
        }
        public void IdentifyRelationshipsWithOtherIdTypes()
        {
            var entityMapper  = new EntityMapper <BaseVariedIdModel>();
            var relationships = EntityMapperExtensions.GetEntityRelationships(entityMapper);

            Assert.AreEqual(2, relationships.Count());
        }
Example #3
0
        public void ValidInversePropertyMapping()
        {
            var entityMapper  = new EntityMapper <ValidInversePropertyModel>();
            var relationships = EntityMapperExtensions.GetEntityRelationships(entityMapper);

            Assert.IsTrue(relationships.Any(r => r.IsCollection && r.IdProperty.Name == "SecondaryId"));
        }
        public void ForeignKeyAttributeOnNavigationProperty()
        {
            var entityMapper  = new EntityMapper <BaseEntityModel>();
            var relationships = EntityMapperExtensions.GetEntityRelationships(entityMapper);

            var updatedByIdProperty       = typeof(BaseEntityModel).GetProperty("UpdatedById");
            var attributeOnIdRelationship = relationships.Where(r => r.IdProperty == updatedByIdProperty).FirstOrDefault();

            Assert.IsFalse(attributeOnIdRelationship.IsCollection);
            Assert.AreEqual(typeof(UserEntityModel), attributeOnIdRelationship.EntityType);
            Assert.AreEqual(typeof(BaseEntityModel).GetProperty("UpdatedBy"), attributeOnIdRelationship.NavigationProperty);
        }
Example #5
0
        public void IdentifyCollectionRelationships()
        {
            var entityMapper  = new EntityMapper <CollectionMappingModel>();
            var relationships = EntityMapperExtensions.GetEntityRelationships(entityMapper);

            Assert.IsTrue(relationships.All(r => r.IsCollection));

            var relationship = relationships.Where(r => r.NavigationProperty.Name == "StringModelEntities").FirstOrDefault();

            Assert.IsTrue(relationship.IsCollection);
            Assert.AreEqual(typeof(StringIdModel), relationship.EntityType);
            Assert.AreEqual(typeof(StringIdModel).GetProperty("Id"), relationship.IdProperty);
            Assert.AreEqual(typeof(CollectionMappingModel).GetProperty("StringModelEntities"), relationship.NavigationProperty);
        }
Example #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddSentry();
                loggingBuilder.AddApplicationInsights(Configuration.GetValue <string>("ApplicationInsights:InstrumentationKey"));
            });

            services.AddAutoMapper(typeof(AutoMapperProfile).GetTypeInfo().Assembly);

            services.AddMediatR(typeof(CreateScriptCommandHandler).GetTypeInfo().Assembly,
                                typeof(CognitoSignUpCommand).GetTypeInfo().Assembly,
                                typeof(RegisterJobsCommand).GetTypeInfo().Assembly);

            services.AddHttpClient();

            services.AddEntityFrameworkNpgsql();

            services.AddDbContextPool <RsPeerContext>((provider, builder) =>
            {
                builder.UseNpgsql(Configuration.GetConnectionString("Postgres"),
                                  options => { options.MigrationsAssembly(typeof(Startup).Assembly.FullName); });
            });

            services.AddDbContext <DiscourseContext>((provider, builder) =>
            {
                builder.UseNpgsql(Configuration.GetConnectionString("Discourse"));
            });

            services.AddSingleton <IGitlabService, GitLabService>();
            services.AddSingleton <IRedisPubSubListener, RedisPubSubCommandHandler>();
            services.AddScoped <IBotLauncherService, BotLauncherService>();
            services.AddSingleton <IRedisService, RedisService>();
            services.AddSingleton <IDashboardAuthorizationFilter, HangfireDashboardAuthorizationFilter>();
            services.AddScoped <DaxWalkerService>();
            services.AddScoped <AcuityWalkerService>();

            services.AddMemoryCache();

            services.AddCors(o => o.AddPolicy("AllowCors", builder =>
            {
                builder
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowAnyOrigin();
            }));

            // Jobs
            services.AddScoped <InstanceCloseJob>();
            services.AddScoped <SetClientCountJob>();
            services.AddScoped <SaveIpAccess>();
            services.AddScoped <SetTrueScriptCounts>();
            services.AddScoped <CheckInuvationAccess>();
            services.AddScoped <SendDiscordAlerts>();
            services.AddScoped <ClearMessagesJob>();
            services.AddScoped <ArchiveRunescapeClients>();

            services.AddSingleton <IFileStorage, SpacesService>();

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders =
                    ForwardedHeaders.All;
                var cloudflare = Configuration.GetValue <string>("Cloudflare:IpList").Split(",").Select(w => w.Split("/")[0]).Select(IPAddress.Parse).ToList();
                cloudflare.ForEach(ip => options.KnownProxies.Add(ip));
            });

            services.AddControllers()
            .AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            })
            .AddJsonOptions(w =>
            {
                w.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
            });

            services.AddHangfire(config =>
            {
                config.UsePostgreSqlStorage(Configuration.GetConnectionString("Postgres"), new PostgreSqlStorageOptions
                {
                    PrepareSchemaIfNecessary = false
                });
            });

            services.Configure <ApiBehaviorOptions>(options => { options.SuppressModelStateInvalidFilter = true; });


            services.AddSingleton <IDiscordSocketClientProvider, DiscordSocketClientProvider>();
            services.AddSingleton <DiscordRoleHelper>();

            services.AddSingleton <IUserFactory, SentryUserFactory>();

            services.AddScoped <ISendGridClient>(a =>
            {
                var config = a.GetService <IConfiguration>();
                return(new SendGridClient(config.GetValue <string>("SendGrid:ApiKey")));
            });

            EntityMapperExtensions.AddEntityMappers();
        }
 public void InvalidForeignKeyOnRelationship()
 {
     var entityMapper  = new EntityMapper <InvalidForeignKeyModel>();
     var relationships = EntityMapperExtensions.GetEntityRelationships(entityMapper).ToArray();
 }
 public void UnsupportedIdTypeOnRelationship()
 {
     var entityMapper  = new EntityMapper <UnsupportedIdModel>();
     var relationships = EntityMapperExtensions.GetEntityRelationships(entityMapper).ToArray();
 }
Example #9
0
 public void InversePropertyMappingInvalidPropertyType()
 {
     var entityMapper  = new EntityMapper <InversePropertyMappingInvalidPropertyTypeModel>();
     var relationships = EntityMapperExtensions.GetEntityRelationships(entityMapper);
 }
Example #10
0
 public void InversePropertyMappingNonExistantProperty()
 {
     var entityMapper  = new EntityMapper <InversePropertyNonExistantPropertyModel>();
     var relationships = EntityMapperExtensions.GetEntityRelationships(entityMapper);
 }