-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extract services. * Add unit testing project. * Using Verify. With custom converter for DevToys UI elements. * 100% code coverage. * Use `global.json` for .NET version. * Run linting during CI. * Extract packages to `Directory.Packages.props`.
- Loading branch information
Showing
38 changed files
with
4,376 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Verify | ||
# https://github.com/VerifyTests/Verify/blob/main/docs/wiz/Windows_VisualStudioWithReSharper_Gui_Xunit_GitHubActions.md#source-control-settings | ||
*.verified.txt text eol=lf working-tree-encoding=UTF-8 | ||
*.verified.xml text eol=lf working-tree-encoding=UTF-8 | ||
*.verified.json text eol=lf working-tree-encoding=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="coverlet.collector" Version="6.0.2" /> | ||
<PackageVersion Include="CSharpier.MsBuild" Version="0.29.2" /> | ||
<PackageVersion Include="DevToys.Api" Version="2.0.5-preview" /> | ||
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.2.25" /> | ||
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" /> | ||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> | ||
<PackageVersion Include="Moq" Version="4.20.72" /> | ||
<PackageVersion Include="Moq.Contrib.HttpClient" Version="1.4.0" /> | ||
<PackageVersion Include="Semver" Version="2.3.0" /> | ||
<PackageVersion Include="Verify.Xunit" Version="26.6.0" /> | ||
<PackageVersion Include="xunit" Version="2.9.1" /> | ||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Ignore Verify files. | ||
# https://github.com/VerifyTests/Verify/blob/main/docs/wiz/Windows_VisualStudioWithReSharper_Gui_Xunit_GitHubActions.md#includesexcludes | ||
*.received.* | ||
*.received/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
[assembly: SuppressMessage( | ||
"Performance", | ||
"CA1869", | ||
Justification = "Do not cache JsonSerializerOptions in tests." | ||
)] |
69 changes: 69 additions & 0 deletions
69
Jvw.DevToys.SemverCalculator.Tests/Converters/DevToysElementConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Reflection; | ||
using DevToys.Api; | ||
|
||
namespace Jvw.DevToys.SemverCalculator.Tests.Converters; | ||
|
||
/// <summary> | ||
/// DevToys element converter used for Verify tool. | ||
/// </summary> | ||
public class DevToysElementConverter : WriteOnlyJsonConverter<IUIElement> | ||
{ | ||
public override void Write(VerifyJsonWriter writer, IUIElement element) | ||
{ | ||
writer.WriteStartObject(); | ||
|
||
var type = element.GetType(); | ||
|
||
// Prepend type name. | ||
writer.WriteMember(element, type.Name, "$type"); | ||
|
||
var props = type.GetTypeInfo().GetProperties(BindingFlags.Instance | BindingFlags.Public); | ||
foreach (var prop in props) | ||
{ | ||
var name = prop.Name; | ||
var val = prop.GetValue(element); | ||
|
||
// Replace button `OnClickAction` value with a placeholder, instead of delegate details. | ||
if (IsButtonClickAction(element, name, val)) | ||
{ | ||
writer.WriteMember(element, "{has click action}", prop.Name); | ||
} | ||
// Replace info-bar `OnCloseAction` value with a placeholder, instead of delegate details. | ||
else if (IsInfoBarCloseAction(element, name, val)) | ||
{ | ||
writer.WriteMember(element, "{has close action}", prop.Name); | ||
} | ||
else | ||
{ | ||
writer.WritePropertyName(name); | ||
writer.Serializer.Serialize(writer, val); | ||
} | ||
} | ||
|
||
writer.WriteEndObject(); | ||
} | ||
|
||
/// <summary> | ||
/// Detect if property is `OnClickAction` from a button. | ||
/// </summary> | ||
/// <param name="element">Element.</param> | ||
/// <param name="name">Property name.</param> | ||
/// <param name="val">Property value.</param> | ||
/// <returns>Whether property is `OnClickAction` from a button.</returns> | ||
private static bool IsButtonClickAction(IUIElement element, string name, object? val) | ||
{ | ||
return element is IUIButton && name == nameof(IUIButton.OnClickAction) && val is not null; | ||
} | ||
|
||
/// <summary> | ||
/// Detect if property is `OnCloseAction` from an info-bar. | ||
/// </summary> | ||
/// <param name="element">Element.</param> | ||
/// <param name="name">Property name.</param> | ||
/// <param name="val">Property value.</param> | ||
/// <returns>Whether property is `OnCloseAction` from an info-bar.</returns> | ||
private static bool IsInfoBarCloseAction(IUIElement element, string name, object? val) | ||
{ | ||
return element is IUIInfoBar && name == nameof(IUIInfoBar.OnCloseAction) && val is not null; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Jvw.DevToys.SemverCalculator.Tests/Jvw.DevToys.SemverCalculator.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="CSharpier.MsBuild"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="GitHubActionsTestLogger"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="Moq" /> | ||
<PackageReference Include="Moq.Contrib.HttpClient" /> | ||
<PackageReference Include="Verify.Xunit" /> | ||
<PackageReference Include="xunit" /> | ||
<PackageReference Include="xunit.runner.visualstudio"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Jvw.DevToys.SemverCalculator\Jvw.DevToys.SemverCalculator.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.