First commit. Include junk from template to remove
This commit is contained in:
53
tests/Application.UnitTests/Common/Mappings/MappingTests.cs
Normal file
53
tests/Application.UnitTests/Common/Mappings/MappingTests.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using AutoMapper;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Application.Common.Models;
|
||||
using Hutopy.Application.TodoItems.Queries.GetTodoItemsWithPagination;
|
||||
using Hutopy.Application.TodoLists.Queries.GetTodos;
|
||||
using Hutopy.Domain.Entities;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Hutopy.Application.UnitTests.Common.Mappings;
|
||||
|
||||
public class MappingTests
|
||||
{
|
||||
private readonly IConfigurationProvider _configuration;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public MappingTests()
|
||||
{
|
||||
_configuration = new MapperConfiguration(config =>
|
||||
config.AddMaps(Assembly.GetAssembly(typeof(IApplicationDbContext))));
|
||||
|
||||
_mapper = _configuration.CreateMapper();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldHaveValidConfiguration()
|
||||
{
|
||||
_configuration.AssertConfigurationIsValid();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase(typeof(TodoList), typeof(TodoListDto))]
|
||||
[TestCase(typeof(TodoItem), typeof(TodoItemDto))]
|
||||
[TestCase(typeof(TodoList), typeof(LookupDto))]
|
||||
[TestCase(typeof(TodoItem), typeof(LookupDto))]
|
||||
[TestCase(typeof(TodoItem), typeof(TodoItemBriefDto))]
|
||||
public void ShouldSupportMappingFromSourceToDestination(Type source, Type destination)
|
||||
{
|
||||
var instance = GetInstanceOf(source);
|
||||
|
||||
_mapper.Map(instance, source, destination);
|
||||
}
|
||||
|
||||
private object GetInstanceOf(Type type)
|
||||
{
|
||||
if (type.GetConstructor(Type.EmptyTypes) != null)
|
||||
return Activator.CreateInstance(type)!;
|
||||
|
||||
// Type without parameterless constructor
|
||||
return RuntimeHelpers.GetUninitializedObject(type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user