Ejemplo n.º 1
0
        public void From_AttributeDefinition_To_IndexOperation()
        {
            //Arrange

            var entity = CreateTypedEntity();
            var attDef = entity.EntitySchema.AttributeDefinitions.First();

            //Act

            var result = _mapper.Map <AttributeDefinition, NestedHiveIndexOperation>(attDef);

            //lazily add the ids
            ExamineHelper.EnsureIds(result);

            //Assert

            Assert.AreEqual("AttributeDefinition", result.ItemCategory);
            Assert.AreEqual(IndexOperationType.Add, result.OperationType);
            Assert.AreEqual(attDef.Id.Value.ToString(), result.Id.Value);
            Assert.AreEqual(attDef.Alias, result.Fields["Alias"].FieldValue);
            Assert.AreEqual(attDef.Name, result.Fields["Name"].FieldValue);
            Assert.AreEqual(attDef.Description, result.Fields["Description"].FieldValue);
            Assert.AreEqual(attDef.Ordinal, result.Fields["Ordinal"].FieldValue);
            Assert.IsNotNull(result.Fields[FixedIndexedFields.GroupId].FieldValue);
            Assert.AreEqual(attDef.AttributeGroup.Id.Value, result.Fields[FixedIndexedFields.GroupId].FieldValue);
            Assert.IsNotNull(result.Fields[FixedIndexedFields.AttributeTypeId].FieldValue);
            Assert.AreEqual(attDef.AttributeType.Id.Value, result.Fields[FixedIndexedFields.AttributeTypeId].FieldValue);
            //NOTE: Groups is not a sub operation because a group is attached to a schema, not definition
            Assert.AreEqual(1, result.SubIndexOperations.Count);

            VerifyIEntityFields(result, attDef);
        }
Ejemplo n.º 2
0
        public void From_EntitySchema_To_IndexOperation()
        {
            //Arrange

            var input = HiveModelCreationHelper.CreateEntitySchema("test" + Guid.NewGuid(), "Test" + Guid.NewGuid(), true,
                                                                   HiveModelCreationHelper.CreateAttributeDefinition("test" + Guid.NewGuid(), "Test" + Guid.NewGuid(), "this is a test" + Guid.NewGuid(),
                                                                                                                     HiveModelCreationHelper.CreateAttributeType("test" + Guid.NewGuid(), "Test" + Guid.NewGuid(), "this is a test" + Guid.NewGuid()),
                                                                                                                     HiveModelCreationHelper.CreateAttributeGroup("test" + Guid.NewGuid(), "Test" + Guid.NewGuid(), new Random().Next(0, 1000), true), true));
            var child = HiveModelCreationHelper.CreateEntitySchema("test" + Guid.NewGuid(), "Test" + Guid.NewGuid(), true,
                                                                   HiveModelCreationHelper.CreateAttributeDefinition("test" + Guid.NewGuid(), "Test" + Guid.NewGuid(), "this is a test" + Guid.NewGuid(),
                                                                                                                     HiveModelCreationHelper.CreateAttributeType("test" + Guid.NewGuid(), "Test" + Guid.NewGuid(), "this is a test" + Guid.NewGuid()),
                                                                                                                     HiveModelCreationHelper.CreateAttributeGroup("test" + Guid.NewGuid(), "Test" + Guid.NewGuid(), new Random().Next(0, 1000), true), true));

            input.RelationProxies.EnlistChild(child, FixedRelationTypes.DefaultRelationType);

            //Act

            var output = _mapper.Map <EntitySchema, NestedHiveIndexOperation>(input);

            //lazily add the ids
            ExamineHelper.EnsureIds(output);

            //Assert

            Assert.AreEqual(typeof(EntitySchema).Name, output.ItemCategory);
            Assert.AreEqual(IndexOperationType.Add, output.OperationType);
            Assert.AreEqual(input.Id.Value.ToString(), output.Id.Value);
            Assert.AreEqual(input.SchemaType, output.Fields["SchemaType"].FieldValue);
            Assert.AreEqual(
                input.AttributeDefinitions.Count() +
                input.AttributeGroups.Count() +
                input.RelationProxies.AllChildRelations().Count() + 1, output.SubIndexOperations.Count());

            Assert.AreEqual(input, output.Entity);
            var fieldMapper = new EntitySchemaToIndexFields();

            Assert.AreEqual(fieldMapper.GetValue(input).Count(), output.Fields.Count());

            VerifyIEntityFields(output, input);

            foreach (var a in output.SubIndexOperations.Where(x => x.Entity is AttributeDefinition).ToArray())
            {
                Assert.IsFalse(((HiveIdValue)a.Fields[FixedIndexedFields.GroupId].FieldValue) == HiveIdValue.Empty);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds an index operation to the Queue, if the item already exists it is ignored.
        /// </summary>
        /// <param name="op"></param>
        public void EnqueueIndexOperation(LinearHiveIndexOperation op)
        {
            if (!_itemsToIndex.ShouldAddNewQueueItem(op))
            {
                return;
            }

            //before we process each item, we need to update all of the item ids if they haven't been set
            if (op.OperationType == IndexOperationType.Add && op.Entity != null)
            {
                //check if we should be creating Ids
                if (!_providerMetadata.IsPassthroughProvider)
                {
                    ExamineHelper.EnsureIds(op);
                }
            }

            _itemsToIndex.Add(op);
        }