Skip to content
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
4 changes: 2 additions & 2 deletions src/AStar.Dev.Utilities/AStar.Dev.Utilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/jbarden/astar-dev-utilities</PackageProjectUrl>
<Description>A collection of useful utilities.</Description>
<Version>1.5.0</Version>
<Version>1.5.1</Version>
<Authors>AStar Development, Jason Barden</Authors>
<DocumentationFile>$(AssemblyName).xml</DocumentationFile>
<PackageIcon>AStar.png</PackageIcon>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>version 1.5.0 contains the initial code port from the jbarden NuGet / GitHub organisations.</PackageReleaseNotes>
<PackageReleaseNotes>version 1.5.1 adds the missing tests, no functionality is affected.</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/AStar.Dev.Utilities/AStar.Dev.Utilities.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/AStar.Dev.Utilities/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json;

namespace AStar.Utilities;
namespace AStar.Dev.Utilities;

/// <summary>
/// The <see href="Constants"></see>see> class contains static / constant properties to simplify and centralise various settings.
Expand Down
11 changes: 6 additions & 5 deletions src/AStar.Dev.Utilities/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
namespace AStar.Utilities;
namespace AStar.Dev.Utilities;

/// <summary>
///
/// </summary>
public static class EnumExtensions
{
/// <summary>
///
/// The ParseEnum method will parse the supplied string and return the matching enum value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
/// <typeparam name="T">The typeof of the expected enum.</typeparam>
/// <param name="value">The value to parse to the enum.</param>
/// <returns>The parsed value as the matching enum value.</returns>
/// <exception cref="ArgumentException">Thrown when the string is not a valid enum value.</exception>
public static T ParseEnum<T>(this string value) => (T)Enum.Parse(typeof(T), value, true);
}
2 changes: 1 addition & 1 deletion src/AStar.Dev.Utilities/ObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json;

namespace AStar.Utilities;
namespace AStar.Dev.Utilities;

/// <summary>
/// The <see cref="ObjectExtensions" /> class contains some useful methods to enable various tasks
Expand Down
2 changes: 1 addition & 1 deletion src/AStar.Dev.Utilities/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json;

namespace AStar.Utilities;
namespace AStar.Dev.Utilities;

/// <summary>
/// The <see cref="StringExtensions" /> class contains some useful methods to enable checks to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand All @@ -27,6 +28,7 @@
</ItemGroup>

<ItemGroup>
<Using Include="FluentAssertions" />
<Using Include="Xunit" />
</ItemGroup>

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/AStar.Dev.Utilities.Unit.Tests/AnyClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AStar.Dev.Utilities.Unit.Tests;

internal class AnyClass
{
public int AnyInt { get; set; }

public string AnyString { get; set; } = string.Empty;
}
7 changes: 7 additions & 0 deletions tests/unit/AStar.Dev.Utilities.Unit.Tests/AnyEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace AStar.Dev.Utilities.Unit.Tests;

internal enum AnyEnum
{
NotDefined,
Defined
}
11 changes: 11 additions & 0 deletions tests/unit/AStar.Dev.Utilities.Unit.Tests/ConstantsShould.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace AStar.Dev.Utilities.Unit.Tests;

public class ConstantsShould
{
[Fact]
public void ContainTheExpectedWebDeserialisationSettingsSetting()
=> Constants.WebDeserialisationSettings
.ToJson()
.Should()
.Be("{\"Converters\":[],\"TypeInfoResolver\":null,\"TypeInfoResolverChain\":[],\"AllowTrailingCommas\":false,\"DefaultBufferSize\":16384,\"Encoder\":null,\"DictionaryKeyPolicy\":null,\"IgnoreNullValues\":false,\"DefaultIgnoreCondition\":0,\"NumberHandling\":1,\"PreferredObjectCreationHandling\":0,\"IgnoreReadOnlyProperties\":false,\"IgnoreReadOnlyFields\":false,\"IncludeFields\":false,\"MaxDepth\":0,\"PropertyNamingPolicy\":{},\"PropertyNameCaseInsensitive\":true,\"ReadCommentHandling\":0,\"UnknownTypeHandling\":0,\"UnmappedMemberHandling\":0,\"WriteIndented\":false,\"ReferenceHandler\":null,\"IsReadOnly\":false}");
}
16 changes: 16 additions & 0 deletions tests/unit/AStar.Dev.Utilities.Unit.Tests/EnumExtensionsShould.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace AStar.Dev.Utilities.Unit.Tests;

public class EnumExtensionsShould
{
[Fact]
public void ContainTheParseMethodReturningTheExpectedValue()
=> "Defined".ParseEnum<AnyEnum>().Should().Be(AnyEnum.Defined);

[Fact]
public void ContainTheParseMethodWhichThrowsArgumentExceptionWhenTheValueIsNotFound()
{
Action parseStringAction = () => "ThisDoesntExitst".ParseEnum<AnyEnum>();

_ = parseStringAction.Should().Throw<ArgumentException>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace AStar.Dev.Utilities.Unit.Tests;

public class ObjectExtensionsShould
{
[Fact]
public void ContainTheToJsonMethodWhichReturnsTheExpectedString()
=> ObjectExtensions
.ToJson(new AnyClass())
.Should().Be("{\"AnyInt\":0,\"AnyString\":\"\"}");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace AStar.Dev.Utilities.Unit.Tests;

public class StringExtensionsShould
{
private readonly string? nullString = null;
private readonly string notNullString = "value does not matter";
private readonly string whitespaceString = " ";
private readonly string anyJson = "{\"AnyInt\":0,\"AnyString\":\"\"}";

[Fact]
public void ContainTheIsNullMethodWhichReturnsTheResult()
=> nullString.IsNull().Should().BeTrue();

[Fact]
public void ContainTheIsNotNullMethodWhichReturnsTheResult()
=> notNullString.IsNotNull().Should().BeTrue();

[Fact]
public void ContainTheIsNullOrWhiteSpaceMethodWhichReturnsTheResult()
=> whitespaceString.IsNullOrWhiteSpace().Should().BeTrue();

[Fact]
public void ContainTheIsNotNullOrWhiteSpaceMethodWhichReturnsTheResult()
=> notNullString.IsNotNullOrWhiteSpace().Should().BeTrue();

[Fact]
public void ContainTheFromJsonMethodWhichReturnsTheResult()
=> anyJson.FromJson<AnyClass>().Should().BeEquivalentTo<AnyClass>(new() { });

[Fact]
public void ContainTheFromJsonTakingJsonSerializerOptionsMethodWhichReturnsTheResult()
=> anyJson.FromJson<AnyClass>(new()).Should().BeEquivalentTo<AnyClass>(new() { });
}
10 changes: 0 additions & 10 deletions tests/unit/AStar.Dev.Utilities.Unit.Tests/UnitTest1.cs

This file was deleted.