public void Multiple_Providers_Preserve_Order() { long createCountBefore = Interlocked.Read(ref MockSourceFileProviderFactory.createCount); // This func returns a file name only for the StringValue property Func<MemberInfo, string> func1 = m => { return m.Name == "StringValue" ? m.Name : null; }; // The second func returns "IntValue" but also a contradictory name XXX for StringValue. // We are testing the preservation of order here in that only one service is allowed to // declare a file for a single MemberInfo, and the first one wins Func<MemberInfo, string> func2 = m => { return m.Name == "IntValue" ? m.Name : m.Name == "StringValue" ? "XXX" : null; }; MockSourceFileProviderFactory factory1 = new MockSourceFileProviderFactory(func1); MockSourceFileProviderFactory factory2 = new MockSourceFileProviderFactory(func2); FilenameMap filenameMap = new FilenameMap(); using (SourceFileLocationService locationService = new SourceFileLocationService(new[] { factory1, factory2 }, filenameMap)) { IEnumerable<string> files = locationService.GetFilesForType(typeof(SourceFileLocationServiceTest)); Assert.AreEqual(2, files.Count(), "Expected both service to contribute to files"); Assert.IsTrue(files.Contains("StringValue"), "The first service should have gotten called"); Assert.IsTrue(files.Contains("IntValue"), "The second service should have gotten called"); Assert.IsFalse(files.Contains("XXX"), "The 2nd response to StringValue should be discarded"); } long createCountAfter = Interlocked.Read(ref MockSourceFileProviderFactory.createCount); Assert.AreEqual(createCountBefore, createCountAfter, "Imbalanced create/dispose count of ISourceFileProviders"); }
public void Multiple_Providers_Preserve_Order() { long createCountBefore = Interlocked.Read(ref MockSourceFileProviderFactory.createCount); // This func returns a file name only for the StringValue property Func <MemberInfo, string> func1 = m => { return(m.Name == "StringValue" ? m.Name : null); }; // The second func returns "IntValue" but also a contradictory name XXX for StringValue. // We are testing the preservation of order here in that only one service is allowed to // declare a file for a single MemberInfo, and the first one wins Func <MemberInfo, string> func2 = m => { return(m.Name == "IntValue" ? m.Name : m.Name == "StringValue" ? "XXX" : null); }; MockSourceFileProviderFactory factory1 = new MockSourceFileProviderFactory(func1); MockSourceFileProviderFactory factory2 = new MockSourceFileProviderFactory(func2); FilenameMap filenameMap = new FilenameMap(); using (SourceFileLocationService locationService = new SourceFileLocationService(new[] { factory1, factory2 }, filenameMap)) { IEnumerable <string> files = locationService.GetFilesForType(typeof(SourceFileLocationServiceTest)); Assert.AreEqual(2, files.Count(), "Expected both service to contribute to files"); Assert.IsTrue(files.Contains("StringValue"), "The first service should have gotten called"); Assert.IsTrue(files.Contains("IntValue"), "The second service should have gotten called"); Assert.IsFalse(files.Contains("XXX"), "The 2nd response to StringValue should be discarded"); } long createCountAfter = Interlocked.Read(ref MockSourceFileProviderFactory.createCount); Assert.AreEqual(createCountBefore, createCountAfter, "Imbalanced create/dispose count of ISourceFileProviders"); }