Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 72734da

Browse files
committed
Add tests for LoadingResourceDictionary
Show when ResourceDictionary doesn't work and when LoadingResourceDictionary does.
1 parent 25304b7 commit 72734da

File tree

5 files changed

+287
-0
lines changed

5 files changed

+287
-0
lines changed

GitHubVS.sln

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.VisualStudio.UI", "s
104104
EndProject
105105
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.StartPage", "src\GitHub.StartPage\GitHub.StartPage.csproj", "{50E277B8-8580-487A-8F8E-5C3B9FBF0F77}"
106106
EndProject
107+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHubVSAutomationIDs", "GitHubVSAutomationIDs", "{4405C20E-A72A-4807-9480-14E9BB558347}"
108+
EndProject
109+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GithubVSTestAutomationIDs", "submodules\GitHubVSAutomationIDs\GithubVSAutomationIDs\GithubVSTestAutomationIDs.csproj", "{9453C37F-44CF-463D-B563-5C3110CEF5E7}"
110+
EndProject
111+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.UI.UnitTests", "test\GitHub.UI.UnitTests\GitHub.UI.UnitTests.csproj", "{110B206F-8554-4B51-BF86-94DAA32F5E26}"
112+
EndProject
107113
Global
108114
GlobalSection(SolutionConfigurationPlatforms) = preSolution
109115
Debug|Any CPU = Debug|Any CPU
@@ -542,6 +548,38 @@ Global
542548
{50E277B8-8580-487A-8F8E-5C3B9FBF0F77}.XamlDesign|Any CPU.Build.0 = Release|Any CPU
543549
{50E277B8-8580-487A-8F8E-5C3B9FBF0F77}.XamlDesign|x86.ActiveCfg = Release|Any CPU
544550
{50E277B8-8580-487A-8F8E-5C3B9FBF0F77}.XamlDesign|x86.Build.0 = Release|Any CPU
551+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
552+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
553+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Debug|x86.ActiveCfg = Debug|Any CPU
554+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Debug|x86.Build.0 = Debug|Any CPU
555+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Publish|Any CPU.ActiveCfg = Release|Any CPU
556+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Publish|Any CPU.Build.0 = Release|Any CPU
557+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Publish|x86.ActiveCfg = Release|Any CPU
558+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Publish|x86.Build.0 = Release|Any CPU
559+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
560+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Release|Any CPU.Build.0 = Release|Any CPU
561+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Release|x86.ActiveCfg = Release|Any CPU
562+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.Release|x86.Build.0 = Release|Any CPU
563+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.XamlDesign|Any CPU.ActiveCfg = Release|Any CPU
564+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.XamlDesign|Any CPU.Build.0 = Release|Any CPU
565+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.XamlDesign|x86.ActiveCfg = Release|Any CPU
566+
{9453C37F-44CF-463D-B563-5C3110CEF5E7}.XamlDesign|x86.Build.0 = Release|Any CPU
567+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
568+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Debug|Any CPU.Build.0 = Debug|Any CPU
569+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Debug|x86.ActiveCfg = Debug|Any CPU
570+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Debug|x86.Build.0 = Debug|Any CPU
571+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Publish|Any CPU.ActiveCfg = Release|Any CPU
572+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Publish|Any CPU.Build.0 = Release|Any CPU
573+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Publish|x86.ActiveCfg = Release|Any CPU
574+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Publish|x86.Build.0 = Release|Any CPU
575+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Release|Any CPU.ActiveCfg = Release|Any CPU
576+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Release|Any CPU.Build.0 = Release|Any CPU
577+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Release|x86.ActiveCfg = Release|Any CPU
578+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.Release|x86.Build.0 = Release|Any CPU
579+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.XamlDesign|Any CPU.ActiveCfg = Release|Any CPU
580+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.XamlDesign|Any CPU.Build.0 = Release|Any CPU
581+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.XamlDesign|x86.ActiveCfg = Release|Any CPU
582+
{110B206F-8554-4B51-BF86-94DAA32F5E26}.XamlDesign|x86.Build.0 = Release|Any CPU
545583
EndGlobalSection
546584
GlobalSection(SolutionProperties) = preSolution
547585
HideSolutionNode = FALSE
@@ -565,5 +603,8 @@ Global
565603
{0EC8DBA1-D745-4EE5-993A-6026440EC3BF} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AF9}
566604
{DD99FD0F-82F6-4C30-930E-4A1D0DF01D65} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AB9}
567605
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
606+
{4405C20E-A72A-4807-9480-14E9BB558347} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AB8}
607+
{9453C37F-44CF-463D-B563-5C3110CEF5E7} = {4405C20E-A72A-4807-9480-14E9BB558347}
608+
{110B206F-8554-4B51-BF86-94DAA32F5E26} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
568609
EndGlobalSection
569610
EndGlobal
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{110B206F-8554-4B51-BF86-94DAA32F5E26}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>GitHub.UI.UnitTests</RootNamespace>
11+
<AssemblyName>GitHub.UI.UnitTests</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="nunit.framework, Version=3.6.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
35+
<HintPath>..\..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll</HintPath>
36+
<Private>True</Private>
37+
</Reference>
38+
<Reference Include="PresentationCore" />
39+
<Reference Include="PresentationFramework" />
40+
<Reference Include="System" />
41+
<Reference Include="System.Core" />
42+
<Reference Include="System.Xml.Linq" />
43+
<Reference Include="System.Data.DataSetExtensions" />
44+
<Reference Include="Microsoft.CSharp" />
45+
<Reference Include="System.Data" />
46+
<Reference Include="System.Net.Http" />
47+
<Reference Include="System.Xml" />
48+
<Reference Include="WindowsBase" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<Compile Include="LoadingResourceDictionaryTests.cs" />
52+
<Compile Include="Properties\AssemblyInfo.cs" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<None Include="packages.config" />
56+
</ItemGroup>
57+
<ItemGroup>
58+
<ProjectReference Include="..\..\src\GitHub.UI\GitHub.UI.csproj">
59+
<Project>{346384dd-2445-4a28-af22-b45f3957bd89}</Project>
60+
<Name>GitHub.UI</Name>
61+
</ProjectReference>
62+
<ProjectReference Include="..\..\src\GitHub.VisualStudio.UI\GitHub.VisualStudio.UI.csproj">
63+
<Project>{d1dfbb0c-b570-4302-8f1e-2e3a19c41961}</Project>
64+
<Name>GitHub.VisualStudio.UI</Name>
65+
</ProjectReference>
66+
</ItemGroup>
67+
<ItemGroup />
68+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
69+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
70+
Other similar extension points exist, see Microsoft.Common.targets.
71+
<Target Name="BeforeBuild">
72+
</Target>
73+
<Target Name="AfterBuild">
74+
</Target>
75+
-->
76+
</Project>
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Windows;
5+
using NUnit.Framework;
6+
7+
namespace GitHub.UI.Tests
8+
{
9+
public class LoadingResourceDictionaryTests
10+
{
11+
public class TheSourceProperty
12+
{
13+
[Description("Load assembly using LoadFrom away from application base")]
14+
[TestCase("pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml")]
15+
[TestCase("pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml")]
16+
[RequiresThread(System.Threading.ApartmentState.STA)]
17+
public void SetInLoadFromContext(string url)
18+
{
19+
var setup = new AppDomainSetup { ApplicationBase = "NOTHING_HERE" };
20+
using (var context = new AppDomainContext(setup))
21+
{
22+
var remote = context.CreateInstance<LoadingResourceDictionaryContext>();
23+
24+
int count = remote.CountMergedDictionaries(url);
25+
26+
Assert.That(count, Is.GreaterThan(0));
27+
}
28+
}
29+
30+
[Description("Load assembly using LoadFrom on application base")]
31+
[TestCase("pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml")]
32+
[TestCase("pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml")]
33+
[RequiresThread(System.Threading.ApartmentState.STA)]
34+
public void SetInLoadContext(string url)
35+
{
36+
var local = new LoadingResourceDictionaryContext();
37+
38+
int count = local.CountMergedDictionaries(url);
39+
40+
Assert.That(count, Is.GreaterThan(0));
41+
}
42+
43+
class LoadingResourceDictionaryContext : MarshalByRefObject
44+
{
45+
internal int CountMergedDictionaries(string url)
46+
{
47+
var target = new LoadingResourceDictionary();
48+
var packUri = ToPackUri(url);
49+
50+
target.Source = packUri;
51+
52+
return target.MergedDictionaries.Count;
53+
}
54+
}
55+
}
56+
57+
public class TheResourceDictionarySourceProperty
58+
{
59+
[Description("This shows why LoadingResourceDictionary is necessary")]
60+
[TestCase("pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml")]
61+
[TestCase("pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml")]
62+
public void SetInLoadFromContext(string url)
63+
{
64+
var setup = new AppDomainSetup { ApplicationBase = "NOTHING_HERE" };
65+
using (var context = new AppDomainContext(setup))
66+
{
67+
var remote = context.CreateInstance<ResourceDictionaryContext>();
68+
69+
Assert.Throws<FileNotFoundException>(() => remote.CountMergedDictionaries(url));
70+
}
71+
}
72+
73+
class ResourceDictionaryContext : MarshalByRefObject
74+
{
75+
internal int CountMergedDictionaries(string url)
76+
{
77+
var target = new ResourceDictionary();
78+
var packUri = ToPackUri(url);
79+
80+
target.Source = packUri;
81+
82+
return target.MergedDictionaries.Count;
83+
}
84+
}
85+
}
86+
87+
static Uri ToPackUri(string url)
88+
{
89+
if (!UriParser.IsKnownScheme("pack"))
90+
{
91+
// Register the pack scheme.
92+
new Application();
93+
}
94+
95+
return new Uri(url);
96+
}
97+
98+
class AppDomainContext : IDisposable
99+
{
100+
AppDomain domain;
101+
102+
public AppDomainContext(AppDomainSetup setup)
103+
{
104+
var friendlyName = GetType().FullName;
105+
domain = AppDomain.CreateDomain(friendlyName, null, setup);
106+
}
107+
108+
public T CreateInstance<T>()
109+
{
110+
return (T)domain.CreateInstanceFromAndUnwrap(typeof(T).Assembly.CodeBase, typeof(T).FullName);
111+
}
112+
113+
public void Dispose()
114+
{
115+
AppDomain.Unload(domain);
116+
}
117+
}
118+
119+
static void DumpResourceDictionary(ResourceDictionary rd, string indent = "")
120+
{
121+
var source = rd.Source?.ToString() ?? "null";
122+
123+
Trace.WriteLine(indent + source + rd.GetType().FullName);
124+
foreach (var child in rd.MergedDictionaries)
125+
{
126+
DumpResourceDictionary(child, indent + " ");
127+
}
128+
}
129+
}
130+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("GitHub.QuickTests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("GitHub.QuickTests")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("110b206f-8554-4b51-bf86-94daa32f5e26")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NUnit" version="3.6.1" targetFramework="net461" />
4+
</packages>

0 commit comments

Comments
 (0)