Пример #1
0
        public object CreatePatchForm(Type resourceType, object original)
        {
            var extendedResourceProxy = original as ExtendedResourceBase;

            if (extendedResourceProxy != null)
            {
                var info = extendedResourceProxy.UserTypeInfo;
                return
                    (this.extendedResourceMapper.WrapForm(
                         CreatePatchForm(info.ServerType, extendedResourceProxy.WrappedResource),
                         info.ExtendedType));
            }

            var resourceInfo = this.GetResourceInfoForType(resourceType);

            if (!resourceType.GetCustomAttributes(typeof(AllowedMethodsAttribute), false)
                .OfType <AllowedMethodsAttribute>()
                .Select(x => x.Methods)
                .FirstOrDefault()
                .HasFlag(HttpMethod.Patch))
            {
                throw new InvalidOperationException("Method PATCH is not allowed for uri.");
            }

            var serverPatchForm = ObjectDeltaProxyBase.CreateDeltaProxy(original,
                                                                        FromType(
                                                                            resourceInfo.InterfaceType),
                                                                        this,
                                                                        null,
                                                                        resourceInfo.InterfaceType);

            return(serverPatchForm);
        }
Пример #2
0
        private ITestResource GetObjectProxy(Action <TestResource> modifyOriginal = null)
        {
            var original = new TestResource
            {
                Info     = "Hei",
                Children =
                {
                    new TestResource {
                        Info = "Childbar", Id = 1
                    },
                    new TestResource {
                        Info = "ChildToRemove", Id = 2
                    }
                },
                Set =
                {
                    new TestResource {
                        Info = "Childbar", Id = 10
                    },
                    new TestResource {
                        Info = "ChildToRemove", Id = 11
                    }
                },
                Spouse = new TestResource {
                    Info = "Jalla", Id = 3
                },
                Friend = new TestResource {
                    Info = "good friend", Id = 4
                },
                Id = 5
            };

            if (modifyOriginal != null)
            {
                modifyOriginal(original);
            }

            var proxy = (ITestResource)ObjectDeltaProxyBase.CreateDeltaProxy(original,
                                                                             this.typeMapper.FromType(
                                                                                 typeof(ITestResource)),
                                                                             this.typeMapper,
                                                                             null,
                                                                             typeof(ITestResource));

            Assert.IsFalse(((Delta)proxy).IsDirty);
            return(proxy);
        }