-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extensions package for a named client
- Loading branch information
1 parent
edb5860
commit c6d0459
Showing
2 changed files
with
129 additions
and
0 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
91 changes: 91 additions & 0 deletions
91
...Delivery.Extensions.Autofac.DependencyInjection.Tests/ServiceCollectionExtensionsTests.cs
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,91 @@ | ||
using Kentico.Kontent.Delivery.Abstractions; | ||
using Kentico.Kontent.Delivery.Caching; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Kentico.Kontent.Delivery.Extensions.Autofac.DependencyInjection.Extensions; | ||
using System; | ||
using Xunit; | ||
using FluentAssertions; | ||
using Autofac; | ||
using FakeItEasy; | ||
|
||
namespace Kentico.Kontent.Delivery.Extensions.Autofac.DependencyInjection.Tests | ||
{ | ||
public class ServiceCollectionExtensionsTests | ||
{ | ||
private readonly ServiceCollection _serviceCollection; | ||
private readonly IComponentContext _container; | ||
|
||
public ServiceCollectionExtensionsTests() | ||
{ | ||
_serviceCollection = new ServiceCollection(); | ||
_container = A.Fake<IComponentContext>(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(CacheTypeEnum.Memory)] | ||
[InlineData(CacheTypeEnum.Distributed)] | ||
public void AddDeliveryNamedClient_CacheWithDeliveryCacheOptions_GetNamedClient(CacheTypeEnum cacheType) | ||
{ | ||
_serviceCollection.AddSingleton(_container); | ||
_serviceCollection.AddDeliveryClient("named", new DeliveryOptions() { ProjectId = Guid.NewGuid().ToString() }); | ||
_serviceCollection.AddDeliveryClientCache("named", new DeliveryCacheOptions() | ||
{ | ||
CacheType = cacheType | ||
}); | ||
|
||
var sp = _serviceCollection.BuildServiceProvider(); | ||
var factory = sp.GetRequiredService<IDeliveryClientFactory>(); | ||
|
||
var client = factory.Get("named"); | ||
|
||
client.Should().NotBeNull(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(CacheTypeEnum.Memory)] | ||
[InlineData(CacheTypeEnum.Distributed)] | ||
public void AddDeliveryNamedClient_CacheWithDeliveryCacheOptions_GetNull(CacheTypeEnum cacheType) | ||
{ | ||
_serviceCollection.AddSingleton(_container); | ||
_serviceCollection.AddDeliveryClient("named", new DeliveryOptions() { ProjectId = Guid.NewGuid().ToString() }); | ||
_serviceCollection.AddDeliveryClientCache("named", new DeliveryCacheOptions() | ||
{ | ||
CacheType = cacheType | ||
}); | ||
|
||
var sp = _serviceCollection.BuildServiceProvider(); | ||
var factory = sp.GetRequiredService<IDeliveryClientFactory>(); | ||
|
||
var client = factory.Get("WrongName"); | ||
|
||
client.Should().BeNull(); | ||
} | ||
|
||
[Fact] | ||
public void AddDeliveryNamedClient_DeliveryOptions_GetNamedClient() | ||
{ | ||
_serviceCollection.AddSingleton(_container); | ||
_serviceCollection.AddDeliveryClient("named", new DeliveryOptions() { ProjectId = Guid.NewGuid().ToString() }); | ||
var sp = _serviceCollection.BuildServiceProvider(); | ||
|
||
var factory = sp.GetRequiredService<IDeliveryClientFactory>(); | ||
var client = factory.Get("named"); | ||
|
||
client.Should().NotBeNull(); | ||
} | ||
|
||
[Fact] | ||
public void AddDeliveryNamedClient_DeliveryOptions_GetNull() | ||
{ | ||
_serviceCollection.AddSingleton(_container); | ||
_serviceCollection.AddDeliveryClient("named", new DeliveryOptions() { ProjectId = Guid.NewGuid().ToString() }); | ||
var sp = _serviceCollection.BuildServiceProvider(); | ||
|
||
var factory = sp.GetRequiredService<IDeliveryClientFactory>(); | ||
var client = factory.Get("WrongName"); | ||
|
||
client.Should().BeNull(); | ||
} | ||
|
||
} | ||
} |