Skip to content

Commit

Permalink
test: create a test to validate the change
Browse files Browse the repository at this point in the history
  • Loading branch information
pictos committed Jan 31, 2024
1 parent 0a26d65 commit 10ded15
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 33 deletions.
50 changes: 46 additions & 4 deletions src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#nullable enable
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.Collections.Generic;
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Xml.Linq;
Expand All @@ -26,13 +27,39 @@ protected GeneratePackageAppxManifest_v0 GetNewTask(
IntermediateOutputPath = DestinationDirectory,
BuildEngine = this,
GeneratedFilename = generatedFilename,
AppxManifest = new TaskItem(manifest),
AppxManifest = [new TaskItem(manifest)],
ApplicationId = guid,
ApplicationDisplayVersion = displayVersion,
ApplicationVersion = version,
ApplicationTitle = displayName,
AppIcon = appIcon == null ? null : new[] { appIcon },
SplashScreen = splashScreen == null ? null : new[] { splashScreen },
AppIcon = appIcon == null ? null : [appIcon],
SplashScreen = splashScreen == null ? null : [splashScreen],
TargetFramework = "windows"
};
}

protected GeneratePackageAppxManifest_v0 GetNewTask(
ITaskItem[] appxManifests,
string? generatedFilename = null,
string? guid = null,
string? displayVersion = null,
string? version = null,
string? displayName = null,
ITaskItem? appIcon = null,
ITaskItem? splashScreen = null)
{
return new()
{
IntermediateOutputPath = DestinationDirectory,
BuildEngine = this,
GeneratedFilename = generatedFilename,
AppxManifest = appxManifests,
ApplicationId = guid,
ApplicationDisplayVersion = displayVersion,
ApplicationVersion = version,
ApplicationTitle = displayName,
AppIcon = appIcon == null ? null : [appIcon],
SplashScreen = splashScreen == null ? null : [splashScreen],
TargetFramework = "windows"
};
}
Expand All @@ -45,6 +72,7 @@ public void FileIsGenerated(string? specificFn, string outputFn)
var task = GetNewTask($"testdata/appxmanifest/typical.appxmanifest", generatedFilename: specificFn);

var success = task.Execute();

Assert.True(success, $"{task.GetType()}.Execute() failed: " + LogErrorEvents.FirstOrDefault()?.Message);

Assert.True(File.Exists(Path.Combine(DestinationDirectory, outputFn)), "Package.appxmanifest file was not generated.");
Expand Down Expand Up @@ -183,5 +211,19 @@ public void InvalidMergeVersionNumbers(string displayVersion, string appVersion)
var result = GeneratePackageAppxManifest_v0.TryMergeVersionNumbers(displayVersion, appVersion, out var merged);
Assert.False(result);
}

[Fact]
public void TaskShouldFileAWarningIfMoreThanOneManifestIsProvided()
{
// Arrange
var taskItem = new TaskItem("testdata/appxmanifest/typical.appxmanifest");
var task = GetNewTask(appxManifests: [taskItem, taskItem]);

// Act
task.Execute();

// Assert
Assert.True(LogWarningEvents.Count > 0, "Warnings should be greater than zero");
}
}
}
59 changes: 30 additions & 29 deletions src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AssemblyName>Uno.Resizetizer.UnitTests</AssemblyName>
<IsPackable>false</IsPackable>
<DefineConstants Condition="'$(OS)' == 'Windows_NT'">$(DefineConstants);WINDOWS</DefineConstants>
<Configurations>Debug;Release;DEBUG_RESIZETIZER</Configurations>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AssemblyName>Uno.Resizetizer.UnitTests</AssemblyName>
<IsPackable>false</IsPackable>
<DefineConstants Condition="'$(OS)' == 'Windows_NT'">$(DefineConstants);WINDOWS</DefineConstants>
<Configurations>Debug;Release;DEBUG_RESIZETIZER</Configurations>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.6.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.6.3" PrivateAssets="all" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="SkiaSharp.Extended" Version="2.0.0-preview.61" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Svg.Skia" Version="0.5.18" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.6.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.6.3" PrivateAssets="all" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="SkiaSharp.Extended" Version="2.0.0-preview.61" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Svg.Skia" Version="0.5.18" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Resizetizer.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Resizetizer.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="images\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="testdata\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="imageresults\**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<None Include="images\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="testdata\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="imageresults\**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>

0 comments on commit 10ded15

Please sign in to comment.