public void Equals_WhenDifferentIdentityStructureId_ReturnsFalse()
        {
            const bool isUniqueTemp = true;

            var structure1 = new StructureIndex(StructureId.NewIdentityId(1), "TheName", "TheValue", isUniqueTemp);
            var structure2 = new StructureIndex(StructureId.NewIdentityId(2), "TheName", "TheValue", isUniqueTemp);

            Assert.AreNotEqual(structure1, structure2);
        }
        public void Equals_WhenSameStructureIdNameAndValue_ReturnsTrue()
        {
            var guid = Guid.Parse("06E2FC67-AB9F-4E65-A2C8-5FC897597887");
            const bool isUniqueTemp = true;

            var structure1 = new StructureIndex(StructureId.NewGuidId(guid), "TheName", "TheValue", isUniqueTemp);
            var structure2 = new StructureIndex(StructureId.NewGuidId(guid), "TheName", "TheValue", isUniqueTemp);

            Assert.AreEqual(structure1, structure2);
        }
        public void Equals_WhenDifferentValue_ReturnsFalse()
        {
            var guid1 = Guid.Parse("06E2FC67-AB9F-4E65-A2C8-5FC897597887");
            const bool isUniqueTemp = true;

            var structure1 = new StructureIndex(StructureId.NewGuidId(guid1), "TheName", "TheValue", isUniqueTemp);
            var structure2 = new StructureIndex(StructureId.NewGuidId(guid1), "TheName", "OtherValue", isUniqueTemp);

            Assert.AreNotEqual(structure1, structure2);
        }
        public void Equals_WhenDifferentName_ReturnsFalse()
        {
            var structureId = StructureId.Create(Guid.Parse("06E2FC67-AB9F-4E65-A2C8-5FC897597887"));
            const string thevalue = "TheValue";
            
            var structure1 = new StructureIndex(structureId, "TheName", thevalue, thevalue.GetType(), _converter.Convert(CreateProperty(thevalue.GetType())));
            var structure2 = new StructureIndex(structureId, "TheOtherName", thevalue, thevalue.GetType(), _converter.Convert(CreateProperty(thevalue.GetType())));

            Assert.AreNotEqual(structure1, structure2);
        }
        public void Equals_WhenDifferentGuidStructureId_ReturnsFalse()
        {
            var guid1 = Guid.Parse("06E2FC67-AB9F-4E65-A2C8-5FC897597887");
            var guid2 = Guid.Parse("14D4D3EC-6E1E-4839-ACC7-EA3B4653CF96");
            const bool isUniqueTemp = true;

            var structure1 = new StructureIndex(StructureId.NewGuidId(guid1), "TheName", "TheValue", isUniqueTemp);
            var structure2 = new StructureIndex(StructureId.NewGuidId(guid2), "TheName", "TheValue", isUniqueTemp);

            Assert.AreNotEqual(structure1, structure2);
        }
        public void Equals_WhenDifferentValue_ReturnsFalse()
        {
            var structureId = StructureId.Create(Guid.Parse("06E2FC67-AB9F-4E65-A2C8-5FC897597887"));
            var dataType = typeof (string);
            var dataTypeCode = _converter.Convert(CreateProperty(dataType));
            
            var structure1 = new StructureIndex(structureId, "TheName", "TheValue", dataType, dataTypeCode);
            var structure2 = new StructureIndex(structureId, "TheName", "OtherValue", dataType, dataTypeCode);

            Assert.AreNotEqual(structure1, structure2);
        }
        public void Equals_WhenDifferentGuidStructureId_ReturnsFalse()
        {
            var structureId1 = StructureId.Create(Guid.Parse("06E2FC67-AB9F-4E65-A2C8-5FC897597887"));
            var structureId2 = StructureId.Create(Guid.Parse("14D4D3EC-6E1E-4839-ACC7-EA3B4653CF96"));
            const string thevalue = "TheValue";
            
            var structure1 = new StructureIndex(structureId1, "TheName", thevalue, thevalue.GetType(), _converter.Convert(CreateProperty(thevalue.GetType())));
            var structure2 = new StructureIndex(structureId2, "TheName", thevalue, thevalue.GetType(), _converter.Convert(CreateProperty(thevalue.GetType())));

            Assert.AreNotEqual(structure1, structure2);
        }
Example #8
0
        public IStructureIndex[] CreateIndexes <T>(IStructureSchema structureSchema, T item, IStructureId structureId) where T : class
        {
            var indexes = new IEnumerable <IStructureIndex> [structureSchema.IndexAccessors.Count];

            Parallel.For(0, indexes.Length, c =>
            {
                var indexAccessor        = structureSchema.IndexAccessors[c];
                var values               = indexAccessor.GetValues(item);
                var valuesExists         = values != null && values.Count > 0;
                var isCollectionOfValues = indexAccessor.IsEnumerable || indexAccessor.IsElement || (values != null && values.Count > 1);

                if (!valuesExists)
                {
                    if (!isCollectionOfValues && indexAccessor.IsUnique)
                    {
                        throw new SisoDbException(ExceptionMessages.StructureIndexesFactory_UniqueIndex_IsNull.Inject(structureSchema.Name, indexAccessor.Path));
                    }

                    return;
                }

                if (!isCollectionOfValues)
                {
                    indexes[c] = new[] { new StructureIndex(structureId, indexAccessor.Path, values[0], indexAccessor.DataType, indexAccessor.DataTypeCode, indexAccessor.UniqueMode.ToStructureIndexType()) }
                }
                ;
                else
                {
                    var subIndexes = new IStructureIndex[values.Count];
                    Parallel.For(0, subIndexes.Length, subC =>
                    {
                        if (values[subC] != null)
                        {
                            subIndexes[subC] = new StructureIndex(structureId, indexAccessor.Path, values[subC],
                                                                  indexAccessor.DataType, indexAccessor.DataTypeCode,
                                                                  indexAccessor.UniqueMode.ToStructureIndexType());
                        }
                    });
                    indexes[c] = subIndexes;
                }
            });

            return(indexes.Where(i => i != null).SelectMany(i => i).Where(i => i != null).ToArray());
        }