|
| 1 | +using Xunit; |
| 2 | +using JsonApiDotNetCore.Builders; |
| 3 | +using Microsoft.Extensions.DependencyInjection; |
| 4 | +using JsonApiDotNetCore.Extensions; |
| 5 | +using JsonApiDotNetCore.Configuration; |
| 6 | +using Microsoft.EntityFrameworkCore; |
| 7 | +using JsonApiDotNetCore.Data; |
| 8 | +using JsonApiDotNetCore.Internal; |
| 9 | +using Microsoft.AspNetCore.Http; |
| 10 | +using JsonApiDotNetCore.Services; |
| 11 | +using JsonApiDotNetCoreExample.Data; |
| 12 | +using Microsoft.Extensions.Caching.Memory; |
| 13 | +using JsonApiDotNetCoreExample.Models; |
| 14 | + |
| 15 | +namespace JsonApiDotNetCoreExampleTests.Unit.Extensions |
| 16 | +{ |
| 17 | + public class IServiceCollectionExtensionsTests |
| 18 | + { |
| 19 | + [Fact] |
| 20 | + public void AddJsonApiInternals_Adds_All_Required_Services() |
| 21 | + { |
| 22 | + // arrange |
| 23 | + var services = new ServiceCollection(); |
| 24 | + var jsonApiOptions = new JsonApiOptions(); |
| 25 | + |
| 26 | + services.AddDbContext<AppDbContext>(options => |
| 27 | + { |
| 28 | + options.UseMemoryCache(new MemoryCache(new MemoryCacheOptions())); |
| 29 | + }, ServiceLifetime.Transient); |
| 30 | + |
| 31 | + // act |
| 32 | + services.AddJsonApiInternals<AppDbContext>(jsonApiOptions); |
| 33 | + var provider = services.BuildServiceProvider(); |
| 34 | + |
| 35 | + // assert |
| 36 | + Assert.NotNull(provider.GetService<DbContext>()); |
| 37 | + Assert.NotNull(provider.GetService(typeof(IEntityRepository<TodoItem>))); |
| 38 | + Assert.NotNull(provider.GetService<JsonApiOptions>()); |
| 39 | + Assert.NotNull(provider.GetService<IContextGraph>()); |
| 40 | + Assert.NotNull(provider.GetService<IJsonApiContext>()); |
| 41 | + Assert.NotNull(provider.GetService<IHttpContextAccessor>()); |
| 42 | + Assert.NotNull(provider.GetService<IMetaBuilder>()); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments