public void TestQuerying (Type dataType)
        {
            RunAsync (async delegate {
                var mgr = new ForeignRelationManager ();

                // Test null relation
                var relation = new ForeignRelation () {
                    Type = dataType,
                    Id = null,
                };
                Assert.IsNull (await mgr.ToListAsync (relation));

                // Test missing relation
                relation = new ForeignRelation () {
                    Type = dataType,
                    Id = Guid.NewGuid (),
                };
                Assert.IsNull (await mgr.ToListAsync (relation));

                // Create dummy data:
                var inst = (CommonData)Activator.CreateInstance (dataType);
                inst.Id = relation.Id.Value;

                var putAsyncMethod = DataStore.GetType ().GetMethod ("PutAsync").MakeGenericMethod (dataType);
                await (Task)putAsyncMethod.Invoke (DataStore, new object[] { inst });
                Assert.IsNotNull (await mgr.ToListAsync (relation));
            });
        }
Esempio n. 2
0
        public async Task <CommonData> ToListAsync(ForeignRelation relation)
        {
            var type = relation.Type;
            var id   = relation.Id;

            if (type == typeof(ClientData))
            {
                return(await ToListAsync <ClientData> (id).ConfigureAwait(false));
            }
            else if (type == typeof(ProjectData))
            {
                return(await ToListAsync <ProjectData> (id).ConfigureAwait(false));
            }
            else if (type == typeof(ProjectUserData))
            {
                return(await ToListAsync <ProjectUserData> (id).ConfigureAwait(false));
            }
            else if (type == typeof(TagData))
            {
                return(await ToListAsync <TagData> (id).ConfigureAwait(false));
            }
            else if (type == typeof(TaskData))
            {
                return(await ToListAsync <TaskData> (id).ConfigureAwait(false));
            }
            else if (type == typeof(TimeEntryData))
            {
                return(await ToListAsync <TimeEntryData> (id).ConfigureAwait(false));
            }
            else if (type == typeof(TimeEntryTagData))
            {
                return(await ToListAsync <TimeEntryTagData> (id).ConfigureAwait(false));
            }
            else if (type == typeof(UserData))
            {
                return(await ToListAsync <UserData> (id).ConfigureAwait(false));
            }
            else if (type == typeof(WorkspaceData))
            {
                return(await ToListAsync <WorkspaceData> (id).ConfigureAwait(false));
            }
            else if (type == typeof(WorkspaceUserData))
            {
                return(await ToListAsync <WorkspaceUserData> (id).ConfigureAwait(false));
            }

            throw new InvalidOperationException(String.Format("Unknown relation type {0}", type));
        }
Esempio n. 3
0
        public static Task <CommonData> QueryAsync(this ForeignRelation relation)
        {
            var manager = ServiceContainer.Resolve <ForeignRelationManager> ();

            return(manager.QueryAsync(relation));
        }