Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions CodeMaid.UnitTests/CachedSettingSetTests.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SteveCadwallader.CodeMaid.Helpers;
using SteveCadwallader.CodeMaid.Helpers;
using SteveCadwallader.CodeMaid.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace SteveCadwallader.CodeMaid.UnitTests
{
[TestClass]
public class CachedSettingSetTests
{
private int _lookupCount;
private int _parseCount;
private CachedSettingSet<string> _cachedSettingSet;

[TestInitialize]
public void TestInitialize()
public CachedSettingSetTests()
{
Settings.Default.Reset();

Expand All @@ -36,45 +34,45 @@ public void TestInitialize()
.ToList();
});

Assert.AreEqual(0, _lookupCount);
Assert.AreEqual(0, _parseCount);
Assert.IsNotNull(_cachedSettingSet);
Assert.Equal(0, _lookupCount);
Assert.Equal(0, _parseCount);
Assert.NotNull(_cachedSettingSet);
}

[TestMethod]
[Fact]
public void CachedSettingSetCanLookupAndParse()
{
var cleanupExclusions = _cachedSettingSet.Value;

Assert.IsNotNull(cleanupExclusions);
Assert.AreEqual(1, _lookupCount);
Assert.AreEqual(1, _parseCount);
Assert.NotNull(cleanupExclusions);
Assert.Equal(1, _lookupCount);
Assert.Equal(1, _parseCount);
}

[TestMethod]
[Fact]
public void CachedSettingSetUsesCacheOnSecondLookup()
{
var cleanupExclusions = _cachedSettingSet.Value;

Assert.IsNotNull(cleanupExclusions);
Assert.AreEqual(1, _lookupCount);
Assert.AreEqual(1, _parseCount);
Assert.NotNull(cleanupExclusions);
Assert.Equal(1, _lookupCount);
Assert.Equal(1, _parseCount);

var cleanupExclusions2 = _cachedSettingSet.Value;

Assert.IsNotNull(cleanupExclusions2);
Assert.AreEqual(2, _lookupCount);
Assert.AreEqual(1, _parseCount);
Assert.NotNull(cleanupExclusions2);
Assert.Equal(2, _lookupCount);
Assert.Equal(1, _parseCount);
}

[TestMethod]
[Fact]
public void CachedSettingSetReParsesOnChange()
{
var cleanupExclusions = _cachedSettingSet.Value;

Assert.IsNotNull(cleanupExclusions);
Assert.AreEqual(1, _lookupCount);
Assert.AreEqual(1, _parseCount);
Assert.NotNull(cleanupExclusions);
Assert.Equal(1, _lookupCount);
Assert.Equal(1, _parseCount);

var cleanupExclusion2 = new List<string>(cleanupExclusions) { ".*Test.*" };
var serializedCleanupExclusions = string.Join("||", cleanupExclusion2);
Expand All @@ -83,9 +81,9 @@ public void CachedSettingSetReParsesOnChange()

var memberTypeSetting2 = _cachedSettingSet.Value;

Assert.IsNotNull(memberTypeSetting2);
Assert.AreEqual(2, _lookupCount);
Assert.AreEqual(2, _parseCount);
Assert.NotNull(memberTypeSetting2);
Assert.Equal(2, _lookupCount);
Assert.Equal(2, _parseCount);
}
}
}
}
52 changes: 25 additions & 27 deletions CodeMaid.UnitTests/CachedSettingTests.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SteveCadwallader.CodeMaid.Helpers;
using SteveCadwallader.CodeMaid.Helpers;
using SteveCadwallader.CodeMaid.Properties;
using Xunit;

namespace SteveCadwallader.CodeMaid.UnitTests
{
[TestClass]
public class CachedSettingTests
{
private int _lookupCount;
private int _parseCount;
private CachedSetting<MemberTypeSetting> _cachedSetting;

[TestInitialize]
public void TestInitialize()
public CachedSettingTests()
{
Settings.Default.Reset();

Expand All @@ -30,54 +28,54 @@ public void TestInitialize()
return (MemberTypeSetting)x;
});

Assert.AreEqual(0, _lookupCount);
Assert.AreEqual(0, _parseCount);
Assert.IsNotNull(_cachedSetting);
Assert.Equal(0, _lookupCount);
Assert.Equal(0, _parseCount);
Assert.NotNull(_cachedSetting);
}

[TestMethod]
[Fact]
public void CachedSettingCanLookupAndParse()
{
var memberTypeSetting = _cachedSetting.Value;

Assert.IsNotNull(memberTypeSetting);
Assert.AreEqual(1, _lookupCount);
Assert.AreEqual(1, _parseCount);
Assert.NotNull(memberTypeSetting);
Assert.Equal(1, _lookupCount);
Assert.Equal(1, _parseCount);
}

[TestMethod]
[Fact]
public void CachedSettingUsesCacheOnSecondLookup()
{
var memberTypeSetting = _cachedSetting.Value;

Assert.IsNotNull(memberTypeSetting);
Assert.AreEqual(1, _lookupCount);
Assert.AreEqual(1, _parseCount);
Assert.NotNull(memberTypeSetting);
Assert.Equal(1, _lookupCount);
Assert.Equal(1, _parseCount);

var memberTypeSetting2 = _cachedSetting.Value;

Assert.IsNotNull(memberTypeSetting2);
Assert.AreEqual(2, _lookupCount);
Assert.AreEqual(1, _parseCount);
Assert.NotNull(memberTypeSetting2);
Assert.Equal(2, _lookupCount);
Assert.Equal(1, _parseCount);
}

[TestMethod]
[Fact]
public void CachedSettingReParsesOnChange()
{
var memberTypeSetting = _cachedSetting.Value;

Assert.IsNotNull(memberTypeSetting);
Assert.AreEqual(1, _lookupCount);
Assert.AreEqual(1, _parseCount);
Assert.NotNull(memberTypeSetting);
Assert.Equal(1, _lookupCount);
Assert.Equal(1, _parseCount);

memberTypeSetting.EffectiveName = "Member Variables";
Settings.Default.Reorganizing_MemberTypeFields = (string)memberTypeSetting;

var memberTypeSetting2 = _cachedSetting.Value;

Assert.IsNotNull(memberTypeSetting2);
Assert.AreEqual(2, _lookupCount);
Assert.AreEqual(2, _parseCount);
Assert.NotNull(memberTypeSetting2);
Assert.Equal(2, _lookupCount);
Assert.Equal(2, _parseCount);
}
}
}
}
27 changes: 12 additions & 15 deletions CodeMaid.UnitTests/CodeMaid.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ProjectGuid>{27C78B2A-18BC-4CE0-BCB1-DB4C30D805BE}</ProjectGuid>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SteveCadwallader.CodeMaid.UnitTests</RootNamespace>
<AssemblyName>SteveCadwallader.CodeMaid.UnitTests</AssemblyName>
Expand All @@ -21,6 +21,8 @@
<LangVersion>latest</LangVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<RunSettingsFilePath>
</RunSettingsFilePath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -62,6 +64,7 @@
<Compile Include="Formatting\XmlFormattingTests.cs" />
<Compile Include="Formatting\ListFormattingTests.cs" />
<Compile Include="Helpers\CodeItemTypeComparerTests.cs" />
<Compile Include="Helpers\CodeReorganizationManagerTests.cs" />
<Compile Include="Helpers\FileHeaderHelperTests.cs" />
<Compile Include="Helpers\SettingsMonitorTests.cs" />
<Compile Include="MemberTypeSettingTests.cs" />
Expand All @@ -81,25 +84,19 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK">
<Version>16.10.31321.278</Version>
<Version>17.14.40265</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>17.0.0</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>2.2.7</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>2.2.7</Version>
<Version>18.6.0</Version>
</PackageReference>
<PackageReference Include="NSubstitute">
<Version>4.2.2</Version>
<Version>5.3.0</Version>
</PackageReference>
<PackageReference Include="NUnit">
<Version>3.13.2</Version>
<PackageReference Include="xunit.runner.visualstudio">
<Version>3.0.2</Version>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter">
<Version>4.0.0</Version>
<PackageReference Include="xunit.v3">
<Version>3.2.2</Version>
</PackageReference>
</ItemGroup>
<Choose>
Expand Down
6 changes: 3 additions & 3 deletions CodeMaid.UnitTests/Formatting/CommentFormatHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SteveCadwallader.CodeMaid.Model.Comments;
using SteveCadwallader.CodeMaid.Model.Comments;
using Xunit;
using SteveCadwallader.CodeMaid.Model.Comments.Options;
using System;

Expand Down Expand Up @@ -29,7 +29,7 @@ public static string AssertEqualAfterFormat(
Action<FormatterOptions> options = null)
{
var result = CodeComment.Format(text, prefix, options);
Assert.AreEqual(expected ?? text, result);
Assert.Equal(expected ?? text, result);
return result;
}
}
Expand Down
36 changes: 17 additions & 19 deletions CodeMaid.UnitTests/Formatting/FormatWithPrefixTests.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SteveCadwallader.CodeMaid.Properties;
using SteveCadwallader.CodeMaid.Properties;
using System;
using Xunit;

namespace SteveCadwallader.CodeMaid.UnitTests.Formatting
{
/// <summary>
/// </summary>
[TestClass]
public class FormatWithPrefixTests
{
[TestInitialize]
public void TestInitialize()
public FormatWithPrefixTests()
{
Settings.Default.Reset();
}

[TestMethod]
[TestCategory("Formatting UnitTests")]
[Fact]
[Trait("Category", "Formatting UnitTests")]
public void SimpleFormatWithPrefixTests_KeepsPrefix()
{
var input = "// Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
Expand All @@ -26,17 +24,17 @@ public void SimpleFormatWithPrefixTests_KeepsPrefix()
CommentFormatHelper.AssertEqualAfterFormat(input, expected, "//", o => o.WrapColumn = 40);
}

[TestMethod]
[TestCategory("Formatting UnitTests")]
[Fact]
[Trait("Category", "Formatting UnitTests")]
public void SimpleFormatWithPrefixTests_TrimsTrailingSpace()
{
var input = "// Trailing space ";
var expected = "// Trailing space";
CommentFormatHelper.AssertEqualAfterFormat(input, expected, "//");
}

[TestMethod]
[TestCategory("Formatting UnitTests")]
[Fact]
[Trait("Category", "Formatting UnitTests")]
public void SimpleFormatWithPrefixTests_TrimsTrailingLines()
{
var input =
Expand All @@ -48,8 +46,8 @@ public void SimpleFormatWithPrefixTests_TrimsTrailingLines()
CommentFormatHelper.AssertEqualAfterFormat(input, expected, "//");
}

[TestMethod]
[TestCategory("Formatting UnitTests")]
[Fact]
[Trait("Category", "Formatting UnitTests")]
public void SimpleFormatWithPrefixTests_TrimsLeadingLines()
{
var input =
Expand All @@ -62,16 +60,16 @@ public void SimpleFormatWithPrefixTests_TrimsLeadingLines()
CommentFormatHelper.AssertEqualAfterFormat(input, expected, "//");
}

[TestMethod]
[TestCategory("Formatting UnitTests")]
[Fact]
[Trait("Category", "Formatting UnitTests")]
public void SimpleFormatWithPrefixTests_KeepsLeadingSpace()
{
var input = " // Lorem ipsum.";
CommentFormatHelper.AssertEqualAfterFormat(input, input, " //");
}

[TestMethod]
[TestCategory("Formatting UnitTests")]
[Fact]
[Trait("Category", "Formatting UnitTests")]
public void SimpleFormatWithPrefixTests_AlignsToFirstPrefix()
{
var input =
Expand All @@ -83,8 +81,8 @@ public void SimpleFormatWithPrefixTests_AlignsToFirstPrefix()
CommentFormatHelper.AssertEqualAfterFormat(input, expected, " //", o => o.WrapColumn = 40);
}

[TestMethod]
[TestCategory("Formatting UnitTests")]
[Fact]
[Trait("Category", "Formatting UnitTests")]
public void SimpleFormatWithPrefixTests_NoTrailingWhitespaceOnEmptyLine()
{
var input =
Expand Down
Loading