Beispiel #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);
        }
Beispiel #2
0
 protected override void ScenarioSetup()
 {
     Entity = (Entity)Context.Create <IProduct>(rdfs.Class).Unwrap();
     ChangeDetector.Setup(instance => instance.Process(It.IsAny <Entity>(), It.IsAny <IDictionary <IEntity, ISet <Statement> > >(), It.IsAny <IDictionary <IEntity, ISet <Statement> > >()))
     .Callback <Entity, IDictionary <IEntity, ISet <Statement> >, IDictionary <IEntity, ISet <Statement> > >((entity, retracted, added) =>
     {
         RetractedStatements = retracted;
         AddedStatements     = added;
     });
     DeletedEntities = new List <Iri>();
     EntitySource.Setup(instance => instance.Commit(
                            It.IsAny <IEnumerable <Iri> >(),
                            It.IsAny <IDictionary <IEntity, ISet <Statement> > >(),
                            It.IsAny <IDictionary <IEntity, ISet <Statement> > >()));
 }
        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());
        }