protected override void OnModelCreating(DbModelBuilder modelBuilder) { //Register filter interceptor DbInterception.Add(new FilterInterceptor()); modelBuilder.Conventions.Add(FilterConvention.Create <ISoftDelete, bool>("IsDeleted", (e, IsDeleted) => e.IsDeleted == false)); Configuration.LazyLoadingEnabled = false; Configuration.ProxyCreationEnabled = false; modelBuilder.Conventions.Remove <PluralizingTableNameConvention>(); modelBuilder.Conventions.Remove <ManyToManyCascadeDeleteConvention>(); modelBuilder.Conventions.Remove <OneToManyCascadeDeleteConvention>(); base.OnModelCreating(modelBuilder); modelBuilder.Entity <User>().ToTable("User"); modelBuilder.Entity <Role>().ToTable("Role"); modelBuilder.Entity <UserRole>().ToTable("UserRole"); modelBuilder.Entity <UserClaim>().ToTable("UserClaim"); modelBuilder.Entity <UserLogin>().ToTable("UserLogin"); modelBuilder.Entity <User>().Property(r => r.Id); modelBuilder.Entity <UserClaim>().Property(r => r.Id); modelBuilder.Entity <Role>().Property(r => r.Id); modelBuilder.Entity <UserClaim>().Property(r => r.Id); modelBuilder.Entity <UserLogin>().Property(r => r.Id); modelBuilder.Entity <UserRole>().Property(r => r.Id); //Add index to the ObjectId Audit //modelBuilder.Entity<Audit>() // .Property(e => e.ObjectId) // .HasColumnAnnotation( // IndexAnnotation.AnnotationName, // new IndexAnnotation(new IndexAttribute())); }
public void FilterConvention_Should_Fail_When_NoMatchingBindingWasFound() { // arrange var provider = new QueryableFilterProvider( descriptor => { descriptor.AddFieldHandler <QueryableStringEqualsHandler>(); descriptor.AddFieldHandler <QueryableDefaultFieldHandler>(); }); var convention = new FilterConvention( descriptor => { descriptor.Operation(DefaultFilterOperations.Equals).Name("eq"); descriptor.Provider(provider); }); var type = new FooFilterInput(); //act SchemaException error = Assert.Throws <SchemaException>(() => CreateSchemaWith(type, convention)); Assert.Single(error.Errors); #if NETCOREAPP2_1 error.Errors[0].Message.MatchSnapshot(new SnapshotNameExtension("NETCOREAPP2_1")); #else error.Errors[0].Message.MatchSnapshot(); #endif }
public void FilterConvention_Should_Fail_When_FieldHandlerIsNotRegistered() { // arrange var provider = new QueryableFilterProvider( descriptor => { descriptor.AddFieldHandler <QueryableStringEqualsHandler>(); }); var convention = new FilterConvention( descriptor => { descriptor.Operation(DefaultFilterOperations.Equals).Name("eq"); descriptor.BindRuntimeType <string, TestOperationFilterInputType>(); descriptor.Provider(provider); }); var type = new FooFilterInput(); //act SchemaException?error = Assert.Throws <SchemaException>(() => CreateSchemaWith(type, convention)); Assert.Single(error.Errors); error.Errors[0].Message.MatchSnapshot(); }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new BlogPostMap()); modelBuilder.Configurations.Add(new KategoriMap()); modelBuilder.Configurations.Add(new KommentarMap()); modelBuilder.Configurations.Add(new ForfatterMap()); modelBuilder.Configurations.Add(new LeietagerMap()); modelBuilder.Entity <BlogPost>() .Filter("BadCategory", fc => fc.Condition(be => be.Kategorier.Select(c => c.Kategori.Navn).Contains("Bad posts"))) .HasMany(m => m.Kategorier).WithRequired(m => m.BlogPost).WillCascadeOnDelete(true); modelBuilder.Entity <BlogPost>() .HasRequired(m => m.Leietager).WithMany().WillCascadeOnDelete(false); modelBuilder.Entity <Kommentar>() .HasRequired(m => m.Leietager).WithMany().WillCascadeOnDelete(false); modelBuilder.Entity <Kategori>() .HasRequired(m => m.Leietager).WithMany().WillCascadeOnDelete(false); modelBuilder.Entity <BlogPostKategori>() .HasRequired(m => m.Leietager).WithMany().WillCascadeOnDelete(false); modelBuilder.Entity <Forfatter>() .HasRequired(m => m.Leietager).WithMany().WillCascadeOnDelete(false); modelBuilder.Conventions.Add(FilterConvention.Create <ILeietagerEntity, int>("Tenant", (e, leietagerId) => e.LeietagerId == leietagerId)); }
public void Convention_DefaultScope_Extensions() { // arrange // act var convention = new FilterConvention( x => x.UseMock() .Configure <StringOperationFilterInputType>( y => y.Operation(DefaultFilterOperations.Like).Type <StringType>()) .Operation(DefaultFilterOperations.Like) .Name("like")); ISchemaBuilder builder = SchemaBuilder.New() .AddConvention <IFilterConvention>(convention) .TryAddTypeInterceptor <FilterTypeInterceptor>() .AddQueryType( c => c.Name("Query") .Field("foo") .Type <StringType>() .Resolver("bar") .Argument("test", x => x.Type <TestFilter>())); ISchema schema = builder.Create(); // assert schema.ToString().MatchSnapshot(); }
public void FilterConvention_Should_Fail_When_OperationsIsNotNamed() { // arrange var provider = new QueryableFilterProvider( descriptor => { descriptor.AddFieldHandler <QueryableStringEqualsHandler>(); descriptor.AddFieldHandler <QueryableDefaultFieldHandler>(); }); var convention = new FilterConvention( descriptor => { descriptor.Operation(DefaultFilterOperations.Equals).Description("eq"); descriptor.BindRuntimeType <string, TestOperationFilterInputType>(); descriptor.Provider(provider); }); var type = new FooFilterInput(); //act ArgumentException error = Assert.Throws <ArgumentException>(() => CreateSchemaWith(type, convention)); Assert.Equal("Name", error.ParamName); }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { // Registers and configures it first. DbInterception.Add(new FilterInterceptor()); var softDeleteFilter = FilterConvention.Create <BaseEntity>("SoftDelete", e => e.IsDeleted == false); // don't change it into e => !e.IsDeleted modelBuilder.Conventions.Add(softDeleteFilter); }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { IEnumerable <Type> typesToRegister = typeof(T).Assembly.GetTypes().Where(type => !String.IsNullOrEmpty(type.Namespace)).Where(type => type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(DataEntityTypeConfiguration <>)); foreach (var type in typesToRegister) { dynamic configurationInstance = Activator.CreateInstance(type); modelBuilder.Configurations.Add(configurationInstance); } modelBuilder.Conventions.Add(FilterConvention.Create <ISoftDeletable>("SoftDeleteFilter", (e) => e.IsDeleted == false)); }
public void FilterConvention_Should_Work_With_Extensions() { // arrange var provider = new QueryableFilterProvider( descriptor => { descriptor.AddFieldHandler <QueryableStringEqualsHandler>(); descriptor.AddFieldHandler <QueryableDefaultFieldHandler>(); }); var convention = new FilterConvention( descriptor => { }); var extension1 = new FilterConventionExtension( descriptor => { descriptor.BindRuntimeType <string, TestOperationFilterInputType>(); descriptor.Provider(provider); }); var extension2 = new FilterConventionExtension( descriptor => { descriptor.Operation(DefaultFilterOperations.Equals).Name("eq"); }); IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral("{ bar: { eq:\"a\" }}"); var type = new FooFilterInput(); //act CreateSchemaWith(type, convention, extension1, extension2); var executor = new ExecutorBuilder(type); Func <Foo, bool> func = executor.Build <Foo>(value); // assert var a = new Foo { Bar = "a" }; Assert.True(func(a)); var b = new Foo { Bar = "b" }; Assert.False(func(b)); }
public void Create_Implicit_Operation() { // arrange var convention = new FilterConvention(x => x.UseMock().Operation(155).Name("Method155")); // act ISchema schema = SchemaBuilder.New() .AddQueryType <Query>() .AddConvention <IFilterConvention>(convention) .AddFiltering() .Create(); // assert schema.ToString().MatchSnapshot(); }
protected ISchema CreateSchema <T>(T type) where T : IFilterInputType { var convention = new FilterConvention(x => x.AddDefaults()); ISchemaBuilder builder = SchemaBuilder.New() .AddConvention <IFilterConvention>(convention) .AddTypeInterceptor <FilterTypeInterceptor>() .AddQueryType(c => c .Name("Query") .Field("foo") .Type <StringType>() .Resolver("bar")) .AddType(type); return(builder.Create()); }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity <BlogEntry>() .Filter("BadCategory", fc => fc.Condition(be => be.Categories.Select(c => c.Category.Name).Contains("Bad posts"))) .HasMany(m => m.Categories).WithRequired(m => m.BlogEntry).WillCascadeOnDelete(true); modelBuilder.Entity <BlogEntry>() .HasRequired(m => m.Tenant).WithMany().WillCascadeOnDelete(false); modelBuilder.Entity <Comment>() .HasRequired(m => m.Tenant).WithMany().WillCascadeOnDelete(false); modelBuilder.Entity <Category>() .HasRequired(m => m.Tenant).WithMany().WillCascadeOnDelete(false); modelBuilder.Entity <BlogEntryCategory>() .HasRequired(m => m.Tenant).WithMany().WillCascadeOnDelete(false); modelBuilder.Entity <Author>() .HasRequired(m => m.Tenant).WithMany().WillCascadeOnDelete(false); modelBuilder.Conventions.Add(FilterConvention.Create <ITenantEntity, int>("Tenant", (e, tenantId) => e.TenantId == tenantId)); }
public void Create_Explicit_Operation() { // arrange var convention = new FilterConvention( x => { x.UseMock(); x.Operation(155).Name("SimpleMethod"); x.Operation(156).Name("ComplexMethod"); }); // act ISchema schema = SchemaBuilder.New() .AddQueryType <QueryExplicit>() .AddConvention <IFilterConvention>(convention) .AddFiltering() .Create(); // assert schema.ToString().MatchSnapshot(); }
public async Task FilterConvention_Should_NotAddOr() { // arrange var convention = new FilterConvention( descriptor => { descriptor.AddDefaults(); descriptor.AllowOr(false); }); IRequestExecutorBuilder builder = new ServiceCollection() .AddGraphQL() .AddConvention <IFilterConvention>(convention) .AddFiltering() .AddQueryType( x => x.Name("Query").Field("foos").UseFiltering().Resolve(new List <Foo>())); //act ISchema schema = await builder.BuildSchemaAsync(); // assert schema.ToString().MatchSnapshot(); }
protected ISchema CreateSchema <T>(T type) where T : IFilterInputType { var convention = new FilterConvention(x => x .AddDefaults() .AddSpatialOperations() .BindSpatialTypes() .Provider( new QueryableFilterProvider( p => p.AddSpatialHandlers().AddDefaultFieldHandlers()))); ISchemaBuilder builder = SchemaBuilder.New() .AddConvention <IFilterConvention>(convention) .TryAddTypeInterceptor <FilterTypeInterceptor>() .AddQueryType(c => c .Name("Query") .Field("foo") .Type <StringType>() .Resolve("bar")) .AddType(type); return(builder.Create()); }
protected ISchema CreateSchemaWith( IFilterInputType type, FilterConvention convention, params FilterConventionExtension[] extensions) { ISchemaBuilder builder = SchemaBuilder.New() .AddConvention <IFilterConvention>(convention) .AddFiltering() .AddQueryType( c => c.Name("Query") .Field("foo") .Type <StringType>() .Resolve("bar")) .AddType(type); foreach (FilterConventionExtension?extension in extensions) { builder.AddConvention <IFilterConvention>(extension); } return(builder.Create()); }
public async Task FilterConvention_Should_UseBoundFilterType() { // arrange var convention = new FilterConvention( descriptor => { descriptor.AddDefaults(); descriptor.BindRuntimeType <string, TestOperationFilterInputType>(); descriptor.BindRuntimeType <Foo, CustomFooFilterInput>(); }); IRequestExecutorBuilder builder = new ServiceCollection() .AddGraphQL() .AddConvention <IFilterConvention>(convention) .AddFiltering() .AddQueryType( x => x.Name("Query").Field("foos").UseFiltering().Resolve(new List <Foo>())); //act ISchema schema = await builder.BuildSchemaAsync(); // assert schema.ToString().MatchSnapshot(); }