Skip to content

Commit

Permalink
extensions package for a named client
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasjurasek committed Jan 19, 2021
1 parent 69ab4f5 commit c1219b7
Showing 1 changed file with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,28 @@ public void AddDeliveryNamedClient_DeliveryOptions_GetNoNamedClientNull()
}

[Fact]
public void AddDeliveryNamedClient_WithNamedTypeProvider_GetNamedClient()
public void AddDeliveryNamedClient_WithNamedTypeProvider_GetNamedTypeProvider()
{
A.CallTo(() => _customServiceProvider.GetService<ITypeProvider>("named"))
.Returns(new FakeTypeProvider());
.Returns(new FakeNamedTypeProvider());
_serviceCollection.AddSingleton(_customServiceProvider);
_serviceCollection.AddDeliveryClient("named", new DeliveryOptions() { ProjectId = Guid.NewGuid().ToString() });
var sp = _serviceCollection.BuildServiceProvider();

var factory = sp.GetRequiredService<IDeliveryClientFactory>();
var client = factory.Get("named");

var typeProviderType = ((DeliveryClient)client).TypeProvider.GetType();

typeProviderType.Should().Be<FakeNamedTypeProvider>();
}

[Fact]
public void AddDeliveryNamedClient_WithTypeProvider_GetTypeProvider()
{
A.CallTo(() => _customServiceProvider.GetService<ITypeProvider>("named"))
.Returns(null);
_serviceCollection.AddSingleton<ITypeProvider, FakeTypeProvider>();
_serviceCollection.AddSingleton(_customServiceProvider);
_serviceCollection.AddDeliveryClient("named", new DeliveryOptions() { ProjectId = Guid.NewGuid().ToString() });
var sp = _serviceCollection.BuildServiceProvider();
Expand All @@ -138,6 +156,24 @@ public void AddDeliveryNamedClient_WithNamedTypeProvider_GetNamedClient()
typeProviderType.Should().Be<FakeTypeProvider>();
}

[Fact]
public void AddDeliveryNamedClient_WithNamedAndNonamedTypeProvider_GetNamedTypePovider()
{
A.CallTo(() => _customServiceProvider.GetService<ITypeProvider>("named"))
.Returns(new FakeNamedTypeProvider());
_serviceCollection.AddSingleton<ITypeProvider, FakeTypeProvider>();
_serviceCollection.AddSingleton(_customServiceProvider);
_serviceCollection.AddDeliveryClient("named", new DeliveryOptions() { ProjectId = Guid.NewGuid().ToString() });
var sp = _serviceCollection.BuildServiceProvider();

var factory = sp.GetRequiredService<IDeliveryClientFactory>();
var client = factory.Get("named");

var typeProviderType = ((DeliveryClient)client).TypeProvider.GetType();

typeProviderType.Should().Be<FakeNamedTypeProvider>();
}

private class FakeTypeProvider : ITypeProvider
{
public string GetCodename(Type contentType)
Expand All @@ -151,5 +187,19 @@ public Type GetType(string contentType)
}
}

private class FakeNamedTypeProvider : ITypeProvider
{
public string GetCodename(Type contentType)
{
throw new NotImplementedException();
}

public Type GetType(string contentType)
{
throw new NotImplementedException();
}
}


}
}

0 comments on commit c1219b7

Please sign in to comment.