-
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.
Added Unit tests + updated FluentAssertions package.
- Loading branch information
Showing
6 changed files
with
146 additions
and
30 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
77 changes: 77 additions & 0 deletions
77
Raccoon.Ninja.AzFn.DataApi.Tests/ExtensionMethods/HttpRequestExtensionsTests.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,77 @@ | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Primitives; | ||
using Raccoon.Ninja.AzFn.DataApi.ExtensionMethods; | ||
|
||
namespace Raccoon.Ninja.AzFn.DataApi.Tests.ExtensionMethods; | ||
|
||
public class HttpRequestExtensionsTests | ||
{ | ||
[Fact] | ||
public void TryGetReadSinceParam_NoParameter_ReturnsNull() | ||
{ | ||
// Arrange | ||
var context = new DefaultHttpContext(); | ||
var request = context.Request; | ||
|
||
// Act | ||
var result = request.TryGetReadSinceParam(); | ||
|
||
// Assert | ||
result.Should().BeNull(); | ||
} | ||
|
||
[Fact] | ||
public void TryGetReadSinceParam_InvalidParameter_ReturnsNull() | ||
{ | ||
// Arrange | ||
var context = new DefaultHttpContext(); | ||
var request = context.Request; | ||
request.QueryString = new QueryString("?readSince=notANumber"); | ||
|
||
// Act | ||
var result = request.TryGetReadSinceParam(); | ||
|
||
// Assert | ||
result.Should().BeNull(); | ||
} | ||
|
||
[Fact] | ||
public void TryGetReadSinceParam_ValidParameter_ReturnsLongValue() | ||
{ | ||
// Arrange | ||
var context = new DefaultHttpContext(); | ||
var request = context.Request; | ||
request.QueryString = new QueryString("?readSince=123456"); | ||
|
||
// Act | ||
var result = request.TryGetReadSinceParam(); | ||
|
||
// Assert | ||
result.Should().NotBeNull(); | ||
result.Should().Be(123456L); | ||
} | ||
|
||
[Fact] | ||
public void TryGetReadSinceParam_ValidParameterSetThroughQueryProperty_ReturnsLongValue() | ||
{ | ||
// Arrange | ||
var context = new DefaultHttpContext(); | ||
var request = context.Request; | ||
|
||
// Setting Query directly using a dictionary. | ||
// Although Query is read-only, we can reassign it using the constructor of QueryCollection. | ||
var queryDictionary = new Dictionary<string, StringValues> | ||
{ | ||
{ "readSince", "987654" } | ||
}; | ||
request.QueryString = QueryString.Create(queryDictionary); | ||
|
||
// Act | ||
var result = request.TryGetReadSinceParam(); | ||
|
||
// Assert | ||
result.Should().NotBeNull(); | ||
result.Should().Be(987654L); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Raccoon.Ninja.AzFn.DataApi.Tests/Raccoon.Ninja.AzFn.DataApi.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,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"/> | ||
<PackageReference Include="FluentAssertions" Version="6.12.2"/> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/> | ||
<PackageReference Include="xunit" Version="2.5.3"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Raccoon.Ninja.AzFn.DataApi\Raccoon.Ninja.AzFn.DataApi.csproj"/> | ||
</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
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
48 changes: 24 additions & 24 deletions
48
Raccoon.Ninja.Domain.Core.Tests/Raccoon.Ninja.Domain.Core.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 |
---|---|---|
@@ -1,26 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>disable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" /> | ||
<PackageReference Include="xunit" Version="2.8.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Raccoon.Ninja.Domain.Core\Raccoon.Ninja.Domain.Core.csproj" /> | ||
<ProjectReference Include="..\Raccoon.Ninja.TestHelpers\Raccoon.Ninja.TestHelpers.csproj" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>disable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.12.2"/> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0"/> | ||
<PackageReference Include="xunit" Version="2.8.1"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Raccoon.Ninja.Domain.Core\Raccoon.Ninja.Domain.Core.csproj"/> | ||
<ProjectReference Include="..\Raccoon.Ninja.TestHelpers\Raccoon.Ninja.TestHelpers.csproj"/> | ||
</ItemGroup> | ||
</Project> |