parent
cc255de979
commit
0bbf0f9bb9
@ -0,0 +1,49 @@
|
||||
using Dto;
|
||||
using Model;
|
||||
|
||||
namespace ApiMappeur;
|
||||
|
||||
public static class ActivityMappeur
|
||||
{
|
||||
/*public static ActivityDto ToDto(this Activity activity)
|
||||
{
|
||||
return new ActivityDto
|
||||
{
|
||||
Id = activity.Id,
|
||||
Name = activity.Name,
|
||||
Type = activity.Type,
|
||||
Date = activity.Date,
|
||||
Duration = activity.EndTime - activity.StartTime,
|
||||
Distance = activity.Distance,
|
||||
Elevation = activity.Elevation,
|
||||
AverageSpeed = activity.AverageSpeed,
|
||||
AverageHeartRate = activity.AverageHeartRate,
|
||||
Calories = activity.Calories,
|
||||
Description = activity.Description,
|
||||
Gpx = activity.Gpx,
|
||||
Image = activity.Image,
|
||||
AthleteId = activity.AthleteId
|
||||
};
|
||||
}
|
||||
|
||||
public static Activity ToModel(this ActivityDto activityDto)
|
||||
{
|
||||
return new Activity
|
||||
{
|
||||
Id = activityDto.Id,
|
||||
Name = activityDto.Name,
|
||||
Type = activityDto.Type,
|
||||
Date = activityDto.Date,
|
||||
Duration = activityDto.Duration,
|
||||
Distance = activityDto.Distance,
|
||||
Elevation = activityDto.Elevation,
|
||||
AverageSpeed = activityDto.AverageSpeed,
|
||||
AverageHeartRate = activityDto.AverageHeartRate,
|
||||
Calories = activityDto.Calories,
|
||||
Description = activityDto.Description,
|
||||
Gpx = activityDto.Gpx,
|
||||
Image = activityDto.Image,
|
||||
AthleteId = activityDto.AthleteId
|
||||
};
|
||||
}*/
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
namespace ApiMappeur;
|
||||
using Model.Repository;
|
||||
|
||||
namespace Model;
|
||||
|
||||
public static class EnumMappeur
|
||||
{
|
||||
public static Shared.AthleteOrderCriteria ToEnum(this string value)
|
||||
public static Shared.AthleteOrderCriteria ToEnum(this IUserRepository repository, string? value)
|
||||
{
|
||||
return value switch
|
||||
{
|
@ -0,0 +1,9 @@
|
||||
using Model.Repository;
|
||||
|
||||
namespace Model.Manager;
|
||||
|
||||
public interface IDataManager
|
||||
{
|
||||
IUserRepository UserRepository { get; }
|
||||
IActivityRepository ActivityRepository { get; }
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using Shared;
|
||||
|
||||
namespace Model;
|
||||
namespace Model.Repository;
|
||||
|
||||
public interface IActivityService
|
||||
public interface IActivityRepository
|
||||
{
|
||||
public Task<IEnumerable<Activity>> GetActivities(int index, int count, ActivityOrderCriteria criteria, bool descending = false);
|
||||
public Task<Activity?> GetActivityByIdAsync(int id);
|
@ -0,0 +1,12 @@
|
||||
namespace Shared;
|
||||
|
||||
public interface IGenericRepository<T>
|
||||
{
|
||||
Task<IEnumerable<T>> GetItems(int index, int count, string? orderingProperty = null, bool descending = false);
|
||||
Task<T?> GetItemById(int id);
|
||||
Task<T?> UpdateItem(int oldItem, T newItem);
|
||||
Task<T?> AddItem(T item);
|
||||
Task<bool> DeleteItem(int item);
|
||||
Task<int> GetNbItems();
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
using Model;
|
||||
using Model.Repository;
|
||||
using Shared;
|
||||
|
||||
namespace StubAPI;
|
||||
|
||||
public class ActivityService: IActivityRepository
|
||||
{
|
||||
public async Task<IEnumerable<Activity>> GetActivities(int index, int count, ActivityOrderCriteria criteria, bool descending = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Activity?> GetActivityByIdAsync(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Activity?> AddActivity(Activity activity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Activity?> UpdateActivity(int id, Activity activity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteActivity(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<int> GetNbItems()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using Model.Manager;
|
||||
using Model.Repository;
|
||||
|
||||
namespace StubAPI;
|
||||
|
||||
public class StubData : IDataManager
|
||||
{
|
||||
public IUserRepository UserRepository { get; }
|
||||
public IActivityRepository ActivityRepository { get; }
|
||||
|
||||
public StubData()
|
||||
{
|
||||
UserRepository = new UserService();
|
||||
ActivityRepository = new ActivityService();
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4"/>
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.0.4"/>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\HeartTrackAPI\HeartTrackAPI.csproj" />
|
||||
<ProjectReference Include="..\..\Model\Model.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
<ProjectReference Include="..\..\StubAPI\StubAPI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,12 @@
|
||||
namespace ClientTests;
|
||||
|
||||
public class HttpClientManager
|
||||
{
|
||||
protected readonly HttpClient _httpClient;
|
||||
|
||||
public HttpClientManager(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_httpClient.BaseAddress = new Uri("https://localhost:7252");
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4"/>
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.0.4"/>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\HeartTrackAPI\HeartTrackAPI.csproj" />
|
||||
<ProjectReference Include="..\..\..\Model\Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,124 @@
|
||||
using Dto;
|
||||
using HeartTrackAPI.Controllers;
|
||||
using HeartTrackAPI.Request;
|
||||
using HeartTrackAPI.Responce;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Model.Manager;
|
||||
using Model.Repository;
|
||||
using StubAPI;
|
||||
|
||||
namespace UnitTestApi;
|
||||
|
||||
[TestClass]
|
||||
public class UserControllerTest
|
||||
{
|
||||
private readonly IDataManager StubDataManager;
|
||||
private readonly UsersController _usersController;
|
||||
|
||||
public UserControllerTest()
|
||||
{
|
||||
StubDataManager = new StubData();
|
||||
_usersController = new UsersController(new NullLogger<UsersController>(), StubDataManager);
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Get_ReturnsPageResponse_WhenRequestIsValid()
|
||||
{
|
||||
// Arrange
|
||||
var request = new PageRequest
|
||||
{
|
||||
Index = 0,
|
||||
Count = 10,
|
||||
OrderingPropertyName = "Id",
|
||||
Descending = false
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = _usersController.Get(request).Result as OkObjectResult;
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.IsInstanceOfType(result.Value, typeof(PageResponse<UserDto>));
|
||||
}
|
||||
/*
|
||||
[TestMethod]
|
||||
public void GetById_ReturnsUserDto_WhenRequestIsValid()
|
||||
{
|
||||
// Arrange
|
||||
var id = 1;
|
||||
|
||||
// Act
|
||||
var result = _usersController.GetById(id).Result as OkObjectResult;
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.IsInstanceOfType(result.Value, typeof(UserDto));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetById_Returns404_WhenIdIsInvalid()
|
||||
{
|
||||
// Arrange
|
||||
var id = 0;
|
||||
|
||||
// Act
|
||||
var result = _usersController.GetById(id).Result as NotFoundResult;
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetById_Returns500_WheExceptionIsThrown()
|
||||
{
|
||||
// Arrange
|
||||
var id = 0;
|
||||
|
||||
// Act
|
||||
var result = _usersController.GetById(id).Result as StatusCodeResult;
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(500, result.StatusCode);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Count_ReturnsInt_WhenRequestIsValid()
|
||||
{
|
||||
// Act
|
||||
var result = _usersController.Count().Result as OkObjectResult;
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.IsInstanceOfType(result.Value, typeof(int));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Count_Returns500_WheExceptionIsThrown()
|
||||
{
|
||||
// Act
|
||||
var result = _usersController.Count().Result as StatusCodeResult;
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(500, result.StatusCode);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Update_ReturnsUserDto_WhenRequestIsValid()
|
||||
{
|
||||
// Arrange
|
||||
var id = 1;
|
||||
var user = new UserDto
|
||||
{
|
||||
Id = 1,
|
||||
FirstName = "John",
|
||||
LastName = "Doe",
|
||||
Email = "toto@eoeo.fr",
|
||||
};
|
||||
|
||||
}*/
|
||||
|
||||
}
|
Loading…
Reference in new issue