2023-03-13 18:36:59 +02:00
|
|
|
|
// Copyright (c) 2020 Tudor Stanciu
|
|
|
|
|
|
2023-03-13 23:27:13 +02:00
|
|
|
|
using System;
|
2023-03-13 18:36:59 +02:00
|
|
|
|
using Tuitio.Application.Stores;
|
2023-03-09 20:31:17 +02:00
|
|
|
|
using Tuitio.Domain.Models;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Tuitio.Application.Tests
|
|
|
|
|
{
|
|
|
|
|
public class TokenStoreTests
|
|
|
|
|
{
|
2023-04-08 17:55:36 +03:00
|
|
|
|
private Token GetMockedToken()
|
|
|
|
|
{
|
|
|
|
|
var token = new Token(1);
|
|
|
|
|
token.SetUserData(0, "test.tuitio", "tuitio", "user", "user.tuitio@lab.com", Guid.NewGuid().ToString(), null, null, null);
|
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 20:31:17 +02:00
|
|
|
|
[Fact]
|
|
|
|
|
public void Set_ShouldSetTokenInStore()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
var key = "user001";
|
2023-04-08 17:55:36 +03:00
|
|
|
|
var expected = GetMockedToken();
|
|
|
|
|
|
2023-03-09 20:31:17 +02:00
|
|
|
|
var store = new TokenStore();
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
store.Set(key, expected);
|
|
|
|
|
var actual = store.Get(key);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.Equal(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Remove_ShouldRemoveTokenFromStore()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
var key = "user001";
|
2023-04-08 17:55:36 +03:00
|
|
|
|
var mock = GetMockedToken();
|
2023-03-09 20:31:17 +02:00
|
|
|
|
var store = new TokenStore();
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
store.Set(key, mock);
|
|
|
|
|
store.Remove(key);
|
|
|
|
|
var actual = store.Get(key);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.True(actual == null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|