-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: test and improve DI extension method
- Loading branch information
1 parent
ffb6366
commit fdb33a0
Showing
3 changed files
with
65 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Reflection; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Gridify.Tests; | ||
|
||
public class DependencyInjectionTests | ||
{ | ||
|
||
[Fact] | ||
public void AddGridifyMappers_ShouldRegisterMappers() | ||
{ | ||
// Arrange | ||
var services = new ServiceCollection(); | ||
var assemblyMock = GetAssembly(); | ||
|
||
// Act | ||
services.AddGridifyMappers(assemblyMock); | ||
|
||
// Assert | ||
var serviceProvider = services.BuildServiceProvider(); | ||
serviceProvider.GetService<IGridifyMapper<TestEntity>>().Should().NotBeNull(); | ||
serviceProvider.GetService<IGridifyMapper<TestEntity2>>().Should().NotBeNull(); | ||
serviceProvider.GetService<TestMapper>().Should().BeNull(); | ||
services.Count.Should().Be(2); | ||
} | ||
|
||
private static Assembly GetAssembly() | ||
{ | ||
var assemblyMock = Substitute.For<Assembly>(); | ||
assemblyMock.GetTypes().Returns([ | ||
typeof(TestMapper), | ||
typeof(AnotherTestMapper), | ||
typeof(NonGridifyMapper), | ||
]); | ||
return assemblyMock; | ||
} | ||
public record TestEntity(string P1, string P2); | ||
|
||
public record TestEntity2(string P1, string P2); | ||
|
||
public class TestMapper : GridifyMapper<TestEntity>; | ||
|
||
public class AnotherTestMapper : GridifyMapper<TestEntity2>; | ||
|
||
|
||
// Non-Gridify types for testing | ||
public class NonGridifyMapper; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters