зеркало из https://github.com/github/VisualStudio.git
Ensure SharedDictionarManager doesn't return null
Clean up unit tests and make sure they all pass with NCrunch.
This commit is contained in:
Родитель
760928d934
Коммит
c4e6f9aaf0
|
@ -0,0 +1,6 @@
|
|||
<ProjectConfiguration>
|
||||
<Settings>
|
||||
<CopyReferencedAssembliesToWorkspace>True</CopyReferencedAssembliesToWorkspace>
|
||||
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
|
||||
</Settings>
|
||||
</ProjectConfiguration>
|
|
@ -8,6 +8,7 @@ namespace GitHub.Helpers
|
|||
{
|
||||
static IDictionary<Uri, ResourceDictionary> sharedDictionaries;
|
||||
static IList<IDisposable> disposables;
|
||||
Uri source;
|
||||
|
||||
static SharedDictionaryManagerBase()
|
||||
{
|
||||
|
@ -18,9 +19,11 @@ namespace GitHub.Helpers
|
|||
|
||||
public virtual new Uri Source
|
||||
{
|
||||
get { return base.Source; }
|
||||
get { return source; }
|
||||
set
|
||||
{
|
||||
source = value;
|
||||
|
||||
value = FixDesignTimeUri(value);
|
||||
var rd = GetResourceDictionary(value);
|
||||
MergedDictionaries.Clear();
|
||||
|
|
|
@ -59,6 +59,10 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\GitHub.Exports\GitHub.Exports.csproj">
|
||||
<Project>{9aea02db-02b5-409c-b0ca-115d05331a6b}</Project>
|
||||
<Name>GitHub.Exports</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\GitHub.UI\GitHub.UI.csproj">
|
||||
<Project>{346384dd-2445-4a28-af22-b45f3957bd89}</Project>
|
||||
<Name>GitHub.UI</Name>
|
||||
|
|
|
@ -30,18 +30,12 @@ namespace GitHub.UI.UnitTests
|
|||
if (source != null)
|
||||
{
|
||||
writer.WriteLine(indent + source + " (" + rd.GetType().FullName + ") # " + rd.GetHashCode());
|
||||
foreach (var child in rd.MergedDictionaries)
|
||||
{
|
||||
DumpResourceDictionary(writer, child, indent + " ");
|
||||
}
|
||||
indent += " ";
|
||||
}
|
||||
else
|
||||
|
||||
foreach (var child in rd.MergedDictionaries)
|
||||
{
|
||||
// ignore our empty nodes
|
||||
foreach (var child in rd.MergedDictionaries)
|
||||
{
|
||||
DumpResourceDictionary(writer, child, indent);
|
||||
}
|
||||
DumpResourceDictionary(writer, child, indent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,38 @@
|
|||
using GitHub.Helpers;
|
||||
using System;
|
||||
using GitHub.Helpers;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GitHub.UI.UnitTests
|
||||
{
|
||||
public class SharedDictionaryManagerBaseTests
|
||||
{
|
||||
[TestCase("pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml", "pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml")]
|
||||
[TestCase("file:///x:/solution/src/GitHub.VisualStudio.UI/SharedDictionary.xaml", "pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml")]
|
||||
[TestCase("file:///x:/solution/src/GitHub.VisualStudio.UI/Styles/GitHubComboBox.xaml", "pack://application:,,,/GitHub.VisualStudio.UI;component/Styles/GitHubComboBox.xaml")]
|
||||
public void FixDesignTimeUri(string inUrl, string outUrl)
|
||||
public class TheFixDesignTimeUriMethod
|
||||
{
|
||||
var inUri = ResourceDictionaryUtilities.ToPackUri(inUrl);
|
||||
[TestCase("pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml", "pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml")]
|
||||
[TestCase("file:///x:/solution/src/GitHub.VisualStudio.UI/SharedDictionary.xaml", "pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml")]
|
||||
[TestCase("file:///x:/solution/src/GitHub.VisualStudio.UI/Styles/GitHubComboBox.xaml", "pack://application:,,,/GitHub.VisualStudio.UI;component/Styles/GitHubComboBox.xaml")]
|
||||
public void FixDesignTimeUri(string inUrl, string outUrl)
|
||||
{
|
||||
var inUri = ResourceDictionaryUtilities.ToPackUri(inUrl);
|
||||
|
||||
var outUri = SharedDictionaryManagerBase.FixDesignTimeUri(inUri);
|
||||
var outUri = SharedDictionaryManagerBase.FixDesignTimeUri(inUri);
|
||||
|
||||
Assert.That(outUri.ToString(), Is.EqualTo(outUrl));
|
||||
Assert.That(outUri.ToString(), Is.EqualTo(outUrl));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheSourceProperty
|
||||
{
|
||||
[TestCase("pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml")]
|
||||
public void IsEqualToSet(string url)
|
||||
{
|
||||
var uri = ResourceDictionaryUtilities.ToPackUri(url);
|
||||
var target = new SharedDictionaryManagerBase();
|
||||
|
||||
target.Source = uri;
|
||||
|
||||
Assert.That(target.Source, Is.EqualTo(uri));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,15 @@ namespace GitHub.UI.UnitTests
|
|||
[TestCase("file:///x:/Project/src/GitHub.UI/SharedDictionary.xaml", Description = "This is a design time URL")]
|
||||
[TestCase("file:///x:/Project/src/GitHub.VisualStudio.UI/SharedDictionary.xaml", Description = "This is a design time URL")]
|
||||
[RequiresThread(System.Threading.ApartmentState.STA)]
|
||||
public void SetSourceOnDifferentInstances_ExpectTheSameObjects(params string[] urls)
|
||||
public void SetSourceOnDifferentInstances_ExpectTheSameObjects(string url)
|
||||
{
|
||||
var setup = new AppDomainSetup { ApplicationBase = "NOTHING_HERE" };
|
||||
using (var context = new AppDomainContext(setup))
|
||||
{
|
||||
var remote = context.CreateInstance<SharedDictionaryManagerContext>();
|
||||
string expectDump = remote.DumpMergedDictionariesSharedDictionaryManager(urls);
|
||||
string expectDump = remote.DumpMergedDictionariesSharedDictionaryManager(url);
|
||||
|
||||
var dump = remote.DumpMergedDictionariesSharedDictionaryManager(urls);
|
||||
var dump = remote.DumpMergedDictionariesSharedDictionaryManager(url);
|
||||
|
||||
Assert.That(dump, Is.EqualTo(expectDump));
|
||||
}
|
||||
|
@ -32,15 +32,15 @@ namespace GitHub.UI.UnitTests
|
|||
[TestCase("pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml")]
|
||||
[TestCase("pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml")]
|
||||
[RequiresThread(System.Threading.ApartmentState.STA)]
|
||||
public void SetResourceDictionarySourceOnDifferentInstances_ExpectDifferentObjects(params string[] urls)
|
||||
public void SetResourceDictionarySourceOnDifferentInstances_ExpectDifferentObjects(string url)
|
||||
{
|
||||
var setup = new AppDomainSetup { ApplicationBase = "NOTHING_HERE" };
|
||||
using (var context = new AppDomainContext(setup))
|
||||
{
|
||||
var remote = context.CreateInstance<SharedDictionaryManagerContext>();
|
||||
string expectDump = remote.DumpMergedDictionariesLoadingResourceDictionary(urls);
|
||||
string expectDump = remote.DumpMergedDictionariesLoadingResourceDictionary(url);
|
||||
|
||||
var dump = remote.DumpMergedDictionariesLoadingResourceDictionary(urls);
|
||||
var dump = remote.DumpMergedDictionariesLoadingResourceDictionary(url);
|
||||
|
||||
Assert.That(dump, Is.Not.EqualTo(expectDump));
|
||||
}
|
||||
|
@ -48,24 +48,21 @@ namespace GitHub.UI.UnitTests
|
|||
|
||||
class SharedDictionaryManagerContext : MarshalByRefObject
|
||||
{
|
||||
internal string DumpMergedDictionariesLoadingResourceDictionary(params string[] urls)
|
||||
internal string DumpMergedDictionariesLoadingResourceDictionary(string url)
|
||||
{
|
||||
var target = new LoadingResourceDictionary();
|
||||
return DumpMergedDictionaries(target, urls);
|
||||
return DumpMergedDictionaries(target, url);
|
||||
}
|
||||
|
||||
internal string DumpMergedDictionariesSharedDictionaryManager(params string[] urls)
|
||||
internal string DumpMergedDictionariesSharedDictionaryManager(string url)
|
||||
{
|
||||
var target = new SharedDictionaryManager();
|
||||
return DumpMergedDictionaries(target, urls);
|
||||
return DumpMergedDictionaries(target, url);
|
||||
}
|
||||
|
||||
string DumpMergedDictionaries(ResourceDictionary target, params string[] urls)
|
||||
string DumpMergedDictionaries(ResourceDictionary target, string url)
|
||||
{
|
||||
foreach(var url in urls)
|
||||
{
|
||||
SetProperty(target, "Source", ResourceDictionaryUtilities.ToPackUri(url));
|
||||
}
|
||||
SetProperty(target, "Source", ResourceDictionaryUtilities.ToPackUri(url));
|
||||
|
||||
return ResourceDictionaryUtilities.DumpResourceDictionary(target);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче