Esempio n. 1
0
        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 fetcherInstance = context
                                      .CreateFetcher(FetcherType, expectedPath);

                var relatedInstance = Activator.CreateInstance(ConcreteType);

                instance.SetPropertyValue(_pascalCasedName, relatedInstance);

                fetcherInstance.InvokeMethod <Task>("UpdateAsync", new object[] { instance, Type.Missing }).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 fetcher = context.CreateFetcher(FetcherType, Class.GetDefaultEntityPath(entityKeyValues));

                var collectionFetcher = fetcher.GetPropertyValue(_pascalCasedName);

                var addMethod = "Add" + ConcreteType.Name + "Async";

                var relatedInstance = Activator.CreateInstance(ConcreteType);

                collectionFetcher.InvokeMethod <Task>(addMethod, new object[] { relatedInstance, System.Type.Missing }).Wait();
            }
        }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 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())));
        }