-
Notifications
You must be signed in to change notification settings - Fork 4
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 for LoginService class
- v2024.12.27.10
- v2024.9.7.8
- v2024.2.24.160
- v2023.11.25.145
- v2023.8.27.129
- v2023.7.22.101
- v2023.7.7.99
- v2023.6.30.98
- v2023.4.25.130
- v2022.11.20.108
- v2022.10.4.87
- v2022.10.2.84
- v2022.9.3.59
- v2022.8.7.27
- v2022.6.11.754
- v2021.11.25.434
- v2021.11.7.392
- v2021.10.4.342
- v2021.8.15.305
- v2021.6.13.293
- v2021.5.16.265
- v2021.5.1.256
- v2021.4.11.234
- v2021.3.27.223
- v2021.3.13.194
- v2020.12.29.179
- v2020.12.22.151
- v2020.12.11.114
- v2020.11.20.108
- v2020.08.23.62
- v2020.8.8.156
- v2020.7.6.155
- v2020.4.19.150
- v2019.9.29.149
- v2019.9.25.148
- v2019.9.9.142
- v2019.8.24.141
- v2019.6.2.127
- v2019.5.31.126
- v1.4.3.742
- v1.4.2.695
- v1.4.2.681
- v1.4.1.676
- v1.4.0.537
- v1.3.0.521
- v1.2.0.490
- v1.1.0.476
- v1.0.0.466
Duco
committed
May 31, 2019
1 parent
50b870e
commit c8e8e1f
Showing
3 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
src/HttPlaceholder.Tests/Authorization/LoginServiceFacts.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,98 @@ | ||
using Ducode.Essentials.Mvc.TestUtilities; | ||
using HttPlaceholder.Authorization.Implementations; | ||
using HttPlaceholder.Models; | ||
using HttPlaceholder.Services; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Internal; | ||
using Microsoft.Extensions.ObjectPool; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace HttPlaceholder.Tests.Authorization | ||
{ | ||
[TestClass] | ||
public class LoginServiceFacts | ||
{ | ||
private readonly Dictionary<string, string> _cookies = new Dictionary<string, string>(); | ||
private readonly Dictionary<string, string> _config = new Dictionary<string, string>(); | ||
private readonly Mock<IConfigurationService> _configurationServiceMock = new Mock<IConfigurationService>(); | ||
private readonly MockHttpContext _mockHttpContext = new MockHttpContext(); | ||
private LoginService _service; | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
var accessorMock = new Mock<IHttpContextAccessor>(); | ||
accessorMock | ||
.Setup(m => m.HttpContext) | ||
.Returns(_mockHttpContext); | ||
|
||
_configurationServiceMock | ||
.Setup(m => m.GetConfiguration()) | ||
.Returns(_config); | ||
|
||
_mockHttpContext | ||
.HttpRequestMock | ||
.Setup(m => m.Cookies) | ||
.Returns(() => new RequestCookieCollection(_cookies)); | ||
|
||
_service = new LoginService(_configurationServiceMock.Object, accessorMock.Object); | ||
} | ||
|
||
[TestMethod] | ||
public void LoginService_CheckLoginCookie_NoUsernameAndPasswordSet_ShouldReturnTrue() | ||
{ | ||
// Act | ||
bool result = _service.CheckLoginCookie(); | ||
|
||
// Assert | ||
Assert.IsTrue(result); | ||
} | ||
|
||
[TestMethod] | ||
public void LoginService_CheckLoginCookie_UsernameAndPasswordSet_NoCookieSet_ShouldReturnFalse() | ||
{ | ||
// Arrange | ||
_config.Add(Constants.ConfigKeys.ApiUsernameKey, "user"); | ||
_config.Add(Constants.ConfigKeys.ApiPasswordKey, "pass"); | ||
|
||
// Act | ||
bool result = _service.CheckLoginCookie(); | ||
|
||
// Assert | ||
Assert.IsFalse(result); | ||
} | ||
|
||
[TestMethod] | ||
public void LoginService_CheckLoginCookie_UsernameAndPasswordSet_HashIncorrect_ShouldReturnFalse() | ||
{ | ||
// Arrange | ||
_config.Add(Constants.ConfigKeys.ApiUsernameKey, "user"); | ||
_config.Add(Constants.ConfigKeys.ApiPasswordKey, "pass"); | ||
_cookies.Add(Constants.CookieKeys.LoginCookieKey, "INCORRECT"); | ||
|
||
// Act | ||
bool result = _service.CheckLoginCookie(); | ||
|
||
// Assert | ||
Assert.IsFalse(result); | ||
} | ||
|
||
[TestMethod] | ||
public void LoginService_CheckLoginCookie_UsernameAndPasswordSet_HashCorrect_ShouldReturnTrue() | ||
{ | ||
// Arrange | ||
_config.Add(Constants.ConfigKeys.ApiUsernameKey, "user"); | ||
_config.Add(Constants.ConfigKeys.ApiPasswordKey, "pass"); | ||
_cookies.Add(Constants.CookieKeys.LoginCookieKey, "qkUYd4wTaLeznD/nN1v9ei9/5XUekWt1hyOctq3bQZ9DMhSk7FJz+l1ILk++kyYlu+VguxVcuEC9R4Ryk763GA=="); | ||
|
||
// Act | ||
bool result = _service.CheckLoginCookie(); | ||
|
||
// Assert | ||
Assert.IsTrue(result); | ||
} | ||
} | ||
} |
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,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("HttPlaceholder.Tests")] |