Skip to content

Commit

Permalink
MSTest support (#158)
Browse files Browse the repository at this point in the history
* adding mstest support

Co-authored-by: Normen Scheiber <nscheibe@live.com>
  • Loading branch information
aaronpowell and nscheibe authored Oct 31, 2022
1 parent 2df8eda commit 1da1c90
Show file tree
Hide file tree
Showing 33 changed files with 2,240 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ dotnet add package Snapshooter.Xunit
### NUnit
```bash
dotnet add package Snapshooter.NUnit

### MSTest
```bash
dotnet add package Snapshooter.MSTest
```

[Get Started](https://swisslife-oss.github.io/snapshooter/docs/get-started)
Expand Down
32 changes: 32 additions & 0 deletions src/Snapshooter.MSTest.Tests/MSTestAssertTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Snapshooter.MSTest.Tests
{
[TestClass]
public class MSTestAssertTests
{
[TestMethod]
public void Assert_AssertEqualText_AssertSuccessful()
{
// arrange
var snapshotAssert = new MSTestAssert();

// act & assert
snapshotAssert.Assert("{Same}", "{Same}");
}

[TestMethod]
public void Assert_AssertUnequalText_ThrowsEqualException()
{
// arrange
var snapshotAssert = new MSTestAssert();

// act
Action action = () => snapshotAssert.Assert("{Same}", "{Sme}");

// assert
Assert.ThrowsException<AssertFailedException>(action);
}
}
}
128 changes: 128 additions & 0 deletions src/Snapshooter.MSTest.Tests/MSTestSnapshotFullNameReaderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Snapshooter.MSTest.Tests
{
[TestClass]
public class MSTestSnapshotFullNameReaderTests
{
[TestMethod]
public void ReadSnapshotFullName_ResolveTestSnapshotFullName_ResolvedSuccessfully()
{
// arrange
var snapshotFullNameResolver = new MSTestSnapshotFullNameReader();

// act
SnapshotFullName snapshotFullName = snapshotFullNameResolver.ReadSnapshotFullName();

// assert
Assert.AreEqual(snapshotFullName.Filename,
$"{nameof(MSTestSnapshotFullNameReaderTests)}." +
$"{nameof(ReadSnapshotFullName_ResolveTestSnapshotFullName_ResolvedSuccessfully)}");
}

[TestMethod]
public async Task ReadSnapshotFullName_ResolveTestSnapshotFullNameAsync_ResolvedSuccessfully()
{
// arrange
var snapshotFullNameResolver = new MSTestSnapshotFullNameReader();
await Task.Delay(1);

// act
SnapshotFullName snapshotFullName = snapshotFullNameResolver.ReadSnapshotFullName();

// assert
await Task.Delay(1);
Assert.AreEqual(snapshotFullName.Filename,
$"{nameof(MSTestSnapshotFullNameReaderTests)}." +
$"{nameof(ReadSnapshotFullName_ResolveTestSnapshotFullNameAsync_ResolvedSuccessfully)}");
}

[DataTestMethod]
[DataRow("testString1", 5)]
[DataRow("testString2", 6)]
[DataRow("testString3", 7)]
public void ReadSnapshotFullName_ResolveTheorySnapshotName_NameResolvedWithoutInlineDataParameters(
string param1, int param2)
{
// arrange
var snapshotFullNameResolver = new MSTestSnapshotFullNameReader();

// act
SnapshotFullName snapshotFullName = snapshotFullNameResolver.ReadSnapshotFullName();

// assert
Assert.AreEqual(snapshotFullName.Filename,
$"{nameof(MSTestSnapshotFullNameReaderTests)}." +
$"{nameof(ReadSnapshotFullName_ResolveTheorySnapshotName_NameResolvedWithoutInlineDataParameters)}" +
$"_{param1}_{param2}");
}

[DataTestMethod]
[DataRow("testString1", 5)]
[DataRow("testString2", 6)]
[DataRow("testString3", 7)]
public async Task ReadSnapshotFullName_ResolveTheorySnapshotNameAsync_NameResolvedWithoutInlineDataParameters(
string param1, int param2)
{
// arrange
var snapshotFullNameResolver = new MSTestSnapshotFullNameReader();
await Task.Delay(1);

// act
SnapshotFullName snapshotFullName = snapshotFullNameResolver.ReadSnapshotFullName();

// assert
await Task.Delay(1);
Assert.AreEqual(snapshotFullName.Filename,
$"{nameof(MSTestSnapshotFullNameReaderTests)}." +
$"{nameof(ReadSnapshotFullName_ResolveTheorySnapshotNameAsync_NameResolvedWithoutInlineDataParameters)}" +
$"_{param1}_{param2}");
}

[DataTestMethod]
[DataSource(nameof(TestCases))]
public void ReadSnapshotFullName_ResolveTheoryDataSnapshotName_NameResolvedWithoutInlineDataParameters(
string param1, int param2)
{
// arrange
var snapshotFullNameResolver = new MSTestSnapshotFullNameReader();

// act
SnapshotFullName snapshotFullName = snapshotFullNameResolver.ReadSnapshotFullName();

// assert
Assert.AreEqual(snapshotFullName.Filename,
$"{nameof(MSTestSnapshotFullNameReaderTests)}." +
$"{nameof(ReadSnapshotFullName_ResolveTheoryDataSnapshotName_NameResolvedWithoutInlineDataParameters)}" +
$"_{param1}_{param2}");
}

[DataTestMethod]
[DataSource(nameof(TestCases))]
public async Task ReadSnapshotFullName_ResolveTheoryDataSnapshotNameAsync_NameResolvedWithoutInlineDataParameters(
string param1, int param2)
{
// arrange
var snapshotFullNameResolver = new MSTestSnapshotFullNameReader();
await Task.Delay(1);

// act
SnapshotFullName snapshotFullName = snapshotFullNameResolver.ReadSnapshotFullName();

// assert
await Task.Delay(1);
Assert.AreEqual(snapshotFullName.Filename,
$"{nameof(MSTestSnapshotFullNameReaderTests)}." +
$"{nameof(ReadSnapshotFullName_ResolveTheoryDataSnapshotNameAsync_NameResolvedWithoutInlineDataParameters)}" +
$"_{param1}_{param2}");
}

private static object[] TestCases => new object[]
{
new object[] { "testString1", 5 },
new object[] { "testString2", 6 },
new object[] { "testString3", 7 }
};
}
}
20 changes: 20 additions & 0 deletions src/Snapshooter.MSTest.Tests/Snapshooter.MSTest.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(CCTestProjectProps)" Condition="Exists('$(CCTestProjectProps)')" />

<PropertyGroup>
<AssemblyName>Snapshooter.MSTest.Tests</AssemblyName>
<RootNamespace>Snapshooter.MSTest.Tests</RootNamespace>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Snapshooter.MSTest\Snapshooter.MSTest.csproj" />
<ProjectReference Include="..\Snapshooter.Tests.Data\Snapshooter.Tests.Data.csproj" />
</ItemGroup>

</Project>
102 changes: 102 additions & 0 deletions src/Snapshooter.MSTest.Tests/SnapshotExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using Snapshooter.Tests.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Snapshooter.MSTest.Tests
{
[TestClass]
public class SnapshotExtensionTests
{
[TestMethod]
public void MatchSnapshot_ShouldFluentAssertions_RemovesSubject()
{
// arrange
TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().Build();

// act & assert
testPerson.Should().MatchSnapshot();
}

[TestMethod]
public void MatchSnapshot_ShouldFluentAssertionsNameOf_RemovesSubject()
{
// arrange
TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().Build();

// act & assert
testPerson.Should().MatchSnapshot(nameof(MatchSnapshot_ShouldFluentAssertionsNameOf_RemovesSubject));
}

[TestMethod("Test for issue #118")]
public void MatchSnapshot_FluentAssertions_StringValue_ShouldRemovesSubject()
{
// arrange
string testValue = "Some text string";

// act & assert
testValue.Should().MatchSnapshot();
}

[TestMethod("Test for issue #118")]
public void MatchSnapshot_FluentAssertions_DictionaryValue_ShouldRemovesSubject()
{
// arrange
var testCustomer = new List<Dictionary<string, object>>
{
new Dictionary<string, object>
{
{ "Id", 1 },
{ "Name", "Bla "},
{ "EmailAddress", "blabla@blabla.com" },
},
};
var testDictionary = new Dictionary<string, List<Dictionary<string, object>>>();
testDictionary.Add("Customer", testCustomer);

// act & assert
testDictionary.Should().MatchSnapshot();
}

[TestMethod]
public void MatchSnapshot_PlainExtension_CorrectSnapshot()
{
// arrange
TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().Build();

// act & assert
testPerson.MatchSnapshot();
}

[TestMethod]
public void MatchSnapshot_PlainExtensionAnonymousType_CorrectSnapshot()
{
// arrange
TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().Build();

// act & assert
new { foo = testPerson }.MatchSnapshot();
}

[TestMethod]
public void MatchSnapshot_ShouldFluentAssertionsAnonymousType_CorrectSnapshot()
{
// arrange
TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().Build();

// act & assert
new { foo = testPerson }.Should().MatchSnapshot();
}

[TestMethod]
public void MatchSnapshot_Null_Throws()
{
// arrange
TestPerson testPerson = null;

// act & assert
Assert.ThrowsException<ArgumentNullException>(() => testPerson.MatchSnapshot());
}
}
}
Loading

0 comments on commit 1da1c90

Please sign in to comment.