Beispiel #1
0
        protected ResourceServiceTestEnvironmentBase(string resourceName)
        {
            _resourceName = resourceName;

            var resourceGraphBuilder = new ResourceGraphBuilder();

            resourceGraphBuilder.AddResource <TResource, string>(_resourceName);
            SetupResourceGraph(resourceGraphBuilder);
            ResourceGraph = resourceGraphBuilder.Build();

            JsonApiContext = Substitute.For <IJsonApiContext>();
            JsonApiContext.ResourceGraph.Returns(ResourceGraph);
            JsonApiContext.RequestEntity.Returns(ResourceGraph.GetContextEntity(_resourceName));
            JsonApiContext.Options.Returns(new JsonApiOptions {
                IncludeTotalRecordCount = true
            });

            Entities = new MemoryRepository <TEntity>(GetUniqueKeySelectors(), GetInitialData());

            var config = new MapperConfiguration(cfg =>
            {
                cfg.ValidateInlineMaps = false;
                cfg.AddProfile(new XFMapperProfile(SiteId));
                SetupMapper(cfg);
            });

            Mapper       = config.CreateMapper();
            UserAccessor = Substitute.For <IUserAccessor>();
            UserAccessor.IsAuthenticated.Returns(false);

            SiteOptions = Substitute.For <IOptions <SiteOptions> >();
            SiteOptions.Value.Returns(new SiteOptions
            {
                Id        = SiteId,
                Name      = "xForge",
                Origin    = new Uri("http://" + SiteAuthority),
                SiteDir   = SiteDir,
                SharedDir = SharedDir
            });
        }
Beispiel #2
0
        public AttrAttribute GetAttribute(string name)
        {
            ContextEntity resourceType = ResourceGraph.GetContextEntity(_resourceName);

            return(resourceType.Attributes.First(a => a.PublicAttributeName == name));
        }
Beispiel #3
0
        public RelationshipAttribute GetRelationship(string name)
        {
            ContextEntity resourceType = ResourceGraph.GetContextEntity(_resourceName);

            return(resourceType.Relationships.First(r => r.PublicRelationshipName == name));
        }