public void CreateSchema_WhenFirstLevelIdentity_ReturnsSchemaWithIdentityAccessor()
        {
            var builder = new AutoSchemaBuilder<WithIdentity>();

            var schema = builder.CreateSchema();

            Assert.AreEqual(IdTypes.Identity, schema.IdAccessor.IdType);
            Assert.IsNotNull(schema.IdAccessor);
        }
        public void CreateSchema_WhenIdentityItemHasNoIndexableFirstLevelProperties_ThrowsMissingIndexableMembersException()
        {
            var builder = new AutoSchemaBuilder<WithOnlyIdentity>();

            var ex = CustomAssert.Throws<SisoDbException>(
                () => builder.CreateSchema());

            var expectedMessage = string.Format(ExceptionMessages.AutoSchemaBuilder_MissingIndexableMembers, "WithOnlyIdentity");
            Assert.AreEqual(expectedMessage, ex.Message);
        }
        public void CreateSchema_WhenByteMember_IndexAccessorIsCreatedForByteMember()
        {
            var builder = new AutoSchemaBuilder<WithByte>();

            var schema = builder.CreateSchema();

            var byteIac = schema.IndexAccessors.SingleOrDefault(iac => iac.Path == "Byte");
            Assert.IsNotNull(byteIac);
            Assert.IsTrue(byteIac.DataType.IsByteType());
        }
        public void CreateSchema_WhenByteArrayMember_NoIndexAccessorIsCreatedForByteArrayMember()
        {
            var builder = new AutoSchemaBuilder<WithBytes>();

            var ex = Assert.Throws<SisoDbException>(() => builder.CreateSchema());

            Assert.AreEqual(
                ExceptionMessages.AutoSchemaBuilder_MissingIndexableMembers.Inject("WithBytes"),
                ex.Message);
        }
        public void CreateStructure_WhenItemWithEnumerableWithTwoEqualElements_ReturnsIndexWithStringsAsOneValuedDelimitedString()
        {
            var schema = new AutoSchemaBuilder<WithArray>().CreateSchema();
            var item = new WithArray { Values = new[] { "A", "A" } };

            var builder = new StructureBuilder();
            var structure = builder.CreateStructure(item, schema);

            var indexes = structure.Indexes.ToList();
            Assert.AreEqual("<$A$>", indexes[0].Value);
        }
        public void CreateStructure_WhenItemWithByteArray_NoIndexShouldBeCreatedForByteArray()
        {
            var schema = new AutoSchemaBuilder<WithBytes>().CreateSchema();
            var item = new WithBytes { Bytes1 = BitConverter.GetBytes(242) };

            var builder = new StructureBuilder();
            var structure = builder.CreateStructure(item, schema);

            var indexes = structure.Indexes.ToList();
            Assert.AreEqual(1, indexes.Count);
            Assert.IsTrue(indexes[0].Name.StartsWith("DummyMember_"));
        }
        public void CreateStructure_WhenItemWithEnumerable_WillConsumeStringConverter()
        {
            var stringConverterFake = new Mock<IStringConverter>();
            SisoDbEnvironment.StringConverter = stringConverterFake.Object;
            var schema = new AutoSchemaBuilder<WithArray>().CreateSchema();
            var item = new WithArray { Values = new[] { "A", "B" } };

            var builder = new StructureBuilder();
            builder.CreateStructure(item, schema);

            stringConverterFake.Verify(s => s.AsString<object>("A"), Times.Once());
            stringConverterFake.Verify(s => s.AsString<object>("B"), Times.Once());
        }
        public void CreateStructure_WhenItemWithNoEnumerable_ReturnsIndexWithStringValue()
        {
            var schema = new AutoSchemaBuilder<WithNoArray>().CreateSchema();
            var item = new WithNoArray { Value = "A" };

            var builder = new StructureBuilder();
            var structure = builder.CreateStructure(item, schema);

            var indexes = structure.Indexes.ToList();
            Assert.AreEqual("A", indexes[0].Value);
        }
        public void CreateSchema_WhenItemHasIndexableFirstLevelProperties_IndexAccessorsAreExtracted()
        {
            var builder = new AutoSchemaBuilder<WithIdAndIndexableFirstLevelMembers>();

            var schema = builder.CreateSchema();

            CustomAssert.IsNotEmpty(schema.IndexAccessors);
        }
        public void CreateSchema_WhenItemHasIdMember_CreatesSchemaWithKeyMemberAccessor()
        {
            var builder = new AutoSchemaBuilder<WithIdAndIndexableFirstLevelMembers>();

            var schema = builder.CreateSchema();

            Assert.IsNotNull(schema.IdAccessor);
        }
        public void CreateSchema_WhenThirdLevelIndexablePropertiesExists_PathReflectsHierarchy()
        {
            var builder = new AutoSchemaBuilder<WithFirstSecondAndThirdLevelMembers>();

            var schema = builder.CreateSchema();

            var thirdLevelItems = schema.IndexAccessors.Where(iac => iac.Level == 2);
            CustomAssert.ForAll(thirdLevelItems, iac => iac.Path.StartsWith("SecondLevelItem.ThirdLevelItem."));
        }
        public void CreateSchema_WhenThirdLevelIndexablePropertiesExists_IndexAccessorsAreCreated()
        {
            var builder = new AutoSchemaBuilder<WithFirstSecondAndThirdLevelMembers>();

            var schema = builder.CreateSchema();

            var hasThirdLevelAccessors = schema.IndexAccessors.Any(iac => iac.Level == 2);
            Assert.IsTrue(hasThirdLevelAccessors);
        }
        public void CreateSchema_WhenNestedType_SchemaNameReflectsTypeName()
        {
            const string expectedName = "WithIdAndIndexableFirstLevelMembers";
            var builder = new AutoSchemaBuilder<WithIdAndIndexableFirstLevelMembers>();

            var schema = builder.CreateSchema();

            Assert.AreEqual(expectedName, schema.Name);
        }
        public void CreateSchema_WhenItemHasNoIdMember_ThrowsMissingKeyMemberException()
        {
            var builder = new AutoSchemaBuilder<WithNoId>();

            var ex = CustomAssert.Throws<SisoDbException>(() => builder.CreateSchema());

            var expectedMessage = string.Format(ExceptionMessages.AutoSchemaBuilder_MissingIdMember, "WithNoId");
            Assert.AreEqual(expectedMessage, ex.Message);
        }