Ejemplo n.º 1
0
        public void AssertTransformIsCorrect <TServer, TExtended>(Func <IQueryable <TExtended>, IQueryable> origQuery,
                                                                  Func <IQueryable <TServer>, IQueryable> expectedFunc)
            where TExtended : TServer
        {
            var extendedResourceMapper = new ExtendedResourceMapper(Client);
            var visitor = new TransformAdditionalPropertiesToAttributesVisitor(extendedResourceMapper);

            var wrappedSource = Enumerable.Empty <TServer>().AsQueryable();

            ExtendedResourceInfo extendedResourceInfo;

            if (!extendedResourceMapper.TryGetExtendedResourceInfo(typeof(TExtended), out extendedResourceInfo))
            {
                Assert.Fail("Unable to get ExtendedResourceInfo for " + typeof(TExtended));
            }

            var originalQuery =
                origQuery(new ExtendedQueryableRoot <TExtended>(Client, wrappedSource, extendedResourceInfo, extendedResourceMapper));

            var expectedQuery     = expectedFunc(wrappedSource);
            var expectedQueryExpr = expectedQuery.Expression;
            var actualQueryExpr   = visitor.Visit(originalQuery.Expression);

            Assert.That(actualQueryExpr.ToString(), Is.EqualTo(expectedQueryExpr.ToString()));
        }
Ejemplo n.º 2
0
        public ClientTypeMapper(IEnumerable <Type> clientResourceTypes)
        {
            this.resourceTypes = clientResourceTypes.ToList().AsReadOnly();

            this.typeNameMap =
                this.resourceTypes
                .Select(FromType)
                .ToDictionary(GetJsonTypeName, x => x, StringComparer.OrdinalIgnoreCase);

            this.extendedResourceMapper = new ExtendedResourceMapper(this);
        }
Ejemplo n.º 3
0
 internal ExtendedResourceInfo(Type extendedType, Type serverType, PropertyInfo dictProperty, ExtendedResourceMapper mapper)
 {
     ExtendedType = extendedType;
     ServerType = serverType;
     DictProperty = dictProperty;
     this.mapper = mapper;
     Type[] dictTypeArgs;
     if (dictProperty != null
         && dictProperty.PropertyType.TryExtractTypeArguments(typeof(IDictionary<,>), out dictTypeArgs))
         DictValueType = dictTypeArgs[1];
     this.extendedProperties =
         new Lazy<ReadOnlyCollection<ExtendedProperty>>(() => InitializeExtendedProperties().ToList().AsReadOnly());
 }
Ejemplo n.º 4
0
 public void SetUp()
 {
     this.typeMapper = new ClientTypeMapper(new[] { typeof(ITestResource) });
     this.extendedMapper = new ExtendedResourceMapper(this.typeMapper);
 }
Ejemplo n.º 5
0
 public void SetUp()
 {
     this.typeMapper     = new ClientTypeMapper(new[] { typeof(ITestResource) });
     this.extendedMapper = new ExtendedResourceMapper(this.typeMapper);
 }