示例#1
0
        public void It_adds_a_link_to_a_collection_valued_navigation_property()
        {
            var entityKeyValues        = Class.GetSampleKeyArguments().ToArray();
            var propertyPath           = Class.GetDefaultEntityPath(entityKeyValues) + "/" + NavigationProperty.Name;
            var relatedEntityKeyValues = NavTargetClass.GetSampleKeyArguments().ToArray();
            var relatedEntityPath      = NavTargetClass.GetDefaultEntityPath(relatedEntityKeyValues);

            using (_mockedService = new MockService())
            {
                var baseAddress     = _mockedService.GetBaseAddress().TrimEnd('/');
                var expectedJObject = new JObject();
                expectedJObject["@odata.id"] = baseAddress + relatedEntityPath;

                _mockedService
                .SetupPostEntity(TargetEntity, entityKeyValues)
                .SetupPostEntity(NavTargetEntity, relatedEntityKeyValues)
                .OnPostAddLinkRequest(propertyPath, expectedJObject)
                .RespondWithODataOk();

                var context    = _mockedService.GetDefaultContext(Model);
                var collection = context.CreateCollection(NavTargetCollectionType, NavTargetConcreteType,
                                                          propertyPath);
                var sourceInstance = context.CreateConcrete(ConcreteType);
                var targetInstance = context.CreateConcrete(NavTargetConcreteType);

                collection.InvokeMethod <Task>("AddLinkAsync", new object[] { sourceInstance, targetInstance, System.Type.Missing }).Wait();
            }
        }
示例#2
0
        private void Init(bool isCollection)
        {
            base.Init(m =>
            {
                var @namespace = m.Namespaces[0];
                NavTargetClass = Any.OdcmEntityClass(@namespace);
                @namespace.Types.Add(NavTargetClass);

                m_NavTargetProjection = NavTargetClass.AnyOdcmProjection();
                NavTargetClass.AddProjection(m_NavTargetProjection.Capabilities);

                var @class         = @namespace.Classes.First();
                NavigationProperty = Any.OdcmProperty(p =>
                {
                    p.Class        = @class;
                    p.Projection   = m_NavTargetProjection;
                    p.IsCollection = isCollection;
                });

                m.Namespaces[0].Classes.First().Properties.Add(NavigationProperty);
            });

            var identifier = NamesService.GetFetcherInterfaceName(NavTargetClass, m_NavTargetProjection);

            m_NavTargetFetcherInterface = Proxy.GetInterface(NavTargetClass.Namespace, identifier.Name);

            identifier = NamesService.GetCollectionInterfaceName(NavTargetClass, m_NavTargetProjection);
            m_NavTargetCollectionInterface = Proxy.GetInterface(NavTargetClass.Namespace, identifier.Name);
        }
        public void It_removes_a_link_when_delay_saving_and_calling_SaveChangesAsync()
        {
            var entityKeyValues        = Class.GetSampleKeyArguments().ToArray();
            var propertyPath           = Class.GetDefaultEntityPath(entityKeyValues) + "/" + NavigationProperty.Name;
            var relatedEntityKeyValues = NavTargetClass.GetSampleKeyArguments().ToArray();
            var relatedEntityPath      = NavTargetClass.GetDefaultEntityPath(relatedEntityKeyValues);

            using (_mockedService = new MockService())
            {
                var baseAddress = _mockedService.GetBaseAddress().TrimEnd('/');
                var idQueryPath = baseAddress + relatedEntityPath;

                _mockedService
                .SetupPostEntity(TargetEntity, entityKeyValues)
                .SetupPostEntity(NavTargetEntity, relatedEntityKeyValues);

                var context    = _mockedService.GetDefaultContext(Model);
                var collection = context.CreateCollection(NavTargetCollectionType, NavTargetConcreteType,
                                                          propertyPath);
                var sourceInstance = context.CreateConcrete(ConcreteType);
                var targetInstance = context.CreateConcrete(NavTargetConcreteType);

                collection.InvokeMethod <Task>("RemoveLinkAsync", new object[] { sourceInstance, targetInstance, true }).Wait();

                _mockedService = _mockedService.OnDeleteLinkRequest(propertyPath, idQueryPath)
                                 .RespondWithODataOk();

                context.SaveChangesAsync().Wait();
            }
        }
        public void It_creates_a_new_entity_when_delay_saving_and_calling_SaveChangesAsync()
        {
            var entityKeyValues        = Class.GetSampleKeyArguments().ToArray();
            var propertyPath           = Class.GetDefaultEntityPath(entityKeyValues) + "/" + NavigationProperty.Name;
            var relatedEntityKeyValues = NavTargetClass.GetSampleKeyArguments().ToArray();
            var expectedJObject        = new JObject();
            var targetInstance         = Activator.CreateInstance(NavTargetConcreteType);

            foreach (var keyProperty in relatedEntityKeyValues)
            {
                var key = NavTargetConcreteType.GetKeyProperties().Single(p => p.Name == keyProperty.Item1);
                key.SetValue(targetInstance, keyProperty.Item2);
                expectedJObject[keyProperty.Item1] = (string)keyProperty.Item2;
            }

            using (_mockedService = new MockService()
                                    .SetupPostEntity(TargetEntity, entityKeyValues))
            {
                var context        = _mockedService.GetDefaultContext(Model);
                var fetcher        = context.CreateFetcher(NavTargetFetcherType, propertyPath);
                var sourceInstance = context.CreateConcrete(ConcreteType);

                fetcher.InvokeMethod <Task>("SetAsync", new object[] { sourceInstance, targetInstance, true }).Wait();

                _mockedService = _mockedService.OnPatchEntityRequest(propertyPath, expectedJObject)
                                 .RespondWithODataOk();

                context.SaveChangesAsync().Wait();
            }
        }
        public void It_does_not_update_a_link_when_delay_saving()
        {
            var entityKeyValues        = Class.GetSampleKeyArguments().ToArray();
            var propertyPath           = Class.GetDefaultEntityPath(entityKeyValues) + "/" + NavigationProperty.Name;
            var relatedEntityKeyValues = NavTargetClass.GetSampleKeyArguments().ToArray();

            using (_mockedService = new MockService()
                                    .SetupPostEntity(TargetEntity, entityKeyValues)
                                    .SetupPostEntity(NavTargetEntity, relatedEntityKeyValues))
            {
                var context        = _mockedService.GetDefaultContext(Model);
                var fetcher        = context.CreateFetcher(NavTargetFetcherType, propertyPath);
                var sourceInstance = context.CreateConcrete(ConcreteType);
                var targetInstance = context.CreateConcrete(NavTargetConcreteType);

                fetcher.InvokeMethod <Task>("UpdateLinkAsync", new object[] { sourceInstance, targetInstance, true }).Wait();
            }
        }