/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Caching/SqlServer/test/SqlServerCacheServicesExtensionsTest.cs
62 строки
2 KB
Pranav K
Use file scoped namespaces (#38076)
06 ноя 2021, 03:52
Не верифицирован
06 ноя 2021, 03:52
a450cb6
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Linq; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.DependencyInjection; using Moq; using Xunit; namespace Microsoft.Extensions.Caching.SqlServer; public class SqlServerCacheServicesExtensionsTest { [Fact] public void AddDistributedSqlServerCache_AddsAsSingleRegistrationService() { // Arrange var services = new ServiceCollection(); // Act SqlServerCachingServicesExtensions.AddSqlServerCacheServices(services); // Assert var serviceDescriptor = Assert.Single(services); Assert.Equal(typeof(IDistributedCache), serviceDescriptor.ServiceType); Assert.Equal(typeof(SqlServerCache), serviceDescriptor.ImplementationType); Assert.Equal(ServiceLifetime.Singleton, serviceDescriptor.Lifetime); } [Fact] public void AddDistributedSqlServerCache_ReplacesPreviouslyUserRegisteredServices() { // Arrange var services = new ServiceCollection(); services.AddScoped(typeof(IDistributedCache), sp => Mock.Of<IDistributedCache>()); // Act services.AddDistributedSqlServerCache(options => { options.ConnectionString = "Fake"; options.SchemaName = "Fake"; options.TableName = "Fake"; }); // Assert var serviceProvider = services.BuildServiceProvider(); var distributedCache = services.FirstOrDefault(desc => desc.ServiceType == typeof(IDistributedCache)); Assert.NotNull(distributedCache); Assert.Equal(ServiceLifetime.Scoped, distributedCache.Lifetime); Assert.IsType<SqlServerCache>(serviceProvider.GetRequiredService<IDistributedCache>()); } [Fact] public void AddDistributedSqlServerCache_allows_chaining() { var services = new ServiceCollection(); Assert.Same(services, services.AddDistributedSqlServerCache(_ => { })); } }