public void UpdateProvider2PropertyTest()
        {
            IDataService     service   = this.serviceFactory.CreateService <CustomUpdatableProviderService>();
            UpdatableWrapper updatable = new UpdatableWrapper(service);

            foreach (ODataProtocolVersion version in new[] { ODataProtocolVersion.V4 })
            {
                service.Configuration.DataServiceBehavior.MaxProtocolVersion = version;
                try
                {
                    updatable.GetType().GetProperty("UpdateProvider2", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(updatable, null);
                }
                catch (TargetInvocationException tie)
                {
                    InvalidOperationException e = (InvalidOperationException)tie.InnerException;
                    Assert.AreEqual("To support service actions, the data service must implement IServiceProvider.GetService() to return an implementation of IDataServiceUpdateProvider2 or the data source must implement IDataServiceUpdateProvider2.", e.Message);
                }
            }
        }
        public void UpdateProviderPropertyTest()
        {
            IDataService service = this.serviceFactory.CreateService <CustomUpdateProvider2Service>();

            ODataProtocolVersion[] versions   = new[] { ODataProtocolVersion.V4 };
            bool[]        boolValues          = new[] { true, false };
            List <string> failureCombinations = new List <string>();

            foreach (var version in versions)
            {
                foreach (var hasReflectionOrEFProviderQueryBehavior in boolValues)
                {
                    foreach (var implementsIUpdatable in boolValues)
                    {
                        foreach (var implementsIDSUP in boolValues)
                        {
                            foreach (var implementsIDSUP2 in boolValues)
                            {
                                service.Configuration.DataServiceBehavior.MaxProtocolVersion = version;
                                CustomUpdateProvider2Service.ImplementsIUpdatable            = implementsIUpdatable;
                                CustomUpdateProvider2Service.ImplementsIDSUP    = implementsIDSUP;
                                CustomUpdateProvider2Service.ImplementsIDSUP2   = implementsIDSUP2;
                                CustomUpdateProvider2Service.IUpdatableGetCount = 0;
                                CustomUpdateProvider2Service.IDataServiceUpdateProviderGetCount  = 0;
                                CustomUpdateProvider2Service.IDataServiceUpdateProvider2GetCount = 0;

                                ((DataServiceSimulator)service).Provider = CreateProviderWrapper(service.Configuration, hasReflectionOrEFProviderQueryBehavior);
                                UpdatableWrapper updatable = new UpdatableWrapper(service);
                                try
                                {
                                    var instance = updatable.GetType().GetProperty("UpdateProvider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(updatable, null);
                                    Assert.IsNotNull(instance, "UpdatableWrapper should throw if UpdateProvider fails to get the interface.");
                                    Assert.AreEqual(1, CustomUpdateProvider2Service.IDataServiceUpdateProvider2GetCount);

                                    // None of this code is actually hit, we need to investigate this.
                                    if (!CustomUpdateProvider2Service.ImplementsIDSUP2)
                                    {
                                        if (hasReflectionOrEFProviderQueryBehavior)
                                        {
                                            Assert.AreEqual(1, CustomUpdateProvider2Service.IUpdatableGetCount);
                                        }
                                        else
                                        {
                                            Assert.AreEqual(0, CustomUpdateProvider2Service.IUpdatableGetCount);
                                        }

                                        if (!CustomUpdateProvider2Service.ImplementsIUpdatable)
                                        {
                                            Assert.AreEqual(1, CustomUpdateProvider2Service.IDataServiceUpdateProviderGetCount);
                                        }
                                        else
                                        {
                                            if (hasReflectionOrEFProviderQueryBehavior)
                                            {
                                                Assert.AreEqual(0, CustomUpdateProvider2Service.IDataServiceUpdateProviderGetCount);
                                            }
                                            else
                                            {
                                                Assert.AreEqual(1, CustomUpdateProvider2Service.IDataServiceUpdateProviderGetCount);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Assert.AreEqual(0, CustomUpdateProvider2Service.IUpdatableGetCount);
                                        Assert.AreEqual(0, CustomUpdateProvider2Service.IDataServiceUpdateProviderGetCount);
                                    }
                                }
                                catch (TargetInvocationException tie)
                                {
                                    string errorCaseVariation = string.Format("Version:{0}, hasReflectionOrEFProviderQueryBehavior:{1}, implementsIUpdatable:{2}, implementsIDSUP:{3}, implementsIDSUP2:{4}", version, hasReflectionOrEFProviderQueryBehavior, implementsIUpdatable, implementsIDSUP, implementsIDSUP2);
                                    failureCombinations.Add(errorCaseVariation);
                                    DataServiceException e = (DataServiceException)tie.InnerException;
                                    Assert.AreEqual(501, e.StatusCode);
                                    if (hasReflectionOrEFProviderQueryBehavior)
                                    {
                                        Assert.AreEqual("The data source must implement IUpdatable, IDataServiceUpdateProvider or IDataServiceUpdateProvider2 to support updates.", e.Message);
                                    }
                                    else
                                    {
                                        Assert.AreEqual("The data source must implement IDataServiceUpdateProvider or IDataServiceUpdateProvider2 to support updates.", e.Message);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }