using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; namespace Tgstation.Server.Host.Extensions.Tests { [TestClass] public sealed class TestServiceCollectionExtensions { class GoodConfig { public const string Section = "asdf"; } class BadConfig1 { #pragma warning disable IDE0051 // Remove unused private members const string Section = "asdf"; #pragma warning restore IDE0051 // Remove unused private members } class BadConfig2 { public const bool Section = false; } class BadConfig3 { //nah } [TestMethod] public void TestUseStandardConfig() { var serviceCollection = new ServiceCollection(); var mockConfig = new Mock(); mockConfig.Setup(x => x.GetSection(It.IsNotNull())).Returns(mockConfig.Object).Verifiable(); Assert.ThrowsExactly(() => ServiceCollectionExtensions.UseStandardConfig(null, null)); Assert.ThrowsExactly(() => serviceCollection.UseStandardConfig(null)); serviceCollection.UseStandardConfig(mockConfig.Object); Assert.ThrowsExactly(() => serviceCollection.UseStandardConfig(mockConfig.Object)); Assert.ThrowsExactly(() => serviceCollection.UseStandardConfig(mockConfig.Object)); Assert.ThrowsExactly(() => serviceCollection.UseStandardConfig(mockConfig.Object)); mockConfig.Verify(); } } }