protected override void OnFixtureInitialize()
        {
            base.OnFixtureInitialize();

            var structureTypeFactory = new StructureTypeFactory();
            _sisoDbSerializer = new ServiceStackJsonSerializer(structureTypeFactory.Configurations.GetConfiguration);
        }
Example #2
0
        public void CreateFor_WhenConfigIncludingMembersExistsForType_InvokesGetSpecificIndexablePropertiesOnReflecter()
        {
            var type          = typeof(MyClass);
            var reflecterMock = new Mock <IStructureTypeReflecter>();

            reflecterMock.Setup(m => m.GetIdProperty(type)).Returns(() =>
            {
                var idProperty = new Mock <IStructureProperty>();

                return(idProperty.Object);
            });
            reflecterMock.Setup(m => m.GetSpecificIndexableProperties(type, new[] { "IncludeTEMP" })).Returns(() =>
            {
                var indexProperty = new Mock <IStructureProperty>();

                return(new[] { indexProperty.Object });
            });

            var factory = new StructureTypeFactory(t => reflecterMock.Object);

            factory.Configurations.Configure(type, cfg => cfg.OnlyIndexThis("IncludeTEMP"));
            factory.CreateFor(type);

            reflecterMock.Verify(m => m.GetSpecificIndexableProperties(type, new[] { "IncludeTEMP" }));
        }
Example #3
0
        internal static IStructureType CreateFor <T>() where T : class
        {
            var configs = new StructureTypeConfigurations();
            var factory = new StructureTypeFactory();

            var typeConfig = configs.Register <T>();

            return(factory.CreateFor(typeConfig));
        }
Example #4
0
        public void CreateFor_When_no_config_for_allowing_nested_structures_exists_It_should_include_nested_members()
        {
            var factory = new StructureTypeFactory();

            var structureType = factory.CreateFor <WithContainedStructure>();

            Assert.AreEqual(2, structureType.IndexableProperties.Length);
            Assert.IsTrue(structureType.IndexableProperties.Any(p => p.Path == "Contained.StructureId"));
            Assert.IsTrue(structureType.IndexableProperties.Any(p => p.Path == "Contained.NestedValue"));
        }
Example #5
0
        public void CreateFor_When_no_config_for_allowing_nested_structures_exists_It_should_extract_contained_structure_properties()
        {
            var factory = new StructureTypeFactory();

            var structureType = factory.CreateFor <WithContainedStructures>();

            Assert.AreEqual(2, structureType.ContainedStructureProperties.Length);
            Assert.AreEqual(1, structureType.ContainedStructureProperties.Count(p => p.Path == "Contained1"));
            Assert.AreEqual(1, structureType.ContainedStructureProperties.Count(p => p.Path == "Contained2"));
        }
		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);
		}
Example #7
0
        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 Should_use_reflecter_to_get_all_indexable_properties_When_no_explicit_excludes_exists()
        {
            var typeConfigStub = new Mock <IStructureTypeConfig>();
            var typeConfig     = typeConfigStub.Object;

            typeConfigStub.Setup(m => m.Type).Returns(typeof(MyClass));
            typeConfigStub.Setup(m => m.IndexMode).Returns(IndexMode.Exclusive);
            typeConfigStub.Setup(m => m.MemberPaths).Returns(new List <string>());

            var reflecterMock = new Mock <IStructureTypeReflecter>();

            var factory = new StructureTypeFactory(reflecterMock.Object);

            factory.CreateFor(typeConfig);

            reflecterMock.Verify(m => m.GetIndexableProperties(typeConfig.Type));
        }
        public void Build()
        {
            var structureTypeFactory = new StructureTypeFactory();
            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 ServiceStackJsonSerializer(structureTypeFactory.Configurations.GetConfiguration));
            dbFake.Setup(f => f.StructureSchemas).Returns(structureSchemas);

            var dbDiagnostics = new DbDiagnosticsBuilder(dbFake.Object);
            var info = dbDiagnostics.Build();

            JsonApprovals.VerifyAsJson(info);
        }
        public void GetData()
        {
            var structureTypeFactory = new StructureTypeFactory();
            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<HttpContextBase>());

            JsonApprovals.VerifyAsJson(data);
        }
        public void Should_use_reflecter_to_get_specific_indexable_properties_When_includes_exists()
        {
            var typeConfigStub = new Mock <IStructureTypeConfig>();
            var typeConfig     = typeConfigStub.Object;

            typeConfigStub.Setup(m => m.Type).Returns(typeof(MyClass));
            typeConfigStub.Setup(m => m.IndexMode).Returns(IndexMode.Inclusive);
            typeConfigStub.Setup(m => m.MemberPaths).Returns(new List <string> {
                "FooBeingIncluded"
            });

            var reflecterMock = new Mock <IStructureTypeReflecter>();

            var factory = new StructureTypeFactory(reflecterMock.Object);

            factory.CreateFor(typeConfig);

            reflecterMock.Verify(m => m.GetSpecificIndexableProperties(typeConfig.Type, It.IsAny <IList <string> >()));
        }
        public void GetData()
        {
            var structureTypeFactory = new StructureTypeFactory();
            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 <HttpContextBase>());

            JsonApprovals.VerifyAsJson(data);
        }
        public void CreateFor_WhenNoExplicitConfigExistsForType_InvokesGetIndexablePropertiesOnReflecter()
        {
            var type = typeof(MyClass);
            var reflecterMock = new Mock<IStructureTypeReflecter>();
            reflecterMock.Setup(m => m.GetIdProperty(type)).Returns(() =>
            {
                var idProperty = new Mock<IStructureProperty>();

                return idProperty.Object;
            });
            reflecterMock.Setup(m => m.GetIndexableProperties(type)).Returns(() =>
            {
                var indexProperty = new Mock<IStructureProperty>();

                return new[] { indexProperty.Object };
            });

            var factory = new StructureTypeFactory(t => reflecterMock.Object);
            factory.CreateFor(type);

            reflecterMock.Verify(m => m.GetIndexableProperties(type));
        }
        public void CreateFor_WhenConfigIncludingMembersExistsForType_InvokesGetSpecificIndexablePropertiesOnReflecter()
        {
            var type = typeof(MyClass);
            var reflecterMock = new Mock<IStructureTypeReflecter>();
            reflecterMock.Setup(m => m.GetIdProperty(type)).Returns(() =>
            {
                var idProperty = new Mock<IStructureProperty>();

                return idProperty.Object;
            });
            reflecterMock.Setup(m => m.GetSpecificIndexableProperties(type, new[] { "IncludeTEMP" })).Returns(() =>
            {
                var indexProperty = new Mock<IStructureProperty>();

                return new[] { indexProperty.Object };
            });

            var factory = new StructureTypeFactory(t => reflecterMock.Object);
            factory.Configurations.Configure(type, cfg => cfg.OnlyIndexThis("IncludeTEMP"));
            factory.CreateFor(type);

            reflecterMock.Verify(m => m.GetSpecificIndexableProperties(type, new[] { "IncludeTEMP" }));
        }
Example #15
0
        public void CreateFor_WhenNoExplicitConfigExistsForType_InvokesGetIndexablePropertiesOnReflecter()
        {
            var type          = typeof(MyClass);
            var reflecterMock = new Mock <IStructureTypeReflecter>();

            reflecterMock.Setup(m => m.GetIdProperty(type)).Returns(() =>
            {
                var idProperty = new Mock <IStructureProperty>();

                return(idProperty.Object);
            });
            reflecterMock.Setup(m => m.GetIndexableProperties(type)).Returns(() =>
            {
                var indexProperty = new Mock <IStructureProperty>();

                return(new[] { indexProperty.Object });
            });

            var factory = new StructureTypeFactory(t => reflecterMock.Object);

            factory.CreateFor(type);

            reflecterMock.Verify(m => m.GetIndexableProperties(type));
        }
        public void CreateFor_When_no_config_for_allowing_nested_structures_exists_It_should_extract_contained_structure_properties()
        {
            var factory = new StructureTypeFactory();

            var structureType = factory.CreateFor<WithContainedStructures>();

            Assert.AreEqual(2, structureType.ContainedStructureProperties.Length);
            Assert.AreEqual(1, structureType.ContainedStructureProperties.Count(p => p.Path == "Contained1"));
            Assert.AreEqual(1, structureType.ContainedStructureProperties.Count(p => p.Path == "Contained2"));
        }
        public void CreateFor_When_no_config_for_allowing_nested_structures_exists_It_should_include_nested_members()
        {
            var factory = new StructureTypeFactory();

            var structureType = factory.CreateFor<WithContainedStructure>();

            Assert.AreEqual(2, structureType.IndexableProperties.Length);
            Assert.IsTrue(structureType.IndexableProperties.Any(p => p.Path == "Contained.StructureId"));
            Assert.IsTrue(structureType.IndexableProperties.Any(p => p.Path == "Contained.NestedValue"));
        }