session-companion/SessionCompanion/SessionCompanion.XUnitTests/UserServiceTest.cs

51 lines
1.3 KiB
C#
Raw Normal View History

2020-12-21 18:08:51 +01:00
using System;
using Xunit;
namespace SessionCompanion.XUnitTests
{
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using SessionCompanion.Controllers;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.UserViewModels;
public class UserServiceTest
{
private UserController userController;
private Mock<IUserService> userServiceMock;
[SetUp]
public void Setup()
{
userServiceMock = new Mock<IUserService>();
UserViewModel test = new UserViewModel(){ Id = 1, Password = "123", Username = "test"};
this.userServiceMock.Setup(p => p.SearchUserByUsername("test")).ReturnsAsync(test);
this.userController = new UserController(this.userServiceMock.Object);
}
[Test]
public void ShouldReturnUserId()
{
var result = this.userController.Login("test", "123").Result;
Assert.AreEqual(1,result.Left);
}
[Test]
public void ShouldReturnUserName()
{
var result = this.userController.GetUserName(1).Result;
Assert.AreEqual("test", result.Left);
}
}
}