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 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_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();
            }
        }
コード例 #4
0
        public static string GetDefaultEntityPath(this OdcmEntityClass odcmClass, IEnumerable <Tuple <string, object> > keyValues = null)
        {
            keyValues = keyValues ?? odcmClass.GetSampleKeyArguments().ToArray();

            return(string.Format("{0}({1})", odcmClass.GetDefaultEntitySetPath(), ODataKeyPredicate.AsString(keyValues.ToArray())));
        }