public void TestMediaItemLoader_SingleMIAs_IdFilter() { MockDBUtils.Reset(); SingleTestMIA single1 = TestBackendUtils.CreateSingleMIA("SINGLE1", Cardinality.Inline, true, false); SingleTestMIA single2 = TestBackendUtils.CreateSingleMIA("SINGLE2", Cardinality.Inline, false, true); Guid itemId = new Guid("aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa"); IList <Guid> ids = new List <Guid>(); ids.Add(itemId); IFilter filter = new MediaItemIdFilter(ids); MockReader reader = MockDBUtils.AddReader( "SELECT T0.MEDIA_ITEM_ID A2, T0.MEDIA_ITEM_ID A3, T1.MEDIA_ITEM_ID A4, T0.ATTR_STRING A0, T1.ATTR_INTEGER A1 FROM M_SINGLE1 T0 INNER JOIN M_SINGLE2 T1 ON T1.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID " + " WHERE T0.MEDIA_ITEM_ID = @V0", "A2", "A3", "A4", "A0", "A1"); reader.AddResult(itemId, itemId, itemId, "zero", 0); Guid[] requiredAspects = new Guid[] { single1.ASPECT_ID, single2.ASPECT_ID }; Guid[] optionalAspects = null; MediaItemQuery query = new MediaItemQuery(requiredAspects, optionalAspects, filter); CompiledMediaItemQuery compiledQuery = CompiledMediaItemQuery.Compile(MockCore.Management, query); MediaItem result = compiledQuery.QueryMediaItem(); Assert.AreEqual(itemId, result.MediaItemId, "MediaItem ID"); // TODO: More asserts }
public void TestFilteredRelationshipQueryBuilder() { // Use the real RelationshipFilter because CompiledFilter is hard coded to look for it MockCore.AddMediaItemAspectStorage(RelationshipAspect.Metadata); SingleTestMIA mia1 = TestBackendUtils.CreateSingleMIA("Meta1", Cardinality.Inline, true, true); SingleTestMIA mia2 = TestBackendUtils.CreateSingleMIA("Meta2", Cardinality.Inline, true, true); SingleTestMIA mia3 = TestBackendUtils.CreateSingleMIA("Meta3", Cardinality.Inline, true, true); ICollection <MediaItemAspectMetadata> requiredMIATypes = new List <MediaItemAspectMetadata>(); requiredMIATypes.Add(mia1.Metadata); requiredMIATypes.Add(mia2.Metadata); IFilter linkedMovieFilter = BooleanCombinationFilter.CombineFilters( BooleanOperator.And, new RelationalFilter(mia3.ATTR_INTEGER, RelationalOperator.EQ, 1), new RelationalFilter(mia3.ATTR_STRING, RelationalOperator.EQ, "test")); Guid movieType = new Guid("bbbbbbbb-2222-2222-2222-bbbbbbbbbbbb"); Guid actorType = new Guid("cccccccc-3333-3333-3333-cccccccccccc"); IFilter filter = new FilteredRelationshipFilter(actorType, movieType, linkedMovieFilter); MIAQueryBuilder builder = new MIAQueryBuilder(MockCore.Management, new List <QueryAttribute>(), null, requiredMIATypes, new List <MediaItemAspectMetadata>(), filter, null, null); string mediaItemIdAlias = null; IDictionary <MediaItemAspectMetadata, string> miamAliases = null; IDictionary <QueryAttribute, string> attributeAliases = null; string statementStr = null; IList <BindVar> bindVars = null; builder.GenerateSqlStatement(out mediaItemIdAlias, out miamAliases, out attributeAliases, out statementStr, out bindVars); Console.WriteLine("mediaItemIdAlias: {0}", mediaItemIdAlias); Console.WriteLine("miamAliases: [{0}]", string.Join(",", miamAliases)); Console.WriteLine("attributeAliases: [{0}]", string.Join(",", attributeAliases)); Console.WriteLine("statementStr: {0}", statementStr); Console.WriteLine("bindVars: [{0}]", string.Join(",", bindVars)); Assert.AreEqual("A0", mediaItemIdAlias, "Media item ID alias"); Assert.AreEqual(CreateMIAMAliases(mia1.Metadata, "A1", mia2.Metadata, "A2"), miamAliases, "MIAM aliases"); Assert.AreEqual(new Dictionary <QueryAttribute, string>(), attributeAliases, "Attribute aliases"); Assert.AreEqual("SELECT T0.MEDIA_ITEM_ID A0, T0.MEDIA_ITEM_ID A1, T1.MEDIA_ITEM_ID A2 FROM M_META1 T0 INNER JOIN M_META2 T1 ON T1.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID " + " WHERE T0.MEDIA_ITEM_ID IN(SELECT R1.MEDIA_ITEM_ID FROM M_RELATIONSHIP R1 WHERE R1.ROLE=@V0 AND R1.LINKEDROLE=@V1 AND R1.LINKEDID IN( " + "SELECT TS.A0 FROM (SELECT T0.MEDIA_ITEM_ID A0, T1.MEDIA_ITEM_ID A1 FROM MEDIA_ITEMS T0 LEFT OUTER JOIN M_META3 T1 ON T0.MEDIA_ITEM_ID = T1.MEDIA_ITEM_ID " + " WHERE (T1.ATTR_INTEGER = @V2 AND T1.ATTR_STRING = @V3)) TS) " + "UNION SELECT R1.LINKEDID FROM M_RELATIONSHIP R1 WHERE R1.LINKEDROLE=@V0 AND R1.ROLE=@V1 AND R1.MEDIA_ITEM_ID IN( SELECT TS.A0 FROM (" + "SELECT T0.MEDIA_ITEM_ID A0, T1.MEDIA_ITEM_ID A1 FROM MEDIA_ITEMS T0 LEFT OUTER JOIN M_META3 T1 ON T0.MEDIA_ITEM_ID = T1.MEDIA_ITEM_ID " + " WHERE (T1.ATTR_INTEGER = @V2 AND T1.ATTR_STRING = @V3)) TS))", statementStr, "Statement"); Assert.AreEqual(new List <BindVar> { new BindVar("V0", actorType, typeof(Guid)), new BindVar("V1", movieType, typeof(Guid)), new BindVar("V2", 1, typeof(int)), new BindVar("V3", "test", typeof(string)) }, bindVars, "Bind vars"); }
public void TestRelationshipQueryBuilder() { // Use the real RelationshipFilter because CompiledFilter is hard coded to look for it MockCore.AddMediaItemAspectStorage(RelationshipAspect.Metadata); SingleTestMIA mia1 = TestBackendUtils.CreateSingleMIA("Meta1", Cardinality.Inline, true, true); SingleTestMIA mia2 = TestBackendUtils.CreateSingleMIA("Meta2", Cardinality.Inline, true, true); ICollection <MediaItemAspectMetadata> requiredMIATypes = new List <MediaItemAspectMetadata>(); requiredMIATypes.Add(mia1.Metadata); requiredMIATypes.Add(mia2.Metadata); Guid movieId = new Guid("aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa"); Guid movieType = new Guid("bbbbbbbb-2222-2222-2222-bbbbbbbbbbbb"); Guid actorType = new Guid("cccccccc-3333-3333-3333-cccccccccccc"); IFilter filter = new RelationshipFilter(actorType, movieType, movieId); MIAQueryBuilder builder = new MIAQueryBuilder(MockCore.Management, new List <QueryAttribute>(), null, requiredMIATypes, new List <MediaItemAspectMetadata>(), filter, null); string mediaItemIdAlias = null; IDictionary <MediaItemAspectMetadata, string> miamAliases = null; IDictionary <QueryAttribute, string> attributeAliases = null; string statementStr = null; IList <BindVar> bindVars = null; builder.GenerateSqlStatement(out mediaItemIdAlias, out miamAliases, out attributeAliases, out statementStr, out bindVars); Console.WriteLine("mediaItemIdAlias: {0}", mediaItemIdAlias); Console.WriteLine("miamAliases: [{0}]", string.Join(",", miamAliases)); Console.WriteLine("attributeAliases: [{0}]", string.Join(",", attributeAliases)); Console.WriteLine("statementStr: {0}", statementStr); Console.WriteLine("bindVars: [{0}]", string.Join(",", bindVars)); Assert.AreEqual("A0", mediaItemIdAlias, "Media item ID alias"); Assert.AreEqual(CreateMIAMAliases(mia1.Metadata, "A1", mia2.Metadata, "A2"), miamAliases, "MIAM aliases"); Assert.AreEqual(new Dictionary <QueryAttribute, string>(), attributeAliases, "Attribute aliases"); Assert.AreEqual("SELECT T0.MEDIA_ITEM_ID A0, T0.MEDIA_ITEM_ID A1, T1.MEDIA_ITEM_ID A2 FROM M_META1 T0 INNER JOIN M_META2 T1 ON T1.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID " + " WHERE T0.MEDIA_ITEM_ID IN(SELECT R1.MEDIA_ITEM_ID FROM M_RELATIONSHIP R1 WHERE R1.LINKEDID=@V0 AND R1.ROLE=@V1 AND R1.LINKEDROLE=@V2 UNION SELECT R2.LINKEDID " + "FROM M_RELATIONSHIP R2 WHERE R2.MEDIA_ITEM_ID=@V0 AND R2.LINKEDROLE=@V1 AND R2.ROLE=@V2)", statementStr, "Statement"); Assert.AreEqual(new List <BindVar> { new BindVar("V0", movieId, typeof(Guid)), new BindVar("V1", actorType, typeof(Guid)), new BindVar("V2", movieType, typeof(Guid)) }, bindVars, "Bind vars"); }
public void TestAndQueryBuilder() { SingleTestMIA mia1 = TestBackendUtils.CreateSingleMIA("Meta1", Cardinality.Inline, true, true); SingleTestMIA mia2 = TestBackendUtils.CreateSingleMIA("Meta2", Cardinality.Inline, true, true); IList <IFilter> filters = new List <IFilter>(); filters.Add(new LikeFilter(mia1.ATTR_STRING, "%", null)); filters.Add(new LikeFilter(mia2.ATTR_STRING, "%", null)); IFilter filter = new BooleanCombinationFilter(BooleanOperator.And, filters); ICollection <MediaItemAspectMetadata> requiredMIATypes = new List <MediaItemAspectMetadata>(); requiredMIATypes.Add(mia1.Metadata); requiredMIATypes.Add(mia2.Metadata); MIAQueryBuilder builder = new MIAQueryBuilder(MockCore.Management, new List <QueryAttribute>(), null, requiredMIATypes, new List <MediaItemAspectMetadata>(), filter, null, null); string mediaItemIdAlias = null; IDictionary <MediaItemAspectMetadata, string> miamAliases = null; IDictionary <QueryAttribute, string> attributeAliases = null; string statementStr = null; IList <BindVar> bindVars = null; builder.GenerateSqlStatement(out mediaItemIdAlias, out miamAliases, out attributeAliases, out statementStr, out bindVars); //Console.WriteLine("mediaItemIdAlias: {0}", mediaItemIdAlias); //Console.WriteLine("miamAliases: [{0}]", string.Join(",", miamAliases)); //Console.WriteLine("attributeAliases: [{0}]", string.Join(",", attributeAliases)); //Console.WriteLine("statementStr: {0}", statementStr); //Console.WriteLine("bindVars: [{0}]", string.Join(",", bindVars)); Assert.AreEqual("A0", mediaItemIdAlias, "Media item ID alias"); Assert.AreEqual(CreateMIAMAliases(mia1.Metadata, "A1", mia2.Metadata, "A2"), miamAliases, "MIAM aliases"); Assert.AreEqual(new string[] { }, attributeAliases, "Attribute aliases"); Assert.AreEqual("SELECT T0.MEDIA_ITEM_ID A0, T0.MEDIA_ITEM_ID A1, T1.MEDIA_ITEM_ID A2 FROM M_META1 T0 INNER JOIN M_META2 T1 ON T1.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID " + "WHERE (T0.ATTR_STRING LIKE @V0 AND T1.ATTR_STRING LIKE @V1)", statementStr, "Statement"); Assert.AreEqual(new List <BindVar> { new BindVar("V0", "%", typeof(string)), new BindVar("V1", "%", typeof(string)) }, bindVars, "Bind vars"); }
public void TestExternalQueryBuilder() { SingleTestMIA mia1 = TestBackendUtils.CreateSingleMIA("Meta1", Cardinality.Inline, true, true); SingleTestMIA mia2 = TestBackendUtils.CreateSingleMIA("Meta2", Cardinality.Inline, true, true); MockCore.AddMediaItemAspectStorage(ExternalIdentifierAspect.Metadata); string source = "test"; string type = "series"; string id = "123"; // Search using external identifiers BooleanCombinationFilter filter = new BooleanCombinationFilter(BooleanOperator.And, new[] { new RelationalFilter(ExternalIdentifierAspect.ATTR_SOURCE, RelationalOperator.EQ, source), new RelationalFilter(ExternalIdentifierAspect.ATTR_TYPE, RelationalOperator.EQ, type), new RelationalFilter(ExternalIdentifierAspect.ATTR_ID, RelationalOperator.EQ, id), }); ICollection <MediaItemAspectMetadata> requiredMIATypes = new List <MediaItemAspectMetadata>(); requiredMIATypes.Add(mia1.Metadata); requiredMIATypes.Add(mia2.Metadata); MIAQueryBuilder builder = new MIAQueryBuilder(MockCore.Management, new List <QueryAttribute>(), null, requiredMIATypes, new List <MediaItemAspectMetadata>(), filter, null, null); string mediaItemIdAlias = null; IDictionary <MediaItemAspectMetadata, string> miamAliases = null; IDictionary <QueryAttribute, string> attributeAliases = null; string statementStr = null; IList <BindVar> bindVars = null; builder.GenerateSqlStatement(out mediaItemIdAlias, out miamAliases, out attributeAliases, out statementStr, out bindVars); Console.WriteLine("mediaItemIdAlias: {0}", mediaItemIdAlias); Console.WriteLine("miamAliases: [{0}]", string.Join(",", miamAliases)); Console.WriteLine("attributeAliases: [{0}]", string.Join(",", attributeAliases)); Console.WriteLine("statementStr: {0}", statementStr); Console.WriteLine("bindVars: [{0}]", string.Join(",", bindVars)); }
public void TestMediaItemLoader_SingleMIAs_LikeFilter() { MockDBUtils.Reset(); SingleTestMIA mia1 = TestBackendUtils.CreateSingleMIA("SINGLE1", Cardinality.Inline, true, false); SingleTestMIA mia2 = TestBackendUtils.CreateSingleMIA("SINGLE2", Cardinality.Inline, false, true); SingleTestMIA mia3 = TestBackendUtils.CreateSingleMIA("SINGLE3", Cardinality.Inline, true, true); Guid itemId = new Guid("aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa"); IFilter filter = new LikeFilter(mia1.ATTR_STRING, "%", null); MockReader reader = MockDBUtils.AddReader( "SELECT T0.MEDIA_ITEM_ID A4, T0.MEDIA_ITEM_ID A5, T1.MEDIA_ITEM_ID A6, T2.MEDIA_ITEM_ID A7, T0.ATTR_STRING A0, T1.ATTR_INTEGER A1, T2.ATTR_STRING A2, T2.ATTR_INTEGER A3 " + "FROM M_SINGLE1 T0 INNER JOIN M_SINGLE2 T1 ON T1.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID LEFT OUTER JOIN M_SINGLE3 T2 ON T2.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID " + " WHERE T0.ATTR_STRING LIKE @V0", "A4", "A5", "A6", "A7", "A0", "A1", "A2", "A3"); reader.AddResult(itemId, itemId, itemId, itemId, "zerozero", 11, "twotwo", 33); Guid[] requiredAspects = new Guid[] { mia1.ASPECT_ID, mia2.ASPECT_ID }; Guid[] optionalAspects = new Guid[] { mia3.ASPECT_ID }; MediaItemQuery query = new MediaItemQuery(requiredAspects, optionalAspects, filter); CompiledMediaItemQuery compiledQuery = CompiledMediaItemQuery.Compile(MockCore.Management, query); MediaItem result = compiledQuery.QueryMediaItem(); //Console.WriteLine("Query result " + result.MediaItemId + ": " + string.Join(",", result.Aspects) + ": " + result); Assert.AreEqual(itemId, result.MediaItemId, "MediaItem ID"); SingleMediaItemAspect value = null; Assert.IsTrue(MediaItemAspect.TryGetAspect(result.Aspects, mia1.Metadata, out value), "MIA1"); Assert.AreEqual("zerozero", value.GetAttributeValue(mia1.ATTR_STRING), "MIA1 string attibute"); Assert.IsTrue(MediaItemAspect.TryGetAspect(result.Aspects, mia2.Metadata, out value), "MIA2"); Assert.AreEqual(11, value.GetAttributeValue(mia2.ATTR_INTEGER), "MIA2 integer attibute"); Assert.IsTrue(MediaItemAspect.TryGetAspect(result.Aspects, mia3.Metadata, out value), "MIA3"); Assert.AreEqual("twotwo", value.GetAttributeValue(mia3.ATTR_STRING), "MIA3 string attibute"); Assert.AreEqual(33, value.GetAttributeValue(mia3.ATTR_INTEGER), "MIA3 integer attibute"); }
public void TestMediaItemAspectStorage() { TestBackendUtils.CreateSingleMIA("SINGLE", Cardinality.Inline, true, true); MockCommand singleCommand = MockDBUtils.FindCommand("CREATE TABLE M_SINGLE"); Assert.IsNotNull(singleCommand, "Single create table command"); // Columns and objects will be what we asked for Assert.AreEqual("CREATE TABLE M_SINGLE (MEDIA_ITEM_ID Guid, ATTR_STRING TEXT, ATTR_INTEGER Int32, CONSTRAINT M_SINGLE_PK PRIMARY KEY (MEDIA_ITEM_ID), CONSTRAINT FK FOREIGN KEY (MEDIA_ITEM_ID) REFERENCES MEDIA_ITEMS (MEDIA_ITEM_ID) ON DELETE CASCADE)", singleCommand.CommandText, "Single1 create table command"); MockDBUtils.Reset(); TestBackendUtils.CreateMultipleMIA("MULTIPLE", Cardinality.Inline, true, false); MockCommand multipleCommand = MockDBUtils.FindCommand("CREATE TABLE M_MULTIPLE"); Assert.IsNotNull(multipleCommand, "Multiple create table command"); // Columns and objects will be suffixed with _0 because the alises we asked for have already been given to Multiple1 Assert.AreEqual("CREATE TABLE M_MULTIPLE (MEDIA_ITEM_ID Guid, ATTR_ID TEXT, ATTR_STRING TEXT, CONSTRAINT M_MULTIPLE_PK PRIMARY KEY (MEDIA_ITEM_ID,ATTR_ID), CONSTRAINT FK FOREIGN KEY (MEDIA_ITEM_ID) REFERENCES MEDIA_ITEMS (MEDIA_ITEM_ID) ON DELETE CASCADE)", multipleCommand.CommandText, "Multiple1 create table command"); MockDBUtils.Reset(); TestBackendUtils.CreateMultipleMIA("META3", Cardinality.OneToMany, true, true); MockCommand meta3Command = MockDBUtils.FindCommand("CREATE TABLE M_META3"); Assert.IsNotNull(meta3Command, "Meta3 create table command"); Assert.AreEqual("CREATE TABLE M_META3 (MEDIA_ITEM_ID Guid, ATTR_ID TEXT, CONSTRAINT M_META3_PK PRIMARY KEY (MEDIA_ITEM_ID,ATTR_ID), CONSTRAINT FK FOREIGN KEY (MEDIA_ITEM_ID) REFERENCES MEDIA_ITEMS (MEDIA_ITEM_ID) ON DELETE CASCADE)", meta3Command.CommandText, "Meta3 create table command"); }
public void TestMediaItemLoader_SingleMIAsUnusedOptional_IdFilter() { MockDBUtils.Reset(); SingleTestMIA single1 = TestBackendUtils.CreateSingleMIA("SINGLE1", Cardinality.Inline, true, false); SingleTestMIA single2 = TestBackendUtils.CreateSingleMIA("SINGLE2", Cardinality.Inline, false, true); SingleTestMIA single3 = TestBackendUtils.CreateSingleMIA("SINGLE3", Cardinality.Inline, false, true); SingleTestMIA single4 = TestBackendUtils.CreateSingleMIA("SINGLE4", Cardinality.Inline, false, true); Guid itemId = new Guid("aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa"); IList <Guid> ids = new List <Guid>(); ids.Add(itemId); IFilter filter = new MediaItemIdFilter(ids); MockReader reader = MockDBUtils.AddReader( "SELECT T0.MEDIA_ITEM_ID A4, T0.MEDIA_ITEM_ID A5, T1.MEDIA_ITEM_ID A6, T2.MEDIA_ITEM_ID A7, T3.MEDIA_ITEM_ID A8, T0.ATTR_STRING A0, T1.ATTR_INTEGER A1, T2.ATTR_INTEGER A2, " + "T3.ATTR_INTEGER A3 FROM M_SINGLE1 T0 INNER JOIN M_SINGLE2 T1 ON T1.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID LEFT OUTER JOIN M_SINGLE3 T2 ON T2.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID " + "LEFT OUTER JOIN M_SINGLE4 T3 ON T3.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID WHERE T0.MEDIA_ITEM_ID = @V0", "A4", "A5", "A6", "A7", "A8", "A0", "A1", "A2", "A3"); reader.AddResult(itemId, itemId, itemId, itemId, null, "zero", 0, 0, null); Guid[] requiredAspects = new Guid[] { single1.ASPECT_ID, single2.ASPECT_ID }; Guid[] optionalAspects = new Guid[] { single3.ASPECT_ID, single4.ASPECT_ID }; MediaItemQuery query = new MediaItemQuery(requiredAspects, optionalAspects, filter); CompiledMediaItemQuery compiledQuery = CompiledMediaItemQuery.Compile(MockCore.Management, query); MediaItem result = compiledQuery.QueryMediaItem(); Assert.AreEqual(itemId, result.MediaItemId, "MediaItem ID"); SingleMediaItemAspect value = null; Assert.IsTrue(MediaItemAspect.TryGetAspect(result.Aspects, single1.Metadata, out value), "MIA1"); Assert.IsTrue(MediaItemAspect.TryGetAspect(result.Aspects, single2.Metadata, out value), "MIA2"); Assert.IsTrue(MediaItemAspect.TryGetAspect(result.Aspects, single3.Metadata, out value), "MIA3"); Assert.IsFalse(MediaItemAspect.TryGetAspect(result.Aspects, single4.Metadata, out value), "MIA4"); }
public void TestMediaItemsLoader_SingleAndMultipleMIAs_BooleanLikeFilter() { MockDBUtils.Reset(); SingleTestMIA mia1 = TestBackendUtils.CreateSingleMIA("SINGLE1", Cardinality.Inline, true, true); MultipleTestMIA mia2 = TestBackendUtils.CreateMultipleMIA("MULTIPLE2", Cardinality.Inline, true, false); MultipleTestMIA mia3 = TestBackendUtils.CreateMultipleMIA("MULTIPLE3", Cardinality.Inline, false, true); Guid itemId0 = new Guid("aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa"); Guid itemId1 = new Guid("bbbbbbbb-2222-2222-2222-bbbbbbbbbbbb"); IFilter filter = new BooleanCombinationFilter(BooleanOperator.And, new List <IFilter> { new LikeFilter(mia1.ATTR_STRING, "%", null), new LikeFilter(mia2.ATTR_STRING, "%", null) }); MockReader reader = MockDBUtils.AddReader(1, "SELECT T0.MEDIA_ITEM_ID A2, T0.MEDIA_ITEM_ID A3, T1.MEDIA_ITEM_ID A4, T0.ATTR_STRING A0, T0.ATTR_INTEGER A1 " + "FROM M_SINGLE1 T0 INNER JOIN M_MULTIPLE2 T1 ON T1.MEDIA_ITEM_ID = T0.MEDIA_ITEM_ID " + " WHERE T0.MEDIA_ITEM_ID IN(SELECT MEDIA_ITEM_ID FROM M_MULTIPLE2 WHERE ATTR_STRING LIKE @V0) AND T0.ATTR_STRING LIKE @V1", "A2", "A3", "A4", "A0", "A1"); reader.AddResult(itemId0, itemId0, itemId0, "zero", 0, "0_0"); reader.AddResult(itemId1, itemId1, itemId1, "one", 1, "1_1"); MockReader multipleReader2 = MockDBUtils.AddReader(2, "SELECT T0.MEDIA_ITEM_ID A2, T0.MEDIA_ITEM_ID A3, T0.ATTR_ID A0, T0.ATTR_STRING A1 FROM M_MULTIPLE2 T0 WHERE T0.MEDIA_ITEM_ID IN (@V0, @V1)", "A2", "A3", "A0", "A1"); multipleReader2.AddResult(itemId0, itemId0, "0_0", "zerozero"); multipleReader2.AddResult(itemId0, itemId0, "0_1", "zeroone"); multipleReader2.AddResult(itemId1, itemId1, "1_0", "onezero"); MockReader multipleReader3 = MockDBUtils.AddReader(3, "SELECT T0.MEDIA_ITEM_ID A2, T0.MEDIA_ITEM_ID A3, T0.ATTR_ID A0, T0.ATTR_INTEGER A1 FROM M_MULTIPLE3 T0 WHERE T0.MEDIA_ITEM_ID IN (@V0, @V1)", "A2", "A3", "A0", "A1"); multipleReader3.AddResult(itemId0, itemId0, "1_0", 10); multipleReader3.AddResult(itemId0, itemId0, "1_1", 11); multipleReader3.AddResult(itemId0, itemId0, "1_2", 12); multipleReader3.AddResult(itemId0, itemId0, "1_3", 13); multipleReader3.AddResult(itemId0, itemId0, "1_4", 14); multipleReader3.AddResult(itemId1, itemId1, "1_0", 20); Guid[] requiredAspects = { mia1.ASPECT_ID, mia2.ASPECT_ID }; Guid[] optionalAspects = { mia3.ASPECT_ID }; MediaItemQuery query = new MediaItemQuery(requiredAspects, optionalAspects, filter); CompiledMediaItemQuery compiledQuery = CompiledMediaItemQuery.Compile(MockCore.Management, query); IList <MediaItem> results = compiledQuery.QueryList(); /* * foreach (MediaItem result in results) * //Console.WriteLine("Query result " + result.MediaItemId + ": " + string.Join(",", result.Aspects.Values) + ": " + result); */ SingleMediaItemAspect value; IList <MultipleMediaItemAspect> values; Assert.AreEqual(2, results.Count, "Results count"); Assert.AreEqual(itemId0, results[0].MediaItemId, "MediaItem ID #0"); Assert.IsTrue(MediaItemAspect.TryGetAspect(results[0].Aspects, mia1.Metadata, out value), "MIA1 #0"); Assert.AreEqual("zero", value.GetAttributeValue(mia1.ATTR_STRING), "MIA1 string attibute #0"); Assert.AreEqual(0, value.GetAttributeValue(mia1.ATTR_INTEGER), "MIA1 integer attibute #0"); Assert.IsTrue(MediaItemAspect.TryGetAspects(results[0].Aspects, mia2.Metadata, out values), "MIA2 #0"); Assert.AreEqual(2, values.Count, "MIA2 count #0"); Assert.AreEqual("zerozero", values[0].GetAttributeValue(mia2.ATTR_STRING), "MIA2 string attibute 0 #0"); Assert.AreEqual("zeroone", values[1].GetAttributeValue(mia2.ATTR_STRING), "MIA2 string attibute 1 #0"); Assert.IsTrue(MediaItemAspect.TryGetAspects(results[0].Aspects, mia3.Metadata, out values), "MIA3 #0"); Assert.AreEqual(5, values.Count, "MIA3 count #0"); Assert.AreEqual(10, values[0].GetAttributeValue(mia3.ATTR_INTEGER), "MIA3 integer attibute 0 #0"); Assert.AreEqual(11, values[1].GetAttributeValue(mia3.ATTR_INTEGER), "MIA3 integer attibute 1 #0"); Assert.AreEqual(12, values[2].GetAttributeValue(mia3.ATTR_INTEGER), "MIA3 integer attibute 2 #0"); Assert.AreEqual(13, values[3].GetAttributeValue(mia3.ATTR_INTEGER), "MIA3 integer attibute 3 #0"); Assert.AreEqual(14, values[4].GetAttributeValue(mia3.ATTR_INTEGER), "MIA3 integer attibute 4 #0"); Assert.AreEqual(itemId1, results[1].MediaItemId, "MediaItem ID #1"); Assert.IsTrue(MediaItemAspect.TryGetAspect(results[1].Aspects, mia1.Metadata, out value), "MIA1 #0"); Assert.AreEqual("one", value.GetAttributeValue(mia1.ATTR_STRING), "MIA1 string attibute #1"); Assert.AreEqual(1, value.GetAttributeValue(mia1.ATTR_INTEGER), "MIA1 integer attibute #1"); Assert.IsTrue(MediaItemAspect.TryGetAspects(results[1].Aspects, mia2.Metadata, out values), "MIA2 #1"); Assert.AreEqual(1, values.Count, "MIA2 count #1"); Assert.AreEqual("onezero", values[0].GetAttributeValue(mia2.ATTR_STRING), "MIA2 string attibute 0 #1"); Assert.IsTrue(MediaItemAspect.TryGetAspects(results[1].Aspects, mia3.Metadata, out values), "MIA3 #0"); Assert.AreEqual(1, values.Count, "MIA3 count #1"); Assert.AreEqual(20, values[0].GetAttributeValue(mia3.ATTR_INTEGER), "MIA3 integer attibute 0 #1"); }