Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Aug 14, 2023
1 parent c434011 commit 14a7268
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace RepoM.Plugin.Misc.Tests.Configuration;
using NuDoq;
using RepoM.Api.Plugins;
using RepoM.Core.Plugin;
using RepoM.Plugin.Misc.Tests.TestFramework;
using RepoM.Plugin.Misc.Tests.TestFramework.NuDoc;
using VerifyTests;
using VerifyXunit;
Expand All @@ -19,13 +20,17 @@ namespace RepoM.Plugin.Misc.Tests.Configuration;
[UsesVerify]
public class DocsModuleSettingsTests
{
private FileBasedPackageConfiguration _fileBasedPackageConfiguration;
private const string VERIFY_DIRECTORY = "VerifiedDocs";
private readonly VerifySettings _verifySettings = new();
private readonly FileBasedPackageConfiguration _fileBasedPackageConfiguration;
private readonly MockFileSystem _fileSystem;

public DocsModuleSettingsTests()
{
_fileSystem = MockFileSystemFactory.CreateDefaultFileSystem();
_fileBasedPackageConfiguration = new FileBasedPackageConfiguration(MockFileSystemFactory.CreateDefaultAppDataProvider(), _fileSystem, NullLogger.Instance, "dummy");

_verifySettings.UseDirectory(VERIFY_DIRECTORY);
}

public static IEnumerable<object[]> PackagesTestData => PluginStore.Packages.Select(package => new object[] { package, }).ToArray();
Expand All @@ -44,8 +49,7 @@ public async Task VerifyChanges()
}

// assert
var settings = new VerifySettings();
await Verifier.Verify(results, settings);
await Verifier.Verify(results, _verifySettings);
}

[Theory]
Expand All @@ -59,14 +63,11 @@ public async Task DocsModuleSettings(IPackage package)
(object? config, string? persistedConfig) = await PersistDefaultConfigAsync(package);

// assert
var settings = new VerifySettings();
// settings.AutoVerify();
settings.UseDirectory("VerifiedDocs");
settings.UseTextForParameters(package.GetType().Name);
_verifySettings.UseTextForParameters(package.GetType().Name);
if (config == null && persistedConfig == null)
{
settings.AppendContentAsFile(CreateConfigWithoutSnippetDocumentationMarkdown(), "md", "desc");
await Verifier.Verify($"No config in {packageName}", settings: settings);
_verifySettings.AppendContentAsFile(CreateConfigWithoutSnippetDocumentationMarkdown(), "md", "desc");
await Verifier.Verify($"No config in {packageName}", settings: _verifySettings);
}
else
{
Expand Down Expand Up @@ -111,10 +112,10 @@ public async Task DocsModuleSettings(IPackage package)
configWithSnippetDocumentationMarkdown += Environment.NewLine + sb;
}

settings.AppendContentAsFile(configWithSnippetDocumentationMarkdown, "md", "desc");
_verifySettings.AppendContentAsFile(configWithSnippetDocumentationMarkdown, "md", "desc");

#if DEBUG
await Verifier.Verify(persistedConfig, settings: settings, extension: "json");
await Verifier.Verify(persistedConfig, settings: _verifySettings, extension: "json");
#else
Assert.True(true); // this test should only be run in Debug mode.
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ namespace RepoM.Plugin.Misc.Tests.Configuration;
[UsesVerify]
public class DocsRepositoryActionsTests
{
private const string VERIFY_DIRECTORY = "VerifiedDocs1";
private readonly VerifySettings _verifySettings = new();

public DocsRepositoryActionsTests()
{
_verifySettings.UseDirectory(VERIFY_DIRECTORY);
}

public static IEnumerable<object[]> AssemblyTestData => PluginStore.Assemblies.Select(assembly => new object[] { assembly, }).ToArray();

public static IEnumerable<object[]> RepositoryActionsTestData
Expand Down Expand Up @@ -71,17 +79,13 @@ public async Task VerifyChanges()
}

// assert
var settings = new VerifySettings();
await Verifier.Verify(results, settings);
await Verifier.Verify(results, _verifySettings);
}

[Fact]
public async Task RepositoryActionBaseDocumentationGeneration()
{
var settings = new VerifySettings();
// settings.AutoVerify();
settings.UseDirectory("VerifiedDocs1");
settings.UseTextForParameters(nameof(RepositoryAction));
_verifySettings.UseTextForParameters(nameof(RepositoryAction));

#if DEBUG
var options = new NuDoq.ReaderOptions
Expand Down Expand Up @@ -109,7 +113,7 @@ public async Task RepositoryActionBaseDocumentationGeneration()
}

#if DEBUG
await Verifier.Verify(sb.ToString(), settings: settings, extension: "md");
await Verifier.Verify(sb.ToString(), settings: _verifySettings, extension: "md");
#else
await Task.Yield();
Assert.True(true); // this test should only be run in Debug mode.
Expand All @@ -120,10 +124,7 @@ public async Task RepositoryActionBaseDocumentationGeneration()
[MemberData(nameof(RepositoryActionsTestData))]
public async Task DocsRepositoryActionsSettings(RepositoryTestData repositoryActionTestData)
{
var settings = new VerifySettings();
// settings.AutoVerify();
settings.UseDirectory("VerifiedDocs1");
settings.UseTextForParameters(repositoryActionTestData.Type.Name);
_verifySettings.UseTextForParameters(repositoryActionTestData.Type.Name);

var builtinClassNames = new Dictionary<string, string>
{
Expand Down Expand Up @@ -166,14 +167,17 @@ public async Task DocsRepositoryActionsSettings(RepositoryTestData repositoryAct
}

#if DEBUG
await Verifier.Verify(sb.ToString(), settings: settings, extension: "md");
await Verifier.Verify(sb.ToString(), settings: _verifySettings, extension: "md");
#else
await Task.Yield();
Assert.True(true); // this test should only be run in Debug mode.
#endif
}
}

/// <summary>
/// Helper class used for naming arguments in xunits test name generation.
/// </summary>
public class RepositoryTestData
{
public RepositoryTestData(Assembly assembly, Type type)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
namespace RepoM.Plugin.Misc.Tests.Configuration;
namespace RepoM.Plugin.Misc.Tests.DefaultAppSettingsTests;

using System.Collections.Generic;
using System.IO.Abstractions.TestingHelpers;
using System.Text;
using System.Threading.Tasks;
using FakeItEasy;
using Microsoft.Extensions.Logging.Abstractions;
using NuDoq;
using RepoM.Api.Common;
using RepoM.Core.Plugin.Common;
using RepoM.Plugin.Misc.Tests.TestFramework;
using RepoM.Plugin.Misc.Tests.TestFramework.NuDoc;
using VerifyTests;
using VerifyXunit;
using Xunit;

internal static class MockFileSystemFactory
{
public static MockFileSystem CreateDefaultFileSystem()
{
return new MockFileSystem(new Dictionary<string, MockFileData>()
{
{ "C:\\tmp\\x.tmp", new MockFileData("x") }, // make sure path exists.
});
}

public static IAppDataPathProvider CreateDefaultAppDataProvider()
{
IAppDataPathProvider appDataPathProvider = A.Fake<IAppDataPathProvider>();
A.CallTo(() => appDataPathProvider.AppDataPath).Returns("C:\\tmp\\");
return appDataPathProvider;
}
}

[UsesVerify]
public class DocsAppSettingsTests
{
private FileAppSettingsService _fileBasedPackageConfiguration;
private readonly VerifySettings _verifySettings = new();
private readonly FileAppSettingsService _fileBasedPackageConfiguration;
private readonly MockFileSystem _fileSystem;

public DocsAppSettingsTests()
Expand Down Expand Up @@ -65,10 +46,10 @@ public async Task AppSettingsJsonFileGeneration()
[Fact]
public async Task AppSettingsDocumentationGeneration()
{
var settings = new VerifySettings();
settings.UseTextForParameters(nameof(AppSettings));
_verifySettings.UseTextForParameters(nameof(AppSettings));

#if DEBUG
// ReSharper disable once RedundantNameQualifier
var options = new NuDoq.ReaderOptions
{
KeepNewLinesInText = true,
Expand All @@ -94,7 +75,7 @@ public async Task AppSettingsDocumentationGeneration()
}

#if DEBUG
await Verifier.Verify(sb.ToString(), settings: settings, extension: "md");
await Verifier.Verify(sb.ToString(), settings: _verifySettings, extension: "md");
#else
await Task.Yield();
Assert.True(true); // this test should only be run in Debug mode.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace RepoM.Plugin.Misc.Tests.TestFramework;

using System.Collections.Generic;
using System.IO.Abstractions.TestingHelpers;
using FakeItEasy;
using RepoM.Core.Plugin.Common;

internal static class MockFileSystemFactory
{
public static MockFileSystem CreateDefaultFileSystem()
{
return new MockFileSystem(new Dictionary<string, MockFileData>()
{
{ "C:\\tmp\\x.tmp", new MockFileData("x") }, // make sure path exists.
});
}

public static IAppDataPathProvider CreateDefaultAppDataProvider()
{
IAppDataPathProvider appDataPathProvider = A.Fake<IAppDataPathProvider>();
A.CallTo(() => appDataPathProvider.AppDataPath).Returns("C:\\tmp\\");
return appDataPathProvider;
}
}
10 changes: 2 additions & 8 deletions tests/RepoM.Plugin.Misc.Tests/TestFramework/NuDoc/ClassWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ namespace RepoM.Plugin.Misc.Tests.TestFramework.NuDoc;

internal class ClassWriter
{
public ClassWriter()
{
Head = new StringWriter();
Properties = new StringWriter();
}
public readonly StringWriter Head = new();

public readonly StringWriter Head;

public readonly StringWriter Properties;
public readonly StringWriter Properties = new();
}

0 comments on commit 14a7268

Please sign in to comment.