Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit f67b9f3

Browse files
Enable Nullable for Xamarin.CommunityToolkit.Markup.UnitTests (#1086)
* Add Markup Unit Tests * Add Nullable to Xamarin.CommunityToolkit.Markdown.UnitTests * Update BindingHelpers.cs * Fix Failing Unit Tests * Don't capture XUnit's Synchronization Context * Re-order Unit Tests * Revert "Don't capture XUnit's Synchronization Context" This reverts commit b8b3f16. Co-authored-by: Javier Suárez <[email protected]>
1 parent 01a9597 commit f67b9f3

30 files changed

+506
-420
lines changed

azure-pipelines.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ variables:
1313
PathToMarkupCsproj: 'src/Markup/Xamarin.CommunityToolkit.Markup/Xamarin.CommunityToolkit.Markup.csproj'
1414
PathToCommunityToolkitCsproj: 'src/CommunityToolkit/Xamarin.CommunityToolkit/Xamarin.CommunityToolkit.csproj'
1515
PathToSamplesSln: 'samples/XCT.Sample.sln'
16-
PathToUnitTestCsproj: 'src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Xamarin.CommunityToolkit.UnitTests.csproj'
16+
PathToCommunityToolkitUnitTestCsproj: 'src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Xamarin.CommunityToolkit.UnitTests.csproj'
17+
PathToMarkupUnitTestCsproj: 'src/Markup/Xamarin.CommunityToolkit.Markup.UnitTests/Xamarin.CommunityToolkit.Markup.UnitTests.csproj'
1718
PathToMsBuildOnMacOS: 'mono /Applications/Visual\ studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/MSBuild.dll'
1819
PathToSln: 'samples/XCT.Sample.sln'
1920

@@ -107,7 +108,7 @@ jobs:
107108
Contents: 'SignList.xml'
108109
TargetFolder: '$(Build.ArtifactStagingDirectory)/nuget'
109110
- task: MSBuild@1
110-
displayName: Pack NuGets
111+
displayName: Pack Community Toolkit NuGets
111112
inputs:
112113
solution: $(PathToCommunityToolkitCsproj)
113114
configuration: Release
@@ -132,9 +133,13 @@ jobs:
132133
# custom: 'nuget'
133134
# arguments: 'push --source https://nuget.pkg.github.com/xamarin/index.json --api-key $(GitHub.NuGet.Token) "$(Build.ArtifactStagingDirectory)\nuget\*.nupkg"'
134135
- task: CmdLine@2
135-
displayName: 'Run Unit Tests'
136+
displayName: 'Run Markup Unit Tests'
136137
inputs:
137-
script: dotnet test $(PathToUnitTestCsproj) -c Release --collect "Code coverage" -p:BuildInParallel=false
138+
script: dotnet test $(PathToMarkupUnitTestCsproj) -c Release --collect "Code coverage" -p:BuildInParallel=false
139+
- task: CmdLine@2
140+
displayName: 'Run Community Toolkit Unit Tests'
141+
inputs:
142+
script: dotnet test $(PathToCommunityToolkitUnitTestCsproj) -c Release --collect "Code coverage" -p:BuildInParallel=false
138143
# publish the packages
139144
- task: PublishBuildArtifacts@1
140145
displayName: 'Publish Unsigned NuGets'
@@ -193,15 +198,27 @@ jobs:
193198
version: $(NETCORE_TEST_VERSION_2_1)
194199
includePreviewVersions: false
195200
- task: CmdLine@2
196-
displayName: 'Build Xamarin.CommunityToolkit.csproj'
201+
displayName: 'Build Markup'
202+
inputs:
203+
script: '$(PathToMsBuildOnMacOS) $(PathToMarkupCsproj) /p:Configuration=Release /restore /t:Build /p:ContinuousIntegrationBuild=true /p:Deterministic=false'
204+
- task: CmdLine@2
205+
displayName: 'Build Community Toolkit'
197206
inputs:
198207
script: '$(PathToMsBuildOnMacOS) $(PathToCommunityToolkitCsproj) /p:Configuration=Release /restore /t:Build /p:ContinuousIntegrationBuild=true /p:Deterministic=false'
199208
- task: CmdLine@2
200-
displayName: 'Run Unit Tests'
209+
displayName: 'Run Markup Unit Tests'
210+
inputs:
211+
script: 'dotnet test $(PathToMarkupUnitTestCsproj) /p:Configuration=Release -p:BuildInParallel=false'
212+
- task: CmdLine@2
213+
displayName: 'Run Community Toolkit Unit Tests'
214+
inputs:
215+
script: 'dotnet test $(PathToCommunityToolkitUnitTestCsproj) /p:Configuration=Release -p:BuildInParallel=false'
216+
- task: CmdLine@2
217+
displayName: 'Pack Markup NuGets'
201218
inputs:
202-
script: 'dotnet test $(PathToUnitTestCsproj) /p:Configuration=Release'
219+
script: '$(PathToMsBuildOnMacOS) $(PathToMarkupUnitTestCsproj) /p:Configuration=Release /t:Pack /p:PackageVersion=$(NugetPackageVersion) /p:PackageOutputPath="$(Build.ArtifactStagingDirectory)/nuget"'
203220
- task: CmdLine@2
204-
displayName: 'Pack NuGets'
221+
displayName: 'Pack CommunityToolkit NuGets'
205222
inputs:
206223
script: '$(PathToMsBuildOnMacOS) $(PathToCommunityToolkitCsproj) /p:Configuration=Release /t:Pack /p:PackageVersion=$(NugetPackageVersion) /p:PackageOutputPath="$(Build.ArtifactStagingDirectory)/nuget"'
207224

samples/XCT.Sample.sln

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit.Sa
3131
EndProject
3232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit.Markup", "..\src\Markup\Xamarin.CommunityToolkit.Markup\Xamarin.CommunityToolkit.Markup.csproj", "{A5AAB927-15D7-498C-8295-4209F21836CE}"
3333
EndProject
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.CommunityToolkit.Markup.UnitTests", "..\src\Markup\Xamarin.CommunityToolkit.Markup.UnitTests\Xamarin.CommunityToolkit.Markup.UnitTests.csproj", "{AAE423C4-E9B4-434E-885C-2164C12BF79C}"
35+
EndProject
3436
Global
3537
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3638
Debug|Any CPU = Debug|Any CPU
@@ -301,12 +303,37 @@ Global
301303
{A5AAB927-15D7-498C-8295-4209F21836CE}.Release|x64.Build.0 = Release|Any CPU
302304
{A5AAB927-15D7-498C-8295-4209F21836CE}.Release|x86.ActiveCfg = Release|Any CPU
303305
{A5AAB927-15D7-498C-8295-4209F21836CE}.Release|x86.Build.0 = Release|Any CPU
306+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
307+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|Any CPU.Build.0 = Debug|Any CPU
308+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|ARM.ActiveCfg = Debug|Any CPU
309+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|ARM.Build.0 = Debug|Any CPU
310+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|iPhone.ActiveCfg = Debug|Any CPU
311+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|iPhone.Build.0 = Debug|Any CPU
312+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
313+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
314+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|x64.ActiveCfg = Debug|Any CPU
315+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|x64.Build.0 = Debug|Any CPU
316+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|x86.ActiveCfg = Debug|Any CPU
317+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|x86.Build.0 = Debug|Any CPU
318+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|Any CPU.ActiveCfg = Release|Any CPU
319+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|Any CPU.Build.0 = Release|Any CPU
320+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|ARM.ActiveCfg = Release|Any CPU
321+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|ARM.Build.0 = Release|Any CPU
322+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|iPhone.ActiveCfg = Release|Any CPU
323+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|iPhone.Build.0 = Release|Any CPU
324+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
325+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
326+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|x64.ActiveCfg = Release|Any CPU
327+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|x64.Build.0 = Release|Any CPU
328+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|x86.ActiveCfg = Release|Any CPU
329+
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|x86.Build.0 = Release|Any CPU
304330
EndGlobalSection
305331
GlobalSection(SolutionProperties) = preSolution
306332
HideSolutionNode = FALSE
307333
EndGlobalSection
308334
GlobalSection(NestedProjects) = preSolution
309335
{54B7812B-45A5-4FE2-9CEA-C5F17D65BDE9} = {47DFE508-04F1-433D-8C55-0C1ACD033573}
336+
{AAE423C4-E9B4-434E-885C-2164C12BF79C} = {47DFE508-04F1-433D-8C55-0C1ACD033573}
310337
EndGlobalSection
311338
GlobalSection(ExtensibilityGlobals) = postSolution
312339
SolutionGuid = {449686DB-B85A-4DFA-AA26-9BC92468CC2A}

src/Markup/Xamarin.CommunityToolkit.Markup.UnitTests/BaseTestFixture.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
using System.Globalization;
1+
using System;
2+
using System.Globalization;
23
using NUnit.Framework;
34
using Xamarin.Forms;
45

56
namespace Xamarin.CommunityToolkit.Markup.UnitTests
67
{
78
public class BaseTestFixture
89
{
9-
CultureInfo defaultCulture;
10-
CultureInfo defaultUICulture;
10+
CultureInfo? defaultCulture;
11+
CultureInfo? defaultUICulture;
1112

1213
[SetUp]
1314
public virtual void Setup()
@@ -21,8 +22,9 @@ public virtual void Setup()
2122
public virtual void TearDown()
2223
{
2324
Device.PlatformServices = null;
24-
System.Threading.Thread.CurrentThread.CurrentCulture = defaultCulture;
25-
System.Threading.Thread.CurrentThread.CurrentUICulture = defaultUICulture;
25+
26+
System.Threading.Thread.CurrentThread.CurrentCulture = defaultCulture ?? throw new NullReferenceException();
27+
System.Threading.Thread.CurrentThread.CurrentUICulture = defaultUICulture ?? throw new NullReferenceException();
2628
}
2729
}
2830
}

src/Markup/Xamarin.CommunityToolkit.Markup.UnitTests/BindableLayoutExtensionsTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,51 @@ public class BindableLayoutExtensionsTests : MarkupBaseTestFixture<StackLayout>
1111
public void EmptyView()
1212
{
1313
var view = new BoxView();
14-
TestPropertiesSet(l => l.EmptyView(view), (BindableLayout.EmptyViewProperty, view));
14+
TestPropertiesSet(l => l?.EmptyView(view), (BindableLayout.EmptyViewProperty, view));
1515
}
1616

1717
[Test]
1818
public void EmptyViewTemplate()
1919
{
2020
var template = new DataTemplate(() => new BoxView());
21-
TestPropertiesSet(l => l.EmptyViewTemplate(template), (BindableLayout.EmptyViewTemplateProperty, template));
21+
TestPropertiesSet(l => l?.EmptyViewTemplate(template), (BindableLayout.EmptyViewTemplateProperty, template));
2222
}
2323

2424
[Test]
2525
public void EmptyViewTemplateFunction()
2626
{
2727
Func<object> loadTemplate = () => new BoxView();
28-
Bindable.EmptyViewTemplate(loadTemplate);
28+
Bindable?.EmptyViewTemplate(loadTemplate);
2929
Assert.That(BindableLayout.GetEmptyViewTemplate(Bindable), Is.Not.Null);
3030
}
3131

3232
[Test]
3333
public void ItemsSource()
3434
{
3535
var source = new string[] { };
36-
TestPropertiesSet(l => l.ItemsSource(source), (BindableLayout.ItemsSourceProperty, source));
36+
TestPropertiesSet(l => l?.ItemsSource(source), (BindableLayout.ItemsSourceProperty, source));
3737
}
3838

3939
[Test]
4040
public void ItemTemplate()
4141
{
4242
var template = new DataTemplate(() => new BoxView());
43-
TestPropertiesSet(l => l.ItemTemplate(template), (BindableLayout.ItemTemplateProperty, template));
43+
TestPropertiesSet(l => l?.ItemTemplate(template), (BindableLayout.ItemTemplateProperty, template));
4444
}
4545

4646
[Test]
4747
public void ItemTemplateFunction()
4848
{
4949
Func<object> loadTemplate = () => new BoxView();
50-
Bindable.ItemTemplate(loadTemplate);
50+
Bindable?.ItemTemplate(loadTemplate);
5151
Assert.That(BindableLayout.GetItemTemplate(Bindable), Is.Not.Null);
5252
}
5353

5454
[Test]
5555
public void ItemTemplateSelector()
5656
{
5757
var selector = new Selector();
58-
TestPropertiesSet(l => l.ItemTemplateSelector(selector), (BindableLayout.ItemTemplateSelectorProperty, selector));
58+
TestPropertiesSet(l => l?.ItemTemplateSelector(selector), (BindableLayout.ItemTemplateSelectorProperty, selector));
5959
}
6060

6161
class Selector : DataTemplateSelector

0 commit comments

Comments
 (0)