Skip to content

Commit

Permalink
uncomment jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
emrecoskun705 committed Sep 14, 2023
1 parent 95f1d2c commit 4a65e0f
Showing 1 changed file with 74 additions and 74 deletions.
148 changes: 74 additions & 74 deletions Unitagram.Identity.UnitTests/JwtServiceUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
// using System.Security.Claims;
// using AutoFixture;
// using FluentAssertions;
// using Microsoft.Extensions.Options;
// using Moq;
// using Unitagram.Application.Contracts.Identity;
// using Unitagram.Application.Models.Identity.Jwt;
// using Unitagram.Identity.Services;
//
// namespace Unitagram.Identity.UnitTests;
//
// public class JwtServiceUnitTests
// {
// private readonly IFixture _fixture = new Fixture();
// private readonly IJwtService _jwtService;
//
// public JwtServiceUnitTests()
// {
// var jwtSettings = new JwtSettings()
// {
// Issuer = "http://localhost:7164",
// Audience = "http://localhost:4200",
// ExpirationDays = 1,
// Key = "this is secret key for jwt",
// RefreshTokenValidityInDays = 7,
// };
//
// var optionsMock = new Mock<IOptions<JwtSettings>>();
// optionsMock.Setup(x => x.Value).Returns(jwtSettings);
//
// _jwtService = new JwtService(optionsMock.Object);
// }
//
// #region CreateJwtToken
//
// [Fact]
// public void CreateJwtToken_ReturnsValidJwtResponse()
// {
// // Arrange
// var jwtRequest = _fixture.Build<JwtRequest>().Create();
//
// //Act
// var jwtResponse = _jwtService.CreateJwtToken(jwtRequest);
//
// //Assert
// jwtResponse.Should().BeOfType<JwtResponse>();
// jwtResponse.Token.Should().NotBeNullOrEmpty();
// }
//
// #endregion
//
// #region GetPrincipleFromJwtToken
//
// [Fact]
// public void GetPrincipleFromJwtToken_ValidToken_ReturnsClaimsPrincipal()
// {
// // Arrange
// var jwtRequest = _fixture.Build<JwtRequest>().Create();
// var jwtResponse = _jwtService.CreateJwtToken(jwtRequest);
// var token = jwtResponse.Token;
//
// // Act
// var claimsPrincipal = _jwtService.GetPrincipleFromJwtToken(token);
//
// // Assert
// claimsPrincipal.Should().NotBeNull();
// claimsPrincipal.Should().BeOfType<ClaimsPrincipal>();
// }
//
// #endregion
//
//
//
// }
using System.Security.Claims;
using AutoFixture;
using FluentAssertions;
using Microsoft.Extensions.Options;
using Moq;
using Unitagram.Application.Contracts.Identity;
using Unitagram.Application.Models.Identity.Jwt;
using Unitagram.Identity.Services;

namespace Unitagram.Identity.UnitTests;

public class JwtServiceUnitTests
{
private readonly IFixture _fixture = new Fixture();
private readonly IJwtService _jwtService;

public JwtServiceUnitTests()
{
var jwtSettings = new JwtSettings()
{
Issuer = "http://localhost:7164",
Audience = "http://localhost:4200",
ExpirationDays = 1,
Key = "this is secret key for jwt",
RefreshTokenValidityInDays = 7,
};

var optionsMock = new Mock<IOptions<JwtSettings>>();
optionsMock.Setup(x => x.Value).Returns(jwtSettings);

_jwtService = new JwtService(optionsMock.Object);
}

#region CreateJwtToken

[Fact]
public void CreateJwtToken_ReturnsValidJwtResponse()
{
// Arrange
var jwtRequest = _fixture.Build<JwtRequest>().Create();

//Act
var jwtResponse = _jwtService.CreateJwtToken(jwtRequest);

//Assert
jwtResponse.Should().BeOfType<JwtResponse>();
jwtResponse.Token.Should().NotBeNullOrEmpty();
}

#endregion

#region GetPrincipleFromJwtToken

[Fact]
public void GetPrincipleFromJwtToken_ValidToken_ReturnsClaimsPrincipal()
{
// Arrange
var jwtRequest = _fixture.Build<JwtRequest>().Create();
var jwtResponse = _jwtService.CreateJwtToken(jwtRequest);
var token = jwtResponse.Token;

// Act
var claimsPrincipal = _jwtService.GetPrincipleFromJwtToken(token);

// Assert
claimsPrincipal.Should().NotBeNull();
claimsPrincipal.Should().BeOfType<ClaimsPrincipal>();
}

#endregion



}

0 comments on commit 4a65e0f

Please sign in to comment.