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

Enable Nullable for Xamarin.CommunityToolkit.Markup.UnitTests #1086

Merged
merged 9 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ variables:
PathToMarkupCsproj: 'src/Markup/Xamarin.CommunityToolkit.Markup/Xamarin.CommunityToolkit.Markup.csproj'
PathToCommunityToolkitCsproj: 'src/CommunityToolkit/Xamarin.CommunityToolkit/Xamarin.CommunityToolkit.csproj'
PathToSamplesSln: 'samples/XCT.Sample.sln'
PathToUnitTestCsproj: 'src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Xamarin.CommunityToolkit.UnitTests.csproj'
PathToCommunityToolkitUnitTestCsproj: 'src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Xamarin.CommunityToolkit.UnitTests.csproj'
PathToMarkupUnitTestCsproj: 'src/Markup/Xamarin.CommunityToolkit.Markup.UnitTests/Xamarin.CommunityToolkit.Markup.UnitTests.csproj'
PathToMsBuildOnMacOS: 'mono /Applications/Visual\ studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/MSBuild.dll'
PathToSln: 'samples/XCT.Sample.sln'

Expand Down Expand Up @@ -107,7 +108,7 @@ jobs:
Contents: 'SignList.xml'
TargetFolder: '$(Build.ArtifactStagingDirectory)/nuget'
- task: MSBuild@1
displayName: Pack NuGets
displayName: Pack Community Toolkit NuGets
inputs:
solution: $(PathToCommunityToolkitCsproj)
configuration: Release
Expand All @@ -132,9 +133,13 @@ jobs:
# custom: 'nuget'
# arguments: 'push --source https://nuget.pkg.github.com/xamarin/index.json --api-key $(GitHub.NuGet.Token) "$(Build.ArtifactStagingDirectory)\nuget\*.nupkg"'
- task: CmdLine@2
displayName: 'Run Unit Tests'
displayName: 'Run Markup Unit Tests'
inputs:
script: dotnet test $(PathToUnitTestCsproj) -c Release --collect "Code coverage" -p:BuildInParallel=false
script: dotnet test $(PathToMarkupUnitTestCsproj) -c Release --collect "Code coverage" -p:BuildInParallel=false
- task: CmdLine@2
displayName: 'Run Community Toolkit Unit Tests'
inputs:
script: dotnet test $(PathToCommunityToolkitUnitTestCsproj) -c Release --collect "Code coverage" -p:BuildInParallel=false
# publish the packages
- task: PublishBuildArtifacts@1
displayName: 'Publish Unsigned NuGets'
Expand Down Expand Up @@ -193,15 +198,27 @@ jobs:
version: $(NETCORE_TEST_VERSION_2_1)
includePreviewVersions: false
- task: CmdLine@2
displayName: 'Build Xamarin.CommunityToolkit.csproj'
displayName: 'Build Markup'
inputs:
script: '$(PathToMsBuildOnMacOS) $(PathToMarkupCsproj) /p:Configuration=Release /restore /t:Build /p:ContinuousIntegrationBuild=true /p:Deterministic=false'
- task: CmdLine@2
displayName: 'Build Community Toolkit'
inputs:
script: '$(PathToMsBuildOnMacOS) $(PathToCommunityToolkitCsproj) /p:Configuration=Release /restore /t:Build /p:ContinuousIntegrationBuild=true /p:Deterministic=false'
- task: CmdLine@2
displayName: 'Run Unit Tests'
displayName: 'Run Markup Unit Tests'
inputs:
script: 'dotnet test $(PathToMarkupUnitTestCsproj) /p:Configuration=Release -p:BuildInParallel=false'
- task: CmdLine@2
displayName: 'Run Community Toolkit Unit Tests'
inputs:
script: 'dotnet test $(PathToCommunityToolkitUnitTestCsproj) /p:Configuration=Release -p:BuildInParallel=false'
- task: CmdLine@2
displayName: 'Pack Markup NuGets'
inputs:
script: 'dotnet test $(PathToUnitTestCsproj) /p:Configuration=Release'
script: '$(PathToMsBuildOnMacOS) $(PathToMarkupUnitTestCsproj) /p:Configuration=Release /t:Pack /p:PackageVersion=$(NugetPackageVersion) /p:PackageOutputPath="$(Build.ArtifactStagingDirectory)/nuget"'
- task: CmdLine@2
displayName: 'Pack NuGets'
displayName: 'Pack CommunityToolkit NuGets'
inputs:
script: '$(PathToMsBuildOnMacOS) $(PathToCommunityToolkitCsproj) /p:Configuration=Release /t:Pack /p:PackageVersion=$(NugetPackageVersion) /p:PackageOutputPath="$(Build.ArtifactStagingDirectory)/nuget"'

Expand Down
27 changes: 27 additions & 0 deletions samples/XCT.Sample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit.Sa
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit.Markup", "..\src\Markup\Xamarin.CommunityToolkit.Markup\Xamarin.CommunityToolkit.Markup.csproj", "{A5AAB927-15D7-498C-8295-4209F21836CE}"
EndProject
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -301,12 +303,37 @@ Global
{A5AAB927-15D7-498C-8295-4209F21836CE}.Release|x64.Build.0 = Release|Any CPU
{A5AAB927-15D7-498C-8295-4209F21836CE}.Release|x86.ActiveCfg = Release|Any CPU
{A5AAB927-15D7-498C-8295-4209F21836CE}.Release|x86.Build.0 = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|ARM.ActiveCfg = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|ARM.Build.0 = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|iPhone.Build.0 = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|x64.ActiveCfg = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|x64.Build.0 = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|x86.ActiveCfg = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Debug|x86.Build.0 = Debug|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|Any CPU.Build.0 = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|ARM.ActiveCfg = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|ARM.Build.0 = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|iPhone.ActiveCfg = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|iPhone.Build.0 = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|x64.ActiveCfg = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|x64.Build.0 = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|x86.ActiveCfg = Release|Any CPU
{AAE423C4-E9B4-434E-885C-2164C12BF79C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{54B7812B-45A5-4FE2-9CEA-C5F17D65BDE9} = {47DFE508-04F1-433D-8C55-0C1ACD033573}
{AAE423C4-E9B4-434E-885C-2164C12BF79C} = {47DFE508-04F1-433D-8C55-0C1ACD033573}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {449686DB-B85A-4DFA-AA26-9BC92468CC2A}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Globalization;
using System;
using System.Globalization;
using NUnit.Framework;
using Xamarin.Forms;

namespace Xamarin.CommunityToolkit.Markup.UnitTests
{
public class BaseTestFixture
{
CultureInfo defaultCulture;
CultureInfo defaultUICulture;
CultureInfo? defaultCulture;
CultureInfo? defaultUICulture;

[SetUp]
public virtual void Setup()
Expand All @@ -21,8 +22,9 @@ public virtual void Setup()
public virtual void TearDown()
{
Device.PlatformServices = null;
System.Threading.Thread.CurrentThread.CurrentCulture = defaultCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = defaultUICulture;

System.Threading.Thread.CurrentThread.CurrentCulture = defaultCulture ?? throw new NullReferenceException();
System.Threading.Thread.CurrentThread.CurrentUICulture = defaultUICulture ?? throw new NullReferenceException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,51 @@ public class BindableLayoutExtensionsTests : MarkupBaseTestFixture<StackLayout>
public void EmptyView()
{
var view = new BoxView();
TestPropertiesSet(l => l.EmptyView(view), (BindableLayout.EmptyViewProperty, view));
TestPropertiesSet(l => l?.EmptyView(view), (BindableLayout.EmptyViewProperty, view));
}

[Test]
public void EmptyViewTemplate()
{
var template = new DataTemplate(() => new BoxView());
TestPropertiesSet(l => l.EmptyViewTemplate(template), (BindableLayout.EmptyViewTemplateProperty, template));
TestPropertiesSet(l => l?.EmptyViewTemplate(template), (BindableLayout.EmptyViewTemplateProperty, template));
}

[Test]
public void EmptyViewTemplateFunction()
{
Func<object> loadTemplate = () => new BoxView();
Bindable.EmptyViewTemplate(loadTemplate);
Bindable?.EmptyViewTemplate(loadTemplate);
Assert.That(BindableLayout.GetEmptyViewTemplate(Bindable), Is.Not.Null);
}

[Test]
public void ItemsSource()
{
var source = new string[] { };
TestPropertiesSet(l => l.ItemsSource(source), (BindableLayout.ItemsSourceProperty, source));
TestPropertiesSet(l => l?.ItemsSource(source), (BindableLayout.ItemsSourceProperty, source));
}

[Test]
public void ItemTemplate()
{
var template = new DataTemplate(() => new BoxView());
TestPropertiesSet(l => l.ItemTemplate(template), (BindableLayout.ItemTemplateProperty, template));
TestPropertiesSet(l => l?.ItemTemplate(template), (BindableLayout.ItemTemplateProperty, template));
}

[Test]
public void ItemTemplateFunction()
{
Func<object> loadTemplate = () => new BoxView();
Bindable.ItemTemplate(loadTemplate);
Bindable?.ItemTemplate(loadTemplate);
Assert.That(BindableLayout.GetItemTemplate(Bindable), Is.Not.Null);
}

[Test]
public void ItemTemplateSelector()
{
var selector = new Selector();
TestPropertiesSet(l => l.ItemTemplateSelector(selector), (BindableLayout.ItemTemplateSelectorProperty, selector));
TestPropertiesSet(l => l?.ItemTemplateSelector(selector), (BindableLayout.ItemTemplateSelectorProperty, selector));
}

class Selector : DataTemplateSelector
Expand Down
Loading