36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using Aya_Backend.Controllers;
|
|
using Aya_Backend.Data;
|
|
using Aya_Backend.Data.Repositories.UserRepositories;
|
|
using Aya_Backend.Tests.Data;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NUnit.Framework;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Aya_Backend.Tests
|
|
{
|
|
[TestFixture]
|
|
public class UserControllerTests
|
|
{
|
|
private readonly int validUserID = 2;
|
|
|
|
[Test]
|
|
public async Task GetUser_CorrectUserReturned()
|
|
{
|
|
var expected = MockData.Users.FirstOrDefault(u => u.ID == validUserID);
|
|
var mockContext = new MockRepository(MockData.Users, null, null);
|
|
var controller = new UserController(mockContext);
|
|
|
|
var result = await controller.GetUser(validUserID);
|
|
|
|
Assert.IsNotNull(result);
|
|
var objectResult = result as OkObjectResult;
|
|
Assert.IsNotNull(objectResult);
|
|
var modelResult = objectResult.Value as User;
|
|
Assert.IsNotNull(modelResult);
|
|
|
|
Assert.AreEqual(expected.ID, modelResult.ID);
|
|
Assert.AreEqual(expected.Username, modelResult.Username);
|
|
}
|
|
}
|
|
} |