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())); }
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); }
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()); }
public void SetUp() { this.typeMapper = new ClientTypeMapper(new[] { typeof(ITestResource) }); this.extendedMapper = new ExtendedResourceMapper(this.typeMapper); }