Skip to content

Commit

Permalink
Merge branch 'master' into merge/release/3.1-to-master
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/extensions@b55f0f8
  • Loading branch information
dougbu authored Oct 18, 2019
2 parents c21fc85 + c875abc commit f6bd0b0
Show file tree
Hide file tree
Showing 24 changed files with 211 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public DefaultCoreConfig()
.With(CsProjCoreToolchain.From(new NetCoreAppSettings("netcoreapp3.0", null, ".NET Core 3.0")))
#elif NETCOREAPP3_1
.With(CsProjCoreToolchain.From(new NetCoreAppSettings("netcoreapp3.1", null, ".NET Core 3.1")))
#elif NETCOREAPP5_0
.With(CsProjCoreToolchain.From(new NetCoreAppSettings("netcoreapp5.0", null, ".NET Core 5.0")))
#else
#error Target frameworks need to be updated.
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.Extensions.Internal
{
internal class TypeNameHelper
internal static class TypeNameHelper
{
private const char DefaultNestedTypeDelimiter = '+';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public MsBuildTargetTest(ITestOutputHelper output)

[Theory]
[InlineData(".csproj", ".cs")]
[InlineData(".fsproj", ".fs")]
[InlineData(".fsproj", ".fs", Skip = "https://github.com/aspnet/AspNetCore/issues/13303")]
public void GeneratesAssemblyAttributeFile(string projectExt, string sourceExt)
{
var testTfm = typeof(MsBuildTargetTest).Assembly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Microsoft.Extensions.Configuration
{
/// <summary>
/// IConfigurationBuilder extension methods for the chaind configuration provider.
/// Extension methods for adding <see cref="IConfiguration"/> to an <see cref="IConfigurationBuilder"/>.
/// </summary>
public static class ChainedBuilderExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public static ServiceDescriptor Singleton(
/// <summary>
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
/// <typeparamref name="TService"/>, <paramref name="implementationInstance"/>,
/// and the <see cref="ServiceLifetime.Scoped"/> lifetime.
/// and the <see cref="ServiceLifetime.Singleton"/> lifetime.
/// </summary>
/// <typeparam name="TService">The type of the service.</typeparam>
/// <param name="implementationInstance">The instance of the implementation.</param>
Expand All @@ -471,7 +471,7 @@ public static ServiceDescriptor Singleton<TService>(TService implementationInsta
/// <summary>
/// Creates an instance of <see cref="ServiceDescriptor"/> with the specified
/// <paramref name="serviceType"/>, <paramref name="implementationInstance"/>,
/// and the <see cref="ServiceLifetime.Scoped"/> lifetime.
/// and the <see cref="ServiceLifetime.Singleton"/> lifetime.
/// </summary>
/// <param name="serviceType">The type of the service.</param>
/// <param name="implementationInstance">The instance of the implementation.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,48 @@ public void ProviderScopeDisposeThrowsWhenOnlyDisposeAsyncImplemented()
exception.Message);
}

[Fact]
public void SingletonServiceCreatedFromFactoryIsDisposedWhenContainerIsDisposed()
{
// Arrange
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(_ => new FakeDisposable());
var serviceProvider = CreateServiceProvider(serviceCollection);

// Act
var service = serviceProvider.GetService<FakeDisposable>();
((IDisposable)serviceProvider).Dispose();

// Assert
Assert.True(service.IsDisposed);
}

[Fact]
public void SingletonServiceCreatedFromInstanceIsNotDisposedWhenContainerIsDisposed()
{
// Arrange
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(new FakeDisposable());
var serviceProvider = CreateServiceProvider(serviceCollection);

// Act
var service = serviceProvider.GetService<FakeDisposable>();
((IDisposable)serviceProvider).Dispose();

// Assert
Assert.False(service.IsDisposed);
}

private class FakeDisposable : IDisposable
{
public bool IsDisposed { get; private set; }

public void Dispose()
{
IsDisposed = true;
}
}

private class FakeMultipleServiceWithIEnumerableDependency: IFakeMultipleService
{
public FakeMultipleServiceWithIEnumerableDependency(IEnumerable<IFakeService> fakeServices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,22 @@ public bool UsePollingFileWatcher
{
if (_fileWatcher != null)
{
throw new InvalidOperationException($"Cannot modify {nameof(UsePollingFileWatcher)} once file watcher has been initialized.");
return false;
}

if (_usePollingFileWatcher == null)
{
ReadPollingEnvironmentVariables();
}

return _usePollingFileWatcher.Value;
return _usePollingFileWatcher ?? false;
}
set
{
if (_fileWatcher != null)
{
throw new InvalidOperationException($"Cannot modify {nameof(UsePollingFileWatcher)} once file watcher has been initialized.");
}
_usePollingFileWatcher = value;
}
set => _usePollingFileWatcher = value;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,63 @@ public async Task WildCardToken_RaisesEventsWhenFileSystemWatcherDoesNotFire()
}
}

[Fact]
public void UsePollingFileWatcher_FileWatcherNull_SetsSuccessfully()
{
// Arrange
using (var root = new DisposableFileSystem())
{
using (var provider = new PhysicalFileProvider(root.RootPath))
{
Assert.False(provider.UsePollingFileWatcher);

// Act / Assert
provider.UsePollingFileWatcher = true;
Assert.True(provider.UsePollingFileWatcher);
}
}
}

[Fact]
public void UsePollingFileWatcher_FileWatcherNotNull_SetterThrows()
{
// Arrange
using (var root = new DisposableFileSystem())
{
using (var fileSystemWatcher = new MockFileSystemWatcher(root.RootPath))
{
using (var physicalFilesWatcher = new PhysicalFilesWatcher(root.RootPath + Path.DirectorySeparatorChar, fileSystemWatcher, pollForChanges: false))
{
using (var provider = new PhysicalFileProvider(root.RootPath) { FileWatcher = physicalFilesWatcher })
{
// Act / Assert
Assert.Throws<InvalidOperationException>(() => { provider.UsePollingFileWatcher = true; });
}
}
}
}
}

[Fact]
public void UsePollingFileWatcher_FileWatcherNotNull_ReturnsFalse()
{
// Arrange
using (var root = new DisposableFileSystem())
{
using (var fileSystemWatcher = new MockFileSystemWatcher(root.RootPath))
{
using (var physicalFilesWatcher = new PhysicalFilesWatcher(root.RootPath + Path.DirectorySeparatorChar, fileSystemWatcher, pollForChanges: false))
{
using (var provider = new PhysicalFileProvider(root.RootPath) { FileWatcher = physicalFilesWatcher })
{
// Act / Assert
Assert.False(provider.UsePollingFileWatcher);
}
}
}
}
}

[Fact]
public void CreateFileWatcher_CreatesWatcherWithPollingAndActiveFlags()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Microsoft.Extensions.Hosting
{
/// <summary>
/// Allows consumers to be notified of application lifetime events.
/// Allows consumers to be notified of application lifetime events. This interface is not intended to be user-replaceable.
/// </summary>
public interface IHostApplicationLifetime
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private async Task ExecuteShutdownTest(string testName, string shutdownMechanic)
RuntimeFlavor.CoreClr,
RuntimeArchitecture.x64)
{
TargetFramework = Tfm.NetCoreApp31,
TargetFramework = Tfm.NetCoreApp50,
ApplicationType = ApplicationType.Portable,
PublishApplicationBeforeDeployment = true,
StatusMessagesEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface ILogger
/// <summary>
/// Checks if the given <paramref name="logLevel"/> is enabled.
/// </summary>
/// <param name="logLevel">level to be checked.</param>
/// <param name="logLevel">Level to be checked.</param>
/// <returns><c>true</c> if enabled.</returns>
bool IsEnabled(LogLevel logLevel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class EventLogSettings
public string LogName { get; set; }

/// <summary>
/// Name of the event log source. If <c>null</c> or not specified, "Application" is the default.
/// Name of the event log source. If <c>null</c> or not specified, ".NET Runtime" is the default.
/// </summary>
public string SourceName { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ConfigurationChangeTokenSource(IConfiguration config) : this(Options.Defa
/// <summary>
/// Constructor taking the <see cref="IConfiguration"/> instance to watch.
/// </summary>
/// <param name="name">The name of the options instance being watche.</param>
/// <param name="name">The name of the options instance being watched.</param>
/// <param name="config">The configuration instance.</param>
public ConfigurationChangeTokenSource(string name, IConfiguration config)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public partial interface IOptionsChangeTokenSource<out TOptions>
string Name { get; }
Microsoft.Extensions.Primitives.IChangeToken GetChangeToken();
}
public partial interface IOptionsFactory<TOptions> where TOptions : class, new()
public partial interface IOptionsFactory<TOptions> where TOptions : class
{
TOptions Create(string name);
}
Expand All @@ -120,11 +120,11 @@ public partial interface IOptionsMonitor<out TOptions>
TOptions Get(string name);
System.IDisposable OnChange(System.Action<TOptions, string> listener);
}
public partial interface IOptionsSnapshot<out TOptions> : Microsoft.Extensions.Options.IOptions<TOptions> where TOptions : class, new()
public partial interface IOptionsSnapshot<out TOptions> : Microsoft.Extensions.Options.IOptions<TOptions> where TOptions : class
{
TOptions Get(string name);
}
public partial interface IOptions<out TOptions> where TOptions : class, new()
public partial interface IOptions<out TOptions> where TOptions : class
{
TOptions Value { get; }
}
Expand All @@ -139,7 +139,7 @@ public partial interface IValidateOptions<TOptions> where TOptions : class
public static partial class Options
{
public static readonly string DefaultName;
public static Microsoft.Extensions.Options.IOptions<TOptions> Create<TOptions>(TOptions options) where TOptions : class, new() { throw null; }
public static Microsoft.Extensions.Options.IOptions<TOptions> Create<TOptions>(TOptions options) where TOptions : class { throw null; }
}
public partial class OptionsBuilder<TOptions> where TOptions : class
{
Expand Down Expand Up @@ -179,13 +179,14 @@ public void Clear() { }
public virtual bool TryAdd(string name, TOptions options) { throw null; }
public virtual bool TryRemove(string name) { throw null; }
}
public partial class OptionsFactory<TOptions> : Microsoft.Extensions.Options.IOptionsFactory<TOptions> where TOptions : class, new()
public partial class OptionsFactory<TOptions> : Microsoft.Extensions.Options.IOptionsFactory<TOptions> where TOptions : class
{
public OptionsFactory(System.Collections.Generic.IEnumerable<Microsoft.Extensions.Options.IConfigureOptions<TOptions>> setups, System.Collections.Generic.IEnumerable<Microsoft.Extensions.Options.IPostConfigureOptions<TOptions>> postConfigures) { }
public OptionsFactory(System.Collections.Generic.IEnumerable<Microsoft.Extensions.Options.IConfigureOptions<TOptions>> setups, System.Collections.Generic.IEnumerable<Microsoft.Extensions.Options.IPostConfigureOptions<TOptions>> postConfigures, System.Collections.Generic.IEnumerable<Microsoft.Extensions.Options.IValidateOptions<TOptions>> validations) { }
public TOptions Create(string name) { throw null; }
protected virtual TOptions CreateInstance(string name) { throw null; }
}
public partial class OptionsManager<TOptions> : Microsoft.Extensions.Options.IOptions<TOptions>, Microsoft.Extensions.Options.IOptionsSnapshot<TOptions> where TOptions : class, new()
public partial class OptionsManager<TOptions> : Microsoft.Extensions.Options.IOptions<TOptions>, Microsoft.Extensions.Options.IOptionsSnapshot<TOptions> where TOptions : class
{
public OptionsManager(Microsoft.Extensions.Options.IOptionsFactory<TOptions> factory) { }
public TOptions Value { get { throw null; } }
Expand All @@ -195,7 +196,7 @@ public static partial class OptionsMonitorExtensions
{
public static System.IDisposable OnChange<TOptions>(this Microsoft.Extensions.Options.IOptionsMonitor<TOptions> monitor, System.Action<TOptions> listener) { throw null; }
}
public partial class OptionsMonitor<TOptions> : Microsoft.Extensions.Options.IOptionsMonitor<TOptions>, System.IDisposable where TOptions : class, new()
public partial class OptionsMonitor<TOptions> : Microsoft.Extensions.Options.IOptionsMonitor<TOptions>, System.IDisposable where TOptions : class
{
public OptionsMonitor(Microsoft.Extensions.Options.IOptionsFactory<TOptions> factory, System.Collections.Generic.IEnumerable<Microsoft.Extensions.Options.IOptionsChangeTokenSource<TOptions>> sources, Microsoft.Extensions.Options.IOptionsMonitorCache<TOptions> cache) { }
public TOptions CurrentValue { get { throw null; } }
Expand All @@ -211,7 +212,7 @@ public OptionsValidationException(string optionsName, System.Type optionsType, S
public string OptionsName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public System.Type OptionsType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
}
public partial class OptionsWrapper<TOptions> : Microsoft.Extensions.Options.IOptions<TOptions> where TOptions : class, new()
public partial class OptionsWrapper<TOptions> : Microsoft.Extensions.Options.IOptions<TOptions> where TOptions : class
{
public OptionsWrapper(TOptions options) { }
public TOptions Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
Expand Down
Loading

0 comments on commit f6bd0b0

Please sign in to comment.