Skip to content

Commit 6eda1fd

Browse files
committed
add router injection test
1 parent 4dca346 commit 6eda1fd

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

JsonApiDotNetCoreTests/Extensions/Class1.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Xunit;
2+
using JsonApiDotNetCore.Routing;
3+
using JsonApiDotNetCore.Extensions;
4+
using JsonApiDotNetCoreTests.Helpers;
5+
6+
namespace JsonApiDotNetCoreTests.Extensions.UnitTests
7+
{
8+
// see example explanation on xUnit.net website:
9+
// https://xunit.github.io/docs/getting-started-dotnet-core.html
10+
public class IServiceCollectionExtensionsTests
11+
{
12+
[Fact]
13+
public void AddJsonApi_AddsRouterToServiceCollection()
14+
{
15+
// arrange
16+
var serviceCollection = new ServiceCollection();
17+
18+
// act
19+
serviceCollection.AddJsonApi(config => {});
20+
21+
// assert
22+
Assert.True(serviceCollection.ContainsType(typeof(Router)));
23+
}
24+
25+
}
26+
}

JsonApiDotNetCoreTests/Helpers/ServiceCollection.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
using System.Linq;
13
using System.Collections;
24
using System.Collections.Generic;
35
using Microsoft.Extensions.DependencyInjection;
@@ -10,5 +12,17 @@ IEnumerator IEnumerable.GetEnumerator()
1012
{
1113
return GetEnumerator();
1214
}
15+
16+
public bool ContainsType(Type type)
17+
{
18+
var ret = false;
19+
this.ForEach(sD => {
20+
if(sD.ServiceType == type)
21+
{
22+
ret = true;
23+
}
24+
});
25+
return ret;
26+
}
1327
}
1428
}

0 commit comments

Comments
 (0)