public void Setup()
        {
            Mappings = new[]
            {
                MappingOf(new Iri("http://schema.org/name"), "eventName"),
                MappingOf(new Iri("http://schema.org/description"), "eventDescription"),
            };
            Builder  = new MappingsBuilder(Mappings);
            Strategy = new BodyResourceBoundIriTemplateExpansionStrategy();
            var mappingsRepository = new Mock <IMappingsRepository>(MockBehavior.Strict);

            mappingsRepository.Setup(_ => _.FindPropertyMappingFor(It.IsAny <IEntity>(), It.IsAny <Iri>(), It.IsAny <Iri>()))
            .Returns <IEntity, Iri, Iri>((entity, iri, graph) =>
            {
                var propertyInfo = (
                    from property in typeof(IEvent).GetProperties(BindingFlags.Instance | BindingFlags.Public)
                    from propertyMapping in property.GetCustomAttributes <PropertyAttribute>()
                    where propertyMapping.Iri == iri
                    select property).First();
                var result = new Mock <IPropertyMapping>(MockBehavior.Strict);
                result.SetupGet(_ => _.PropertyInfo).Returns(propertyInfo);
                return(result.Object);
            });
            var context = new Mock <IEntityContext>(MockBehavior.Strict);

            context.SetupGet(_ => _.Mappings).Returns(mappingsRepository.Object);
            Body             = new MulticastObject().ActLike <IEvent>();
            Body.Description = "Some description";
            Body.Unwrap().SetProperty(typeof(IEntity).GetProperty(nameof(IEntity.Context)), context.Object);
            Parameters      = new MulticastObject().ActLike <IEvent>();
            Parameters.Name = "the-name";
            Parameters.Unwrap().SetProperty(typeof(IEntity).GetProperty(nameof(IEntity.Context)), context.Object);
            ScenarioSetup();
            TheTest();
        }
        private T Create <T>(Iri iri)
        {
            var result = new MulticastObject();

            result.SetProperty(typeof(IEntity).GetProperty(nameof(IEntity.Iri)), iri);
            return(result.ActLike <T>());
        }
예제 #3
0
        public void Setup()
        {
            var entity = new MulticastObject();

            entity.SetProperty(PropertyInfo, "test");
            Entity = entity.ActLike <IUnmappedProduct>();
            PropertyInfo.GetAccessors().Last().Invoke(PropertyInfo, new object[] { Entity, "test", null });
        }
예제 #4
0
        public async Task Setup()
        {
            Result = new List <IResource>();
            Client = new Mock <IHydraClient>(MockBehavior.Strict);
            var proxy = new MulticastObject();

            proxy.SetProperty(HypermediaProcessorBase.ClientPropertyInfo, Client.Object);
            Collection = proxy.ActLike <ICollection>();
            ScenarioSetup();
            await TheTest();
        }
예제 #5
0
        public async Task Setup()
        {
            EntryPoint = new Mock <IHypermediaContainer>(MockBehavior.Strict);
            Client     = new Mock <IHydraClient>(MockBehavior.Strict);
            Client.Setup(_ => _.GetResource(It.IsAny <IResource>())).ReturnsAsync(EntryPoint.Object);
            var proxy = new MulticastObject();

            proxy.SetProperty(HypermediaProcessorBase.ClientPropertyInfo, Client.Object);
            ApiDocumentation = proxy.ActLike <IApiDocumentation>();
            proxy.SetProperty(
                typeof(IApiDocumentation).GetProperty(nameof(IApiDocumentation.EntryPoint)),
                Resource.Of <IResource>(new Uri("http://temp.uri/api")).Object);
            await TheTest();
        }
        public void Setup()
        {
            Template = new Mock <IIriTemplate>(MockBehavior.Strict);
            Template.SetupGet(_ => _.Template).Returns("some-uri{?with_variable}");
            var target = new Mock <IResource>(MockBehavior.Strict);

            target.SetupGet(_ => _.Iri).Returns(new Iri("test-url"));
            var context = new Mock <IEntityContext>(MockBehavior.Strict);

            context.Setup(_ => _.Create <ILink>(It.IsAny <Iri>())).Returns <Iri>(Create <ILink>);
            context.Setup(_ => _.Create <IResource>(It.IsAny <Iri>())).Returns <Iri>(Create <IResource>);
            var proxy = new MulticastObject();

            proxy.SetProperty(typeof(IPointingResource).GetProperty(nameof(IPointingResource.BaseUrl)), new Uri("http://temp.uri/"));
            proxy.SetProperty(typeof(IPointingResource).GetProperty(nameof(IPointingResource.Target)), target.Object);
            proxy.SetProperty(typeof(IDereferencableLink).GetProperty(nameof(IDereferencableLink.Relation)), "test");
            proxy.SetProperty(JsonLdHypermediaProcessor.IriTemplatePropertyInfo, Template.Object);
            proxy.SetProperty(typeof(IEntity).GetProperty(nameof(IEntity.Context)), context.Object);
            Link = proxy.ActLike <ITemplatedLink>();
            TheTest();
        }
 static HypermediaProcessorBase()
 {
     MulticastObject
     .ImplementationOf <IApiDocumentation>()
     .ForFunction(_ => _.GetEntryPoint())
     .ImplementedBy(_ => ApiDocumentation.GetEntryPoint(_));
     MulticastObject
     .ImplementationOf <IApiDocumentation>()
     .ForFunction(_ => _.GetEntryPoint(CancellationToken.None))
     .ImplementedBy(_ => ApiDocumentation.GetEntryPoint(_, CancellationToken.None));
     MulticastObject
     .ImplementationOf <ICollection>()
     .ForFunction(_ => _.GetIterator())
     .ImplementedBy(_ => Collection.GetIterator(_));
     MulticastObject
     .ImplementationOf <ITemplatedLink>()
     .ForFunction(_ => _.ExpandTarget((IDictionary <string, string>)null))
     .ImplementedBy(_ => TemplatedLink.ExpandTarget(_, (IDictionary <string, string>)null));
     MulticastObject
     .ImplementationOf <ITemplatedLink>()
     .ForFunction(_ => _.ExpandTarget((Action <MappingsBuilder>)null))
     .ImplementedBy(_ => TemplatedLink.ExpandTarget(_, (Action <MappingsBuilder>)null));
     MulticastObject
     .ImplementationOf <ITemplatedOperation>()
     .ForFunction(_ => _.ExpandTarget((IDictionary <string, string>)null))
     .ImplementedBy(_ => TemplatedOperation.ExpandTarget(_, (IDictionary <string, string>)null));
     MulticastObject
     .ImplementationOf <ITemplatedOperation>()
     .ForFunction(_ => _.ExpandTarget((Action <MappingsBuilder>)null))
     .ImplementedBy(_ => TemplatedOperation.ExpandTarget(_, (Action <MappingsBuilder>)null));
     MulticastObject
     .ImplementationOf <IResource>()
     .ForProperty(_ => _.DisplayName)
     .ImplementedBy(_ => ResourceExtensions.GetDisplayName(_));
     MulticastObject
     .ImplementationOf <IResource>()
     .ForProperty(_ => _.TextDescription)
     .ImplementedBy(_ => ResourceExtensions.GetTextDescription(_));
 }