public void When_retrieved_through_Concrete_ConcreteInterface_Property_then_request_is_sent_with_original_name()
        {
            var entitySetName = Class.Name + "s";
            var entitySetPath = "/" + entitySetName;
            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();
            var entityPath = string.Format("{0}({1})", entitySetPath, ODataKeyPredicate.AsString(entityKeyValues));
            var expectedPath = entityPath + "/" + _camelCasedName;
            var keyValues = Class.GetSampleKeyArguments().ToArray();

            using (_mockedService = new MockService()
                .SetupPostEntity(TargetEntity, entityKeyValues)
                .SetupGetEntity(TargetEntity, keyValues))
            {
                var instance = _mockedService
                    .GetDefaultContext(Model)
                    .CreateConcrete(ConcreteType);

                instance.SetPropertyValues(Class.GetSampleKeyArguments());

                var propertyValue = instance.GetPropertyValue<RestShallowObjectFetcher>(ConcreteInterface,
                    _pascalCasedName);

                propertyValue.ExecuteAsync().Wait();
            }
        }
        public void The_Concrete_parses_the_response()
        {
            Init(m =>
            {
                m.Verbs = OdcmAllowedVerbs.Get;
                m.Parameters.Clear();
            });

            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();
            var instancePath = Class.GetDefaultEntityPath(entityKeyValues);
            var responseKeyValues = Class.GetSampleKeyArguments().ToArray();
            var response = Class.GetSampleJObject(responseKeyValues);

            using (var mockService = new MockService()
                .SetupPostEntity(TargetEntity, entityKeyValues))
            {
                mockService
                    .OnInvokeMethodRequest("GET",
                        instancePath + "/" + ServerMethodNameGenerator(),
                        null,
                        null)
                    .RespondWithGetEntity(TargetEntity.Class.GetDefaultEntitySetName(), response);

                var concrete = mockService
                    .GetDefaultContext(Model)
                    .CreateConcrete(ConcreteType);

                var result = concrete.InvokeMethod<Task>(Method.Name + "Async").GetPropertyValue<EntityBase>("Result");

                result.ValidatePropertyValues(responseKeyValues);
            }
        }
        public void The_Collection_path_is_the_fetcher_path_plus_property_name()
        {
            var collectionProperty =
                Model.GetProperties()
                    .Where(p => p.Class.Kind == OdcmClassKind.Entity)
                    .Where(p => p.IsCollection)
                    .RandomElement();

            var entityPath = Any.UriPath(1);

            entityPath = "/" + entityPath;

            using (_mockedService = new MockService()
                    .OnGetEntityPropertyRequest(entityPath, collectionProperty.Name)
                    .RespondWithGetEntity(Class.GetDefaultEntitySetName(), Class.GetSampleJObject()))
            {
                var fetcher = _mockedService
                    .GetDefaultContext(Model)
                    .CreateFetcher(Proxy.GetClass(collectionProperty.Class.Namespace, collectionProperty.Class.Name + "Fetcher"), entityPath);

                var propertyValue = fetcher.GetPropertyValue(collectionProperty.Name);

                propertyValue.InvokeMethod<Task>("ExecuteAsync").Wait();
            }
        }
        public void When_the_entity_is_not_null_then_AddAsync_POSTs_to_the_Entitys_canoncial_Uri_property_and_updates_the_added_instance()
        {
            var parentKeyValues = Class.GetSampleKeyArguments().ToArray();
            var navPropertyName = Class.NavigationProperties().First(p => p.Type == Class && p.IsCollection).Name;
            var navPropertyPath = string.Format("{0}/{1}", TargetEntity.Class.GetDefaultEntityPath(parentKeyValues), navPropertyName);
            var childKeyValues = Class.GetSampleKeyArguments().ToArray();

            using (_serviceMock = new MockService()
                    .SetupPostEntity(TargetEntity, parentKeyValues)
                    .OnPostEntityRequest(navPropertyPath)
                    .RespondWithCreateEntity(Class.GetDefaultEntitySetName(), Class.GetSampleJObject(childKeyValues)))
            {
                var parentEntity = Activator.CreateInstance(ConcreteType);
                var childEntity = Activator.CreateInstance(ConcreteType);

                var entitySetCollection = _serviceMock
                    .GetDefaultContext(Model)
                    .CreateCollection(CollectionType, ConcreteType, TargetEntity.Class.GetDefaultEntitySetPath());

                var navigationPropertyCollection = entitySetCollection
                    .Context
                    .CreateCollection(CollectionType, ConcreteType, navPropertyName, parentEntity);

                var parentTask = entitySetCollection.InvokeMethod<Task>("Add" + Class.Name + "Async", args: new[] { parentEntity, false });

                parentTask.Wait();

                var childTask = navigationPropertyCollection.InvokeMethod<Task>("Add" + Class.Name + "Async", args: new object[] { childEntity, false });

                childTask.Wait();

                childEntity.ValidatePropertyValues(childKeyValues);
            }
        }
        private void ValidateCollectionResponseParsing(
            Func<MockService, EntityArtifacts, Tuple<string, object>> instanceGenerator)
        {
            Init(m =>
            {
                m.Verbs = OdcmAllowedVerbs.Get;
                m.Parameters.Clear();
            });
            
            var responseKeyValues = Class.GetSampleKeyArguments().ToArray();
            var response = Class.GetSampleJObject(responseKeyValues);

            using (var mockService = new MockService())
            {
                var instanceAndPath = instanceGenerator(mockService, TargetEntity);

                mockService
                    .OnInvokeMethodRequest("GET",
                        instanceAndPath.Item1 + "/" + ServerMethodNameGenerator(),
                        null,
                        null)
                    .RespondWithGetEntity(TargetEntity.Class.GetDefaultEntitySetName(), response);

                var instance = instanceAndPath.Item2;

                var result =
                    instance.InvokeMethod<Task>(Method.Name + "Async").GetPropertyValue<IEnumerable<EntityBase>>("Result");

                result.ValidateCollectionPropertyValues(new List<IEnumerable<Tuple<string, object>>>
                {
                    responseKeyValues.ToList()
                });
            }
        }
        public void When_ExecuteAsync_is_called_it_GETs_the_collection_by_name()
        {
            using (_serviceMock = new MockService()
                    .SetupGetEntitySet(TargetEntity))
            {
                var context = _serviceMock
                    .GetDefaultContext(Model);

                var collection = context.CreateCollection(CollectionType, ConcreteType, Class.GetDefaultEntitySetPath());

                var task = collection.ExecuteAsync();
                task.Wait();
            }
        }
        public void When_the_path_is_a_Uri_it_requests_metadata_from_the_cloud()
        {
            var metadataPath = Any.UriPath(1);
            var metadata = Any.String(1);

            using (var mockService = new MockService()
                .OnRequest(c => c.Request.Path.ToString() == "/" + metadataPath && c.Request.Method == "GET")
                .RespondWith((c, b) => c.Response.Write(metadata)))
            {
                var metadataUri = mockService.GetBaseAddress() + metadataPath;

                MetadataResolver.GetMetadata(metadataUri)
                    .Should().Be(metadata);
            }
        }
        public void It_retrieves_a_value_from_its_own_path()
        {
            var keyValues = Class.GetSampleKeyArguments().ToArray();

            using (_mockedService = new MockService()
                    .SetupGetEntity(TargetEntity, keyValues))
            {
                var fetcher = _mockedService
                    .GetDefaultContext(Model)
                    .CreateFetcher(FetcherType, Class.GetDefaultEntityPath(keyValues));

                var result = fetcher.InvokeMethod<Task>("ExecuteAsync").GetPropertyValue<EntityBase>("Result");

                result.ValidatePropertyValues(keyValues);
            }
        }
        public void When_retrieved_through_Fetcher_then_request_is_sent_to_server_with_original_name()
        {
            var keyValues = Class.GetSampleKeyArguments().ToArray();

            using (_mockedService = new MockService()
                    .SetupGetEntityProperty(TargetEntity, keyValues, _camelCasedProperty))
            {
                var fetcher = _mockedService
                    .GetDefaultContext(Model)
                    .CreateFetcher(FetcherType, TargetEntity.Class.GetDefaultEntityPath(keyValues));

                var propertyFetcher = fetcher.GetPropertyValue<RestShallowObjectFetcher>(_pascalCasedName);

                propertyFetcher.ExecuteAsync().Wait();
            }
        }
        public void When_retrieved_through_Collection_GetById_indexer_then_request_is_sent_to_server_with_original_key_parameter_name()
        {
            var keyValues = Class.GetSampleKeyArguments().ToArray();

            using (_mockedService = new MockService()
                    .SetupGetEntity(TargetEntity, keyValues))
            {
                var collection = _mockedService
                    .GetDefaultContext(Model)
                    .CreateCollection(CollectionType, ConcreteType, Class.GetDefaultEntitySetPath());

                var fetcher =
                    collection.GetIndexerValue<RestShallowObjectFetcher>(keyValues.Select(k => k.Item2).ToArray());

                fetcher.ExecuteAsync().Wait();
            }
        }
        public void When_the_indexer_is_called_it_GETs_the_collection_by_name_and_passes_the_id_in_the_path()
        {
            var keyValues = Class.GetSampleKeyArguments().ToList();

            using (_serviceMock = new MockService()
                    .SetupGetEntity(TargetEntity, keyValues))
            {
                var collection = _serviceMock
                    .GetDefaultContext(Model)
                    .CreateCollection(CollectionType, ConcreteType, Class.GetDefaultEntitySetPath());

                var fetcher = collection.GetIndexerValue<RestShallowObjectFetcher>(keyValues.Select(k => k.Item2).ToArray());

                var task = fetcher.ExecuteAsync();
                task.Wait();
            }
        }
        public void When_a_single_property_is_expanded_it_populates_the_DollarExpand_query_parameter()
        {
            var navigationPropertyName = Class.NavigationProperties().Where(p => !p.IsCollection).RandomElement().Name;

            var param = Expression.Parameter(ConcreteInterface, "i");
            var navigationProperty = Expression.Property(param, navigationPropertyName);
            var lambda = Expression.Lambda(navigationProperty, new[] { param });

            using (_mockedService = new MockService()
                    .SetupGetEntitySet(TargetEntity, new []{navigationPropertyName}))
            {
                var fetcher = _mockedService
                    .GetDefaultContext(Model)
                    .CreateFetcher(FetcherType, Class.GetDefaultEntitySetName());

                fetcher.InvokeMethod<RestShallowObjectFetcher>("Expand", new []{lambda}, new []{ConcreteInterface}).InvokeMethod<Task>("ExecuteAsync").GetPropertyValue<EntityBase>("Result");
            }
        }
        public void When_it_changes_a_namespace_then_requests_OdataType_is_set_to_the_old_namespace()
        {
            var oldNamespace = _model.EntityContainer.Namespace;

            var namespacePrefix = Any.CSharpIdentifier();

            var namespaceRename = Any.CSharpIdentifier();

            var newNamespace = new OdcmNamespace(namespacePrefix + "." + namespaceRename);

            var namespaceMap = new Dictionary<string, string> { { oldNamespace.Name, namespaceRename } };

            var proxy = GetProxyWithChangedNamespaces(namespacePrefix, namespaceMap);

            var @class = oldNamespace.Classes.OfType<OdcmEntityClass>().First();

            var entityArtifacts = GetEntityArtifactsFromNewNamespace(@class, newNamespace, proxy, oldNamespace);

            using (var mockService = new MockService()
)
            {
                mockService
                    .OnRequest(c => c.Request.Method == "POST" &&
                                c.Request.Path.Value == @class.GetDefaultEntitySetPath() &&
                                IsNamespaceReplaced(c.Request, oldNamespace.Name, newNamespace.Name))
                    .RespondWith(
                        (c, b) =>
                        {
                            c.Response.StatusCode = 201;
                            c.Response.WithDefaultODataHeaders();
                            c.Response.WithODataEntityResponseBody(b,
                                @class.GetDefaultEntitySetName(), null);
                        });

                var collection = mockService
                    .CreateContainer(proxy.GetClass(newNamespace.Name, _model.EntityContainer.Name))
                    .GetPropertyValue<ReadOnlyQueryableSetBase>(entityArtifacts.Class.GetDefaultEntitySetName());

                var instance = entityArtifacts.ConcreteType.Initialize(@class.GetSampleKeyArguments().ToArray());

                var task = collection.InvokeMethod<Task>("Add" + @class.Name + "Async", args: new[] { instance, false });

                task.Wait();
            }
        public void When_CountAsync_is_called_it_GETs_the_collection_by_name()
        {
            var expectedCount = Any.Long();

            using (_serviceMock = new MockService()
                        .OnGetEntityCountRequest(TargetEntity.Class.GetDefaultEntitySetPath())
                        .RespondWithODataText(expectedCount.ToString()))
            {
                var context = _serviceMock
                    .GetDefaultContext(Model);

                var collection = context.CreateCollection(CollectionType, ConcreteType, Class.GetDefaultEntitySetPath());

                var task = collection.InvokeMethod<Task<long>>("CountAsync");

                task.Result
                    .Should().Be(expectedCount);
            }
        }
        public void When_retrieved_through_Concrete_ConcreteInterface_Property_then_request_is_sent_with_original_name()
        {
            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();

            using (_mockedService = new MockService()
                .SetupPostEntity(TargetEntity, entityKeyValues)
                .SetupGetEntity(TargetEntity))
            {
                var instance = _mockedService
                    .GetDefaultContext(Model)
                    .CreateConcrete(ConcreteType);

                instance.SetPropertyValues(Class.GetSampleKeyArguments());

                var propertyValue = instance.GetPropertyValue<IPagedCollection>(ConcreteInterface,
                    _pascalCasedName);

                propertyValue.GetNextPageAsync().Wait();
            }
        }
        public void When_the_entity_is_null_then_AddAsync_POSTs_to_the_EntitySet_and_updates_the_added_instance()
        {
            var keyValues = Class.GetSampleKeyArguments().ToArray();

            using (_serviceMock = new MockService()
                    .SetupPostEntity(TargetEntity, keyValues))
            {
                var collection = _serviceMock
                    .GetDefaultContext(Model)
                    .CreateCollection(CollectionType, ConcreteType, TargetEntity.Class.GetDefaultEntitySetPath());

                var instance = Activator.CreateInstance(ConcreteType);

                var task = collection.InvokeMethod<Task>("Add" + Class.Name + "Async", args: new[] { instance, false });

                task.Wait();

                instance.ValidatePropertyValues(keyValues);
            }
        }
        public void When_retrieved_through_Concrete_FetcherInterface_Property_then_request_is_sent_with_original_name()
        {
            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();

            using (_mockedService = new MockService()
                    .SetupPostEntity(TargetEntity, entityKeyValues)
                    .OnGetEntityPropertyRequest(Class.GetDefaultEntityPath(entityKeyValues), _camelCasedName)
                    .RespondWithGetEntity(Class.GetDefaultEntitySetName(), Class.GetSampleJObject()))
            {
                var instance = _mockedService
                    .GetDefaultContext(Model)
                    .CreateConcrete(ConcreteType);

                instance.SetPropertyValues(entityKeyValues);

                var propertyFetcher = instance.GetPropertyValue<ReadOnlyQueryableSetBase>(FetcherInterface,
                    _pascalCasedName);

                propertyFetcher.ExecuteAsync().Wait();
            }
        }
        public void When_the_verb_is_POST_the_Collection_passes_parameters_on_the_URI_and_in_the_body()
        {
            Init(model =>
            {
                Method = Any.OdcmMethodPost();
                Method.Class = model.EntityContainer;
                Method.ReturnType = Class;
                Method.IsCollection = false;
                Method.IsBoundToCollection = false;
                model.EntityContainer.Methods.Add(Method);
            });

            using (var mockService = new MockService())
            {
                var service = mockService
                    .CreateContainer(EntityContainerType);

                mockService.ValidateParameterPassing("POST", service, "", Method, ServerMethodNameGenerator(),
                    TargetEntity);
            }
        }
        public void The_Service_parses_the_response()
        {
            var responseKeyValues = Class.GetSampleKeyArguments().ToArray();
            var response = Class.GetSampleJObject(responseKeyValues);

            using (var mockService = new MockService())
            {
                mockService
                    .OnInvokeMethodRequest("GET",
                        "/" + ServerMethodNameGenerator(),
                        null,
                        null)
                    .RespondWithGetEntity(TargetEntity.Class.GetDefaultEntitySetName(), response);

                var service = mockService
                    .CreateContainer(EntityContainerType, Any.TokenGetterFunction());

                var result = service.InvokeMethod<Task>(Method.Name + "Async").GetPropertyValue<EntityBase>("Result");

                result.ValidatePropertyValues(responseKeyValues);
            }
        }
        public void When_multiple_properties_are_expanded_it_populates_the_DollarExpand_query_parameter()
        {
            var navigationProperties =
                Class.NavigationProperties().Where(p => !p.IsCollection).RandomSubset(2).ToArray();

            var navigationPropertyName1 = navigationProperties[0].Name;
            var lambda1 = GetExpandLambda(navigationPropertyName1);

            var navigationPropertyName2 = navigationProperties[1].Name;
            var lambda2 = GetExpandLambda(navigationPropertyName2);

            using (_mockedService = new MockService()
                    .SetupGetEntitySet(TargetEntity, new[] { navigationPropertyName1, navigationPropertyName2 }))
            {
                var fetcher = _mockedService
                    .GetDefaultContext(Model)
                    .CreateFetcher(FetcherType, Class.GetDefaultEntitySetName());

                fetcher
                    .InvokeMethod<RestShallowObjectFetcher>("Expand", new[] { lambda1 }, new[] { ConcreteInterface })
                    .InvokeMethod<RestShallowObjectFetcher>("Expand", new[] { lambda2 }, new[] { ConcreteInterface })
                    .InvokeMethod<Task>("ExecuteAsync").GetPropertyValue<EntityBase>("Result");
            }
        }
        public void When_updated_through_Concrete_accessor_then_request_is_sent_to_server_with_original_name()
        {
            var entitySetName = Class.Name + "s";
            var entitySetPath = "/" + entitySetName;
            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();
            var entityPath = string.Format("{0}({1})", entitySetPath, ODataKeyPredicate.AsString(entityKeyValues));
            var expectedPath = entityPath;

            using (_mockedService = new MockService()
                    .SetupPostEntity(TargetEntity, entityKeyValues)
                    .OnPatchEntityRequest(expectedPath)
                        .RespondWithODataOk())
            {
                var context = _mockedService
                    .GetDefaultContext(Model);

                var instance = context
                    .CreateConcrete(ConcreteType);

                var relatedInstance = Activator.CreateInstance(ConcreteType);

                instance.SetPropertyValue(_pascalCasedName, relatedInstance);

                instance.UpdateAsync().Wait();
            }
        }
        public void When_the_verb_is_POST_the_Concrete_passes_parameters_on_the_URI_and_in_the_body()
        {
            Init(m =>
            {
                Method = Any.OdcmMethodPost();
                Method.Class = Class;
                Method.ReturnType = null;
                Method.IsCollection = false;
                Class.Methods.Add(Method);
            });

            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();
            var instancePath = Class.GetDefaultEntityPath(entityKeyValues);

            using (var mockService = new MockService(true)
                    .SetupPostEntity(TargetEntity, entityKeyValues)
)
            {
                var concrete = mockService
                    .GetDefaultContext(Model)
                    .CreateConcrete(ConcreteType);

                mockService.ValidateParameterPassing("POST", concrete, instancePath, Method, 
                    ServerMethodNameGenerator(), null);
            }
        public void When_retrieved_through_Concrete_ConcreteInterface_Property_then_request_is_sent_with_originalName()
        {
            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();
            var expectedPath = Class.GetDefaultEntityPath(entityKeyValues) + "/" + NavigationProperty.Name;
            var keyValues = Class.GetSampleKeyArguments().ToArray();

            using (_mockedService = new MockService()
                .SetupPostEntity(TargetEntity, entityKeyValues)
                .SetupGetEntity(TargetEntity))
            {
                var instance = _mockedService
                    .GetDefaultContext(Model)
                    .CreateConcrete(ConcreteType);

                instance.SetPropertyValues(Class.GetSampleKeyArguments());

                var propertyValue = instance.GetPropertyValue<RestShallowObjectFetcher>(ConcreteInterface,
                    NavigationProperty.Name);

                propertyValue.ExecuteAsync().Wait();
            }
        }
        public void When_retrieved_through_Fetcher_then_request_is_sent_to_server_with_original_name()
        {
            var entityPath = "/" + Any.UriPath(1);

            using (_mockedService = new MockService()
                    .OnGetEntityPropertyRequest(entityPath, _camelCasedName)
                    .RespondWithGetEntity(Class.GetDefaultEntitySetName(), Class.GetSampleJObject()))
            {
                var fetcher = _mockedService
                    .GetDefaultContext(Model)
                    .CreateFetcher(FetcherType, entityPath);

                var propertyFetcher = fetcher.GetPropertyValue<ReadOnlyQueryableSetBase>(_pascalCasedName);

                propertyFetcher.ExecuteAsync().Wait();
            }
        }
        }

        [Fact]
        public void When_the_verb_is_GET_the_Fetcher_passes_parameters_on_the_URI()
        {
            Init(m =>
            {
                Method = Any.OdcmMethodGet();
                Method.Class = Class;
                Method.ReturnType = null;
                Method.IsCollection = false;
                Class.Methods.Add(Method);
            });

            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();
            var fetcherPath = Class.GetDefaultEntityPath(entityKeyValues);

            using (var mockService = new MockService()
)
            {
                var fetcher = mockService
                    .GetDefaultContext(Model)
                    .CreateFetcher(FetcherType, fetcherPath);
        public void When_updated_through_Concrete_accessor_then_request_is_sent_to_server_with_originalName()
        {
            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();
            var expectedPath = Class.GetDefaultEntityPath(entityKeyValues);

            using (_mockedService = new MockService()
                    .SetupPostEntity(TargetEntity, entityKeyValues)
                    .OnPatchEntityRequest(expectedPath)
                        .RespondWithODataOk())
            {
                var context = _mockedService
                    .GetDefaultContext(Model);

                var instance = context
                    .CreateConcrete(ConcreteType);

                var relatedInstance = Activator.CreateInstance(NavTargetConcreteType);

                instance.SetPropertyValue(NavigationProperty.Name, relatedInstance);

                instance.UpdateAsync().Wait();
            }
        }
        public void When_a_renamed_property_is_expanded_it_populates_the_DollarExpand_query_parameter()
        {
            var keyValues = Class.GetSampleKeyArguments().ToArray();

            var param = Expression.Parameter(ConcreteInterface, "i");
            var navigationProperty = Expression.Property(param, _pascalCasedName);
            var lambda = Expression.Lambda(navigationProperty, new[] { param });

            using (_mockedService = new MockService()
                    .SetupGetEntity(TargetEntity, keyValues, new[]{_camelCasedName}))
            {
                var fetcher = _mockedService
                    .GetDefaultContext(Model)
                    .CreateFetcher(FetcherType, Class.GetDefaultEntityPath(keyValues));

                fetcher.InvokeMethod<RestShallowObjectFetcher>("Expand", new[] {lambda}, new[] {ConcreteInterface})
                    .InvokeMethod<Task>("ExecuteAsync").Wait();
            }
        }
        public void When_updated_through_Concrete_accessor_then_request_is_sent_to_server_with_original_name()
        {
            var entitySetName = Class.Name + "s";
            var entitySetPath = "/" + entitySetName;
            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();
            var entityPath = string.Format("{0}({1})", entitySetPath, ODataKeyPredicate.AsString(entityKeyValues));
            var expectedPath = entityPath + "/" + _camelCasedName;

            using (_mockedService = new MockService()
                .OnPostEntityRequest(entitySetPath)
                    .RespondWithCreateEntity(Class.Name + "s", Class.GetSampleJObject(entityKeyValues))
                .OnPostEntityRequest(expectedPath)
                    .RespondWithODataOk())
            {
                var context = _mockedService
                    .GetDefaultContext(Model);

                var instance = context
                    .CreateConcrete(ConcreteType);

                var relatedInstance = Activator.CreateInstance(ConcreteType);

                var collection = Activator.CreateInstance(typeof (List<>).MakeGenericType(ConcreteType));

                collection.InvokeMethod("Add", new[] { relatedInstance });

                instance.SetPropertyValue(_pascalCasedName, collection);

                context.SaveChangesAsync().Wait();
            }
        }
        public void When_the_verb_is_POST_the_Collection_passes_parameters_on_the_URI_and_in_the_body()
        {
            Init(m =>
            {
                Method = Any.OdcmMethodPost();
                Method.Class = Class;
                Method.ReturnType = null;
                Method.IsCollection = false;
                Method.IsBoundToCollection = true;
                Class.Methods.Add(Method);
            });

            using (var mockService = new MockService(true))
            {
                var collectionPath = Any.UriPath(1);

                var collection = mockService
                    .GetDefaultContext(Model)
                    .CreateCollection(CollectionType, ConcreteType, collectionPath);

                mockService.ValidateParameterPassing("POST", collection, "/" + collectionPath, Method,
                    ServerMethodNameGenerator(), null);
            }
        }
        public void When_retrieved_through_Concrete_then_request_is_sent_to_server_with_original_name()
        {
            var entityKeyValues = Class.GetSampleKeyArguments().ToArray();

            using (_mockedService = new MockService()
                    .SetupPostEntity(TargetEntity, entityKeyValues)
                    .SetupGetEntityProperty(TargetEntity, entityKeyValues, _camelCasedProperty))
            {
                var instance = _mockedService
                    .GetDefaultContext(Model)
                    .CreateConcrete(ConcreteType);

                instance.SetPropertyValues(entityKeyValues);

                var propertyFetcher = instance.GetPropertyValue<RestShallowObjectFetcher>(FetcherInterface,
                    _pascalCasedName);

                propertyFetcher.ExecuteAsync().Wait();
            }
        }