Example #1
0
        protected override void ScenarioSetup()
        {
            MappingsRepository.Setup(instance => instance.FindPropertyMappingFor(It.IsAny <IEntity>(), It.IsAny <PropertyInfo>()))
            .Returns <IEntity, PropertyInfo>((entity, propertyInfo) => PropertyMapping.Object);
            Entity = new Entity(Iri, Context);
            EntitySource.Setup(instance => instance.Load(It.IsAny <Iri>()))
            .Returns <Iri>(iri => new[] { new Statement(iri, PredicateIri, ExpectedName) });
            EntityMapping = new Mock <IEntityMapping>(MockBehavior.Strict);
            EntityMapping.SetupGet(instance => instance.Type).Returns(typeof(IProduct));
            Converter = new Mock <IConverter>(MockBehavior.Strict);
            Converter.Setup(instance => instance.ConvertFrom(It.IsAny <Statement>()))
            .Returns <Statement>(statement => statement.Value);
            var property = new Mock <PropertyInfo>(MockBehavior.Strict);

            property.SetupGet(instance => instance.Name).Returns("Name");
            property.SetupGet(instance => instance.PropertyType).Returns(typeof(string));
            property.SetupGet(instance => instance.DeclaringType).Returns(typeof(IProduct));
            property.Setup(instance => instance.GetHashCode()).Returns(typeof(IProduct).GetProperty("Name").GetHashCode());
            property.Setup(instance => instance.Equals(It.IsAny <object>())).Returns <object>(obj => (obj as PropertyInfo)?.Name == "Name");
            PropertyMapping = new Mock <IPropertyMapping>(MockBehavior.Strict);
            PropertyMapping.SetupGet(instance => instance.EntityMapping).Returns(EntityMapping.Object);
            PropertyMapping.SetupGet(instance => instance.PropertyInfo).Returns(property.Object);
            PropertyMapping.SetupGet(instance => instance.Name).Returns("Name");
            PropertyMapping.SetupGet(instance => instance.Graph).Returns((Iri)null);
            PropertyMapping.SetupGet(instance => instance.ValueConverter).Returns(Converter.Object);
        }
 protected override void ScenarioSetup()
 {
     SourceContext = new DefaultEntityContext(EntitySource.Object, MappingsRepository.Object, ChangeDetector.Object);
     Source        = SourceContext.Create <IProduct>(new Iri("source"));
     MappingsRepository.Setup(instance => instance.FindPropertyMappingFor(It.IsAny <IEntity>(), It.IsAny <PropertyInfo>()))
     .Returns <IEntity, PropertyInfo>((entity, propertyInfo) =>
     {
         var result = new Mock <IPropertyMapping>(MockBehavior.Strict);
         result.SetupGet(instance => instance.PropertyInfo).Returns(propertyInfo);
         return(result.Object);
     });
 }
Example #3
0
 protected override void ScenarioSetup()
 {
     base.ScenarioSetup();
     Calls = 0;
     Context.UnmappedPropertyEncountered += (sender, e) =>
     {
         if (Calls++ == 0)
         {
             e.PropertyMapping = PropertyMapping.Object;
         }
     };
     MappingsRepository.Setup(instance => instance.FindPropertyMappingFor(It.IsAny <IEntity>(), It.IsAny <Iri>(), It.IsAny <Iri>())).Returns((IPropertyMapping)null);
 }
Example #4
0
 protected override void ScenarioSetup()
 {
     MappingsRepository.Setup(instance => instance.FindPropertyMappingFor(It.IsAny <IEntity>(), It.IsAny <PropertyInfo>()))
     .Returns <IEntity, PropertyInfo>((entity, propertyInfo) =>
     {
         var result = new Mock <IPropertyMapping>(MockBehavior.Strict);
         result.SetupGet(instance => instance.PropertyInfo).Returns(propertyInfo);
         return(result.Object);
     });
     Product             = Context.Create <IProduct>(new Iri("test"));
     Product.Description = "Product description";
     Product.Name        = "Product name";
     Product.Ordinal     = 1;
     Product.Price       = 3.14159;
     Product.Categories.Add("category 1");
     Product.Categories.Add("category 2");
     Product.Comments.Add("comment 1");
     Product.Comments.Add("comment 2");
 }
Example #5
0
        protected override void ScenarioSetup()
        {
            Converter = new Mock <IConverter>(MockBehavior.Strict);
            Converter.Setup(instance => instance.ConvertTo(It.IsAny <Iri>(), It.IsAny <Iri>(), It.IsAny <object>(), null))
            .Returns <Iri, Iri, object, Iri>((subject, predicate, value, graph) => new Statement(subject, predicate, String.Format(CultureInfo.InvariantCulture, "{0}", value), graph));
            MappingsRepository.Setup(instance => instance.FindEntityMappingFor(It.IsAny <IEntity>(), It.IsAny <Type>()))
            .Returns <IEntity, Type>((entity, type) =>
            {
                var entityMapping = new Mock <IEntityMapping>(MockBehavior.Strict);
                var classMapping  = new Mock <IStatementMapping>(MockBehavior.Strict);
                classMapping.SetupGet(instance => instance.Graph).Returns((Iri)null);
                classMapping.SetupGet(instance => instance.Term).Returns(new Iri(type.Name.Substring(1)));
                entityMapping.SetupGet(instance => instance.Classes).Returns(new[] { classMapping.Object });
                return(entityMapping.Object);
            });
            MappingsRepository.Setup(instance => instance.FindPropertyMappingFor(It.IsAny <IEntity>(), It.IsAny <PropertyInfo>()))
            .Returns <IEntity, PropertyInfo>((entity, property) =>
            {
                var propertyMapping = new Mock <IPropertyMapping>(MockBehavior.Strict);
                propertyMapping.SetupGet(instance => instance.ValueConverter).Returns(Converter.Object);
                propertyMapping.SetupGet(instance => instance.Term).Returns(new Iri(property.Name.ToLower()));
                propertyMapping.SetupGet(instance => instance.Graph).Returns((Iri)null);
                propertyMapping.SetupGet(instance => instance.PropertyInfo).Returns(property);
                if (property.PropertyType.IsAnEnumerable())
                {
                    var collectionMapping = propertyMapping.As <ICollectionMapping>();
                    collectionMapping.SetupGet(instance => instance.StoreAs)
                    .Returns(property.PropertyType.IsAList() ? CollectionStorageModel.LinkedList : CollectionStorageModel.Simple);
                    return(collectionMapping.Object);
                }

                return(propertyMapping.Object);
            });
            RetractedStatements = new Dictionary <IEntity, ISet <Statement> >();
            AddedStatements     = new Dictionary <IEntity, ISet <Statement> >();
            Context             = new Mock <DefaultEntityContext>(null, MappingsRepository.Object, Detector);
            Context.SetupGet(instance => instance.Mappings).Returns(MappingsRepository.Object);
            Entity = new Entity(new Iri("test"), Context.Object);
        }
        protected override void ScenarioSetup()
        {
            CallCounter = new Dictionary <Iri, int>();
            Entity      = new Entity(Iri, Context);
            EntitySource.Setup(instance => instance.Load(It.IsAny <Iri>())).Returns <Iri>(SetupStatements);
            var entityMapping = new Mock <IEntityMapping>(MockBehavior.Strict);

            entityMapping.SetupGet(instance => instance.Type).Returns(typeof(IComplexEntity));
            Mock <ICollectionMapping>[] properties =
            {
                SetupPropertyMapping(entityMapping, "Ordinals"),
                SetupPropertyMapping(entityMapping, "Related"),
                SetupPropertyMapping(entityMapping, "Floats"),
                SetupPropertyMapping(entityMapping, "Doubles"),
                SetupPropertyMapping(entityMapping, "Other")
            };
            MappingsRepository.Setup(instance => instance.FindEntityMappingFor(It.IsAny <IEntity>(), It.IsAny <Iri>(), null))
            .Returns <IEntity, Iri, Iri>((entity, iri, graph) => entityMapping.Object);
            MappingsRepository.Setup(instance => instance.FindPropertyMappingFor(It.IsAny <IEntity>(), It.IsAny <Iri>(), null))
            .Returns <IEntity, Iri, Iri>((entity, iri, graph) => properties.Where(property => property.Object.Term == iri).Select(property => property.Object).First());
            MappingsRepository.Setup(instance => instance.FindPropertyMappingFor(It.IsAny <IEntity>(), It.IsAny <PropertyInfo>()))
            .Returns <IEntity, PropertyInfo>((entity, propertyInfo) => properties.Where(property => property.Object.PropertyInfo == propertyInfo).Select(property => property.Object).First());
        }
Example #7
0
 protected override void ScenarioSetup()
 {
     base.ScenarioSetup();
     MappingsRepository.Setup(instance => instance.FindPropertyMappingFor(It.IsAny <IEntity>(), It.IsAny <Iri>(), It.IsAny <Iri>()))
     .Returns <IEntity, Iri, Iri>((entity, iri, graph) => PropertyMapping.Object);
 }