Пример #1
0
        public void ProjectAsWrapper_Element_ProjectedValueContainsModelID()
        {
            // Arrange
            Customer           customer     = new Customer();
            SelectExpandClause selectExpand = new SelectExpandClause(new SelectItem[0], allSelected: true);
            Expression         source       = Expression.Constant(customer);

            // Act
            Expression projection = _binder.ProjectAsWrapper(source, selectExpand, _model.Customer);

            // Assert
            SelectExpandWrapper <Customer> customerWrapper = Expression.Lambda(projection).Compile().DynamicInvoke() as SelectExpandWrapper <Customer>;

            Assert.NotNull(customerWrapper.ModelID);
            Assert.Same(_model.Model, ModelContainer.GetModel(customerWrapper.ModelID));
        }
Пример #2
0
        public SelectExpandBinder(ODataQuerySettings settings, IAssembliesResolver assembliesResolver,
                                  SelectExpandQueryOption selectExpandQuery)
        {
            Contract.Assert(settings != null);
            Contract.Assert(assembliesResolver != null);
            Contract.Assert(selectExpandQuery != null);
            Contract.Assert(selectExpandQuery.Context != null);
            Contract.Assert(selectExpandQuery.Context.Model != null);
            Contract.Assert(settings.HandleNullPropagation != HandleNullPropagationOption.Default);

            _selectExpandQuery  = selectExpandQuery;
            _context            = selectExpandQuery.Context;
            _model              = _context.Model;
            _modelID            = ModelContainer.GetModelID(_model);
            _settings           = settings;
            _assembliesResolver = assembliesResolver;
        }
        public void ToDictionary_ContainsAllProperties_FromContainer()
        {
            // Arrange
            EdmModel      model      = new EdmModel();
            EdmEntityType entityType = new EdmEntityType("NS", "Name");

            model.AddElement(entityType);
            model.SetAnnotationValue(entityType, new ClrTypeAnnotation(typeof(TestEntity)));
            entityType.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Int32);
            MockPropertyContainer container = new MockPropertyContainer();

            container.Properties.Add("Property", 42);
            SelectExpandWrapper <TestEntity> wrapper = new SelectExpandWrapper <TestEntity>
            {
                Container = container,
                ModelID   = ModelContainer.GetModelID(model)
            };

            // Act
            var result = wrapper.ToDictionary();

            // Assert
            Assert.Equal(42, result["Property"]);
        }
        public void ToDictionary_ContainsAllStructuralProperties_IfInstanceIsNotNull()
        {
            // Arrange
            EdmModel      model      = new EdmModel();
            EdmEntityType entityType = new EdmEntityType("NS", "Name");

            model.AddElement(entityType);
            model.SetAnnotationValue(entityType, new ClrTypeAnnotation(typeof(TestEntity)));
            entityType.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Int32);
            IEdmTypeReference edmType = new EdmEntityTypeReference(entityType, isNullable: false);
            SelectExpandWrapper <TestEntity> testWrapper = new SelectExpandWrapper <TestEntity>
            {
                Instance = new TestEntity {
                    SampleProperty = 42
                },
                ModelID = ModelContainer.GetModelID(model)
            };

            // Act
            var result = testWrapper.ToDictionary();

            // Assert
            Assert.Equal(42, result["SampleProperty"]);
        }
Пример #5
0
        private IEdmModel GetModel()
        {
            Contract.Assert(ModelID != null);

            return(ModelContainer.GetModel(ModelID));
        }
Пример #6
0
        public void GetModelID_Returns_SameIDForSameModel()
        {
            EdmModel model = new EdmModel();

            Assert.Equal(ModelContainer.GetModelID(model), ModelContainer.GetModelID(model));
        }
 public SelectExpandWrapperTest()
 {
     _model   = new CustomersModelWithInheritance();
     _modelID = ModelContainer.GetModelID(_model.Model);
 }