-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8eb6d70
commit 4275b6f
Showing
3 changed files
with
55 additions
and
7 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
47 changes: 47 additions & 0 deletions
47
tests/BitzArt.Blazor.Cookies.Tests/JsInteropCookieServiceTests.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,47 @@ | ||
using Microsoft.JSInterop; | ||
using Moq; | ||
|
||
namespace BitzArt.Blazor.Cookies.Tests; | ||
|
||
public class JsInteropCookieServiceTests | ||
{ | ||
[Fact] | ||
public async Task GetAsync_WithCookieNotPresent_ShouldReturnNull() | ||
{ | ||
// Arrange | ||
var jsRuntime = new Mock<IJSRuntime>(); | ||
jsRuntime.Setup(x => x.InvokeAsync<string>("eval", It.IsAny<object[]>())) | ||
.ReturnsAsync(""); | ||
|
||
var sut = new JsInteropCookieService(jsRuntime.Object); | ||
|
||
// Act | ||
var result = await sut.GetAsync("my-cookie"); | ||
|
||
// Assert | ||
Assert.Null(result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("my-cookie", "")] | ||
[InlineData("my-cookie", "my-value")] | ||
[InlineData("my-cookie", "value=123")] | ||
[InlineData("my-cookie", "value_a=a value_b=b")] | ||
[InlineData("my-cookie", "!@#$%^&*()-_=_-)(*&^%$#@!")] | ||
[InlineData("my-cookie", "abc !@#$%^&*()-_ = _-)(*&^%$#@! def 123456789 ghi")] | ||
public async Task GetAsync_WithCookiePresent_ShouldReturnValue(string cookieName, string cookieValue) | ||
{ | ||
// Arrange | ||
var jsRuntime = new Mock<IJSRuntime>(); | ||
jsRuntime.Setup(x => x.InvokeAsync<string>("eval", It.IsAny<object[]>())) | ||
.ReturnsAsync($"{cookieName}={cookieValue}; path=/"); | ||
|
||
var sut = new JsInteropCookieService(jsRuntime.Object); | ||
|
||
// Act | ||
var result = await sut.GetAsync(cookieName); | ||
|
||
// Assert | ||
Assert.Equal(cookieValue, result?.Value); | ||
} | ||
} |