public void GetSchemas_WhenEmpty_YieldsEmptyStream() { var schemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); var numOfSchemas = schemas.GetSchemas().Count(); Assert.AreEqual(0, numOfSchemas); }
public void GetSchema_InvokedUsingType_WillGenerateSchema() { var schemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); var schema = schemas.GetSchema(typeof(X)); Assert.IsNotNull(schema); }
public void GetSchemas_WhenContainingASchema_YieldsOneSchema() { var schemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); var schema = schemas.GetSchema <X>(); var fetchedSchema = schemas.GetSchemas().First(); Assert.AreEqual(schema, fetchedSchema); }
public void GetSchemas_WhenContainingASchema_YieldsOneSchema() { var schemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); var schema = schemas.GetSchema<X>(); var fetchedSchema = schemas.GetSchemas().First(); Assert.AreEqual(schema, fetchedSchema); }
public void GetSchema_WhenCustomConfigurationExists_ViaNonGenericConfig_ReturnsSchemaWithCorrectIndexAccessor() { var structureTypeFactory = new StructureTypeFactory(); var schemaBuilder = new AutoStructureSchemaBuilder(); var schemas = new StructureSchemas(structureTypeFactory, schemaBuilder); schemas.StructureTypeFactory.Configurations.Configure(typeof(FooCustomer), cfg => cfg.OnlyIndexThis("CustomerNo")); var schema = schemas.GetSchema<FooCustomer>(); Assert.AreEqual("CustomerNo", schema.IndexAccessors.Single().Path); }
public void GetSchema_WhenCustomConfigurationExists_ViaNonGenericConfig_ReturnsSchemaWithCorrectIndexAccessor() { var structureTypeFactory = new StructureTypeFactory(); var schemaBuilder = new AutoStructureSchemaBuilder(); var schemas = new StructureSchemas(structureTypeFactory, schemaBuilder); schemas.StructureTypeFactory.Configurations.Configure(typeof(FooCustomer), cfg => cfg.OnlyIndexThis("CustomerNo")); var schema = schemas.GetSchema <FooCustomer>(); Assert.AreEqual("CustomerNo", schema.IndexAccessors.Single().Path); }
protected virtual void OnDropStructureSets(Type[] types) { using (var dbClient = ProviderFactory.GetTransactionalDbClient(_connectionInfo)) { foreach (var type in types) { CacheProvider.ClearByType(type); var structureSchema = StructureSchemas.GetSchema(type); DbSchemas.Drop(structureSchema, dbClient); StructureSchemas.RemoveSchema(type); } } }
public void StructureType_using_generics_Should_forward_call_to_structure_type_configurations() { var structureSchemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); var dbFake = new Mock <ISisoDatabase>(); dbFake.SetupGet(f => f.StructureSchemas).Returns(structureSchemas); dbFake.Object.Configure().StructureType <StructureForConfigTests>(cfg => cfg.DoNotIndexThis(x => x.StringValue)); var config = structureSchemas.StructureTypeFactory.Configurations.GetConfiguration <StructureForConfigTests>(); Assert.IsNotNull(config); Assert.AreEqual("StringValue", config.MemberPathsNotBeingIndexed.SingleOrDefault()); }
public void Build() { var structureSchemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); structureSchemas.GetSchema<MyDummy>(); var dbFake = new Mock<ISisoDatabase>(); dbFake.SetupGet(f => f.Name).Returns("UnitTestDb"); dbFake.Setup(f => f.ConnectionInfo).Returns(new Sql2012ConnectionInfo("data source=.;initial catalog=foo;integrated security=true;")); dbFake.Setup(f => f.Settings).Returns(DbSettings.CreateDefault()); dbFake.Setup(f => f.Serializer).Returns(new ServiceStackSisoSerializer()); dbFake.Setup(f => f.StructureSchemas).Returns(structureSchemas); var dbDiagnostics = new DbDiagnosticsBuilder(dbFake.Object); var info = dbDiagnostics.Build(); JsonApprovals.VerifyAsJson(info); }
protected SisoDatabase(ISisoConnectionInfo connectionInfo, IDbProviderFactory dbProviderFactory) { Ensure.That(connectionInfo, "connectionInfo").IsNotNull(); Ensure.That(dbProviderFactory, "dbProviderFactory").IsNotNull(); _lockObject = new object(); _connectionInfo = connectionInfo; _providerFactory = dbProviderFactory; Settings = ProviderFactory.GetSettings(); ServerClient = ProviderFactory.GetServerClient(ConnectionInfo); StructureSchemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); Serializer = new DefaultSisoSerializer(); StructureBuilders = new StructureBuilders(() => Serializer, schema => ProviderFactory.GetGuidStructureIdGenerator(), (schema, dbClient) => ProviderFactory.GetIdentityStructureIdGenerator(dbClient)); Maintenance = new SisoDatabaseMaintenance(this); _dbSchemas = ProviderFactory.GetDbSchemaManagerFor(this); }
public void GetData() { var structureSchemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); structureSchemas.GetSchema<MyDummy>(); var dbFake = new Mock<ISisoDatabase>(); dbFake.SetupGet(f => f.Name).Returns("UnitTestDb"); dbFake.Setup(f => f.ConnectionInfo).Returns(new Sql2012ConnectionInfo("data source=.;initial catalog=foo;integrated security=true;")); dbFake.Setup(f => f.Settings).Returns(DbSettings.CreateDefault()); dbFake.Setup(f => f.Serializer).Returns(new ServiceStackSisoSerializer()); dbFake.Setup(f => f.StructureSchemas).Returns(structureSchemas); SisoDbGlimpsePlugin.ResolveDatabasesUsing = () => new[] { dbFake.Object }; var plugin = new SisoDbGlimpsePlugin(); var data = plugin.GetData(Mock.Of<ITabContext>()); JsonApprovals.VerifyAsJson(data); }
protected virtual void OnUpsertStructureSets(Type[] types) { if (!Settings.AllowsAnyDynamicSchemaChanges()) { return; } using (var dbClient = ProviderFactory.GetTransactionalDbClient(_connectionInfo)) { foreach (var type in types) { CacheProvider.ClearByType(type); var structureSchema = StructureSchemas.GetSchema(type); DbSchemas.Upsert(structureSchema, dbClient); } } }
public void Build() { var structureSchemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); structureSchemas.GetSchema <MyDummy>(); var dbFake = new Mock <ISisoDatabase>(); dbFake.SetupGet(f => f.Name).Returns("UnitTestDb"); dbFake.Setup(f => f.ConnectionInfo).Returns(new Sql2012ConnectionInfo("data source=.;initial catalog=foo;integrated security=true;")); dbFake.Setup(f => f.Settings).Returns(DbSettings.CreateDefault()); dbFake.Setup(f => f.Serializer).Returns(new ServiceStackSisoSerializer()); dbFake.Setup(f => f.StructureSchemas).Returns(structureSchemas); var dbDiagnostics = new DbDiagnosticsBuilder(dbFake.Object); var info = dbDiagnostics.Build(); JsonApprovals.VerifyAsJson(info); }
public void GetData() { var structureSchemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); structureSchemas.GetSchema <MyDummy>(); var dbFake = new Mock <ISisoDatabase>(); dbFake.SetupGet(f => f.Name).Returns("UnitTestDb"); dbFake.Setup(f => f.ConnectionInfo).Returns(new Sql2012ConnectionInfo("data source=.;initial catalog=foo;integrated security=true;")); dbFake.Setup(f => f.Settings).Returns(DbSettings.CreateDefault()); dbFake.Setup(f => f.Serializer).Returns(new ServiceStackSisoSerializer()); dbFake.Setup(f => f.StructureSchemas).Returns(structureSchemas); SisoDbGlimpsePlugin.ResolveDatabasesUsing = () => new[] { dbFake.Object }; var plugin = new SisoDbGlimpsePlugin(); var data = plugin.GetData(Mock.Of <ITabContext>()); JsonApprovals.VerifyAsJson(data); }
public void StructureType_using_generics_Should_forward_call_to_structure_type_configurations() { var structureSchemas = new StructureSchemas(new StructureTypeFactory(), new AutoStructureSchemaBuilder()); var dbFake = new Mock<ISisoDatabase>(); dbFake.SetupGet(f => f.StructureSchemas).Returns(structureSchemas); dbFake.Object.Configure().StructureType<StructureForConfigTests>(cfg => cfg.DoNotIndexThis(x => x.StringValue)); var config = structureSchemas.StructureTypeFactory.Configurations.GetConfiguration<StructureForConfigTests>(); Assert.IsNotNull(config); Assert.AreEqual("StringValue", config.MemberPathsNotBeingIndexed.SingleOrDefault()); }