Skip to content

Commit 89275d9

Browse files
committed
Add the missing tests
1 parent a83e9bb commit 89275d9

File tree

8 files changed

+169
-32
lines changed

8 files changed

+169
-32
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=deserialised/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/AStar.Dev.Utilities/AStar.Dev.Utilities.xml

Lines changed: 46 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AStar.Dev.Utilities/RegexExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public static bool ContainsAtLeastOneDigit(this string value)
3434
public static bool ContainsAtLeastOneSpecialCharacter(this string value)
3535
=> SpecialCharacterRegex().IsMatch(value);
3636

37-
[GeneratedRegex("^[a-z]+$", RegexOptions.CultureInvariant, 1_000)]
37+
[GeneratedRegex("(?=.*[a-z])", RegexOptions.CultureInvariant, 1_000)]
3838
private static partial Regex LowercaseLettersRegex();
3939

40-
[GeneratedRegex("^[A-Z]+$", RegexOptions.CultureInvariant, 1_000)]
40+
[GeneratedRegex("(?=.*[A-Z])", RegexOptions.CultureInvariant, 1_000)]
4141
private static partial Regex UppercaseLettersRegex();
4242

43-
[GeneratedRegex("^[A-Z]+$", RegexOptions.CultureInvariant, 1_000)]
43+
[GeneratedRegex("(?=.*[0-9])", RegexOptions.CultureInvariant, 1_000)]
4444
private static partial Regex DigitRegex();
4545

4646
[GeneratedRegex(@"[!-\/:-@[-`{-~]", RegexOptions.CultureInvariant, 1_000)]

tests/unit/AStar.Dev.Utilities.Tests.Unit/AStar.Dev.Utilities.Tests.Unit.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
<PrivateAssets>all</PrivateAssets>
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
</PackageReference>
20+
<PackageReference Include="JetBrains.Annotations" Version="2025.1.0-eap1" />
2021
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0"/>
2122
<PackageReference Include="Shouldly" Version="4.3.0"/>
23+
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="22.0.14" />
2224
<PackageReference Include="xunit" Version="2.9.3"/>
2325
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
2426
<PrivateAssets>all</PrivateAssets>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using AStar.Dev.Utilities;
2+
using JetBrains.Annotations;
3+
4+
namespace AStar.Dev.Utilities;
5+
6+
[TestSubject(typeof(EncryptionExtensions))]
7+
public class EncryptionExtensionsShould
8+
{
9+
10+
[Fact]
11+
public void EncryptTheTextAsExpected()
12+
=> "SomeIrrelevantText".Encrypt("oe3QnEe&@NnJ$$^L$1N@4WVKFayaAAbO", "sBA&3z*4cQf%$ww!").ShouldBe("PQGmSBnvuHDkD9fVoKrSOjQGRLWgCci5GXa0g2DM5L0=");
13+
14+
[Fact]
15+
public void DecryptTheTextAsExpected()
16+
=> "PQGmSBnvuHDkD9fVoKrSOjQGRLWgCci5GXa0g2DM5L0=".Decrypt("oe3QnEe&@NnJ$$^L$1N@4WVKFayaAAbO", "sBA&3z*4cQf%$ww!").ShouldBe("SomeIrrelevantText");
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.IO.Abstractions;
2+
using System.IO.Abstractions.TestingHelpers;
3+
using AStar.Dev.Utilities;
4+
using JetBrains.Annotations;
5+
6+
namespace AStar.Dev.Utilities;
7+
8+
[TestSubject(typeof(FileInfoExtensions))]
9+
public class FileInfoExtensionsShould()
10+
{
11+
[Theory]
12+
[InlineData("textfile.txt", false)]
13+
[InlineData("comma.csv", false)]
14+
[InlineData("filename.png", true)]
15+
[InlineData("filename.jpg", true)]
16+
[InlineData("filename.jpeg", true)]
17+
[InlineData("filename.jpEg", true)]
18+
[InlineData("filename.bmp", true)]
19+
[InlineData("filename.jfif", true)]
20+
[InlineData("filename.jif", true)]
21+
[InlineData("filename.gif", true)]
22+
[InlineData("filename.GIF", true)]
23+
public void ReturnExpectedResultFromIsImage(string filePath, bool expected)
24+
{
25+
var fileSystem = new MockFileSystem();
26+
var fileInfo = fileSystem.FileInfo.New(filePath);
27+
28+
fileInfo.IsImage().ShouldBe(expected);
29+
}
30+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using AStar.Dev.Utilities;
2+
using JetBrains.Annotations;
3+
4+
namespace AStar.Dev.Utilities;
5+
6+
[TestSubject(typeof(RegexExtensions))]
7+
public class RegexExtensionsShould
8+
{
9+
[Theory]
10+
[InlineData("SOMETEXT", false)]
11+
[InlineData("12345678", false)]
12+
[InlineData("SomeText", true)]
13+
public void ReturnTheExpectedResultForTheLowercaseLetterCheck(string stringToCheck, bool expected)
14+
=> stringToCheck.ContainsAtLeastOneLowercaseLetter().ShouldBe(expected);
15+
16+
[Theory]
17+
[InlineData("SOMETEXT", true)]
18+
[InlineData("sometext", false)]
19+
[InlineData("SomeText", true)]
20+
public void ReturnTheExpectedResultForTheUppercaseLetterCheck(string stringToCheck, bool expected)
21+
=> stringToCheck.ContainsAtLeastOneUppercaseLetter().ShouldBe(expected);
22+
23+
[Theory]
24+
[InlineData("SOMETEXT", false)]
25+
[InlineData("12345678", true)]
26+
[InlineData("SomeText1", true)]
27+
public void ReturnTheExpectedResultForTheAtleastOneDigitCheck(string stringToCheck, bool expected)
28+
=> stringToCheck.ContainsAtLeastOneDigit().ShouldBe(expected);
29+
30+
[Theory]
31+
[InlineData("SomeText", false)]
32+
[InlineData("SomeText!", true)]
33+
[InlineData("Some-Text", true)]
34+
[InlineData("Some\\Text", true)]
35+
[InlineData("Some/Text", true)]
36+
[InlineData("Some:Text", true)]
37+
[InlineData("Some@Text", true)]
38+
[InlineData("Some`Text", true)]
39+
[InlineData("Some{Text", true)]
40+
[InlineData("Some}Text", true)]
41+
[InlineData("Some~Text", true)]
42+
public void ReturnTheExpectedResultForTheAtLeastOneSpecialCharacterCheck(string stringToCheck, bool expected)
43+
=> stringToCheck.ContainsAtLeastOneSpecialCharacter().ShouldBe(expected);
44+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using AStar.Dev.Utilities;
2+
using JetBrains.Annotations;
3+
4+
namespace AStar.Dev.Utilities;
5+
6+
[TestSubject(typeof(StringExtensions))]
7+
public class StringExtensionsTest
8+
{
9+
10+
[Theory]
11+
[InlineData("", false)]
12+
[InlineData("textfile.txt", false)]
13+
[InlineData("comma.csv", false)]
14+
[InlineData("filename.png", true)]
15+
[InlineData("filename.jpg", true)]
16+
[InlineData("filename.jpeg", true)]
17+
[InlineData("filename.jpEg", true)]
18+
[InlineData("filename.bmp", true)]
19+
[InlineData("filename.jfif", true)]
20+
[InlineData("filename.jif", true)]
21+
[InlineData("filename.gif", true)]
22+
[InlineData("filename.GIF", true)]
23+
public void IsImageShouldReturnExpectedResults(string fileName, bool expected)
24+
=> fileName.IsImage().ShouldBe(expected);
25+
}

0 commit comments

Comments
 (0)