Skip to content

Commit 1c4281e

Browse files
committed
Migrate from FluentAssertions
1 parent 58e5259 commit 1c4281e

31 files changed

+212
-262
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace Shouldly
2+
{
3+
public static class ShouldlyExtensions
4+
{
5+
public static void ShouldNotBeNullOrEmpty<T>(this IEnumerable<T> actual)
6+
{
7+
actual.ShouldNotBeNull();
8+
actual.ShouldNotBeEmpty();
9+
}
10+
11+
public static void ShouldHaveCount<T>(this IEnumerable<T> actual, int count)
12+
{
13+
actual.Count().ShouldBe(count);
14+
}
15+
16+
public static void ShouldHaveValue<T>(this T? actual)
17+
where T : struct
18+
{
19+
actual.HasValue.ShouldBeTrue();
20+
}
21+
22+
public static void ShouldBeFalse(this bool? actual)
23+
{
24+
actual.ShouldBe(false);
25+
}
26+
27+
public static void ShouldBeCloseTo(this DateTime actual, DateTime expected, TimeSpan precision)
28+
{
29+
actual.ShouldBeInRange(expected - precision, expected + precision);
30+
}
31+
}
32+
}

test/WebExtensions.Net.BrowserExtensionIntegrationTest/Infrastructure/FactAttribute.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure
1+
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure
42
{
53
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
64
public class FactAttribute : Attribute

test/WebExtensions.Net.BrowserExtensionIntegrationTest/Infrastructure/ITestFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Collections.Generic;
2-
using WebExtensions.Net.BrowserExtensionIntegrationTest.Models;
1+
using WebExtensions.Net.BrowserExtensionIntegrationTest.Models;
32

43
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure
54
{

test/WebExtensions.Net.BrowserExtensionIntegrationTest/Infrastructure/ITestRunner.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Threading.Tasks;
2-
3-
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure
1+
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure
42
{
53
public interface ITestRunner
64
{

test/WebExtensions.Net.BrowserExtensionIntegrationTest/Infrastructure/TestClassAttribute.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure
1+
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure
42
{
53
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
64
public class TestClassAttribute : Attribute

test/WebExtensions.Net.BrowserExtensionIntegrationTest/Infrastructure/TestFactory.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Reflection;
1+
using System.Reflection;
52
using WebExtensions.Net.BrowserExtensionIntegrationTest.Models;
63

74
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure

test/WebExtensions.Net.BrowserExtensionIntegrationTest/Infrastructure/TestRunner.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
using FluentAssertions.Execution;
2-
using Microsoft.Extensions.DependencyInjection;
3-
using Microsoft.Extensions.Logging;
4-
using Microsoft.JSInterop;
5-
using System;
6-
using System.Collections.Generic;
7-
using System.Linq;
1+
using Microsoft.JSInterop;
82
using System.Reflection;
9-
using System.Threading.Tasks;
103
using WebExtensions.Net.BrowserExtensionIntegrationTest.Models;
114

125
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure
@@ -63,7 +56,7 @@ public async Task<TestResult> RunTest(TestMethodInfo testMethodInfo)
6356
catch(Exception ex)
6457
{
6558
result.FailMessage = ex.Message;
66-
result.StackTrace = GetStackTrace(ex);
59+
result.StackTrace = ex.StackTrace;
6760
logger.LogError($"Test failed: {testMethodInfo.Description}", ex);
6861
}
6962
return result;
@@ -80,16 +73,6 @@ private object GetTestClassInstance(Type testClassType)
8073
return testClassInstance;
8174
}
8275

83-
private static string GetStackTrace(Exception ex)
84-
{
85-
if (ex is AssertionFailedException)
86-
{
87-
// clear the stack trace from FluentAssertions namespace
88-
return string.Join(Environment.NewLine, ex.StackTrace.Split(Environment.NewLine).Where(line => !line.Contains($"{nameof(FluentAssertions)}.")));
89-
}
90-
return ex.StackTrace;
91-
}
92-
9376
public async Task GetTestCoverageInfo()
9477
{
9578
// AppDomain.Unload is not supported, in the case where the extension is running with coverlet, look for the HitsArray static field in WebExtensions.Net

test/WebExtensions.Net.BrowserExtensionIntegrationTest/Models/TestClassInfo.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Collections.Generic;
2-
3-
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Models
1+
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Models
42
{
53
public class TestClassInfo
64
{

test/WebExtensions.Net.BrowserExtensionIntegrationTest/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
2-
using Microsoft.Extensions.DependencyInjection;
3-
using System.Threading.Tasks;
42
using WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure;
53

64
namespace WebExtensions.Net.BrowserExtensionIntegrationTest

test/WebExtensions.Net.BrowserExtensionIntegrationTest/Tests/AlarmsApiTests.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using FluentAssertions;
2-
using System;
3-
using System.Threading.Tasks;
4-
using WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure;
1+
using WebExtensions.Net.BrowserExtensionIntegrationTest.Infrastructure;
52

63
namespace WebExtensions.Net.BrowserExtensionIntegrationTest.Tests
74
{
@@ -29,7 +26,7 @@ public void Create()
2926
});
3027

3128
// Assert
32-
action.Should().NotThrow();
29+
action.ShouldNotThrow();
3330
}
3431

3532
[Fact(Order = 2)]
@@ -39,7 +36,7 @@ public async Task Get()
3936
var alarm = await webExtensionsApi.Alarms.Get(testAlarmName);
4037

4138
// Assert
42-
((DateTime)alarm.ScheduledTime).Should().Be(testAlarmTime);
39+
((DateTime)alarm.ScheduledTime).ShouldBe(testAlarmTime);
4340
}
4441

4542
[Fact(Order = 2)]
@@ -49,7 +46,7 @@ public async Task GetAll()
4946
var alarms = await webExtensionsApi.Alarms.GetAll();
5047

5148
// Assert
52-
alarms.Should().Contain(alarm => alarm.Name == testAlarmName);
49+
alarms.ShouldContain(alarm => alarm.Name == testAlarmName);
5350
}
5451

5552
[Fact(Order = 3)]
@@ -59,7 +56,7 @@ public async Task Clear()
5956
var alarmCleared = await webExtensionsApi.Alarms.Clear(testAlarmName);
6057

6158
// Assert
62-
alarmCleared.Should().BeTrue();
59+
alarmCleared.ShouldBeTrue();
6360
}
6461

6562
[Fact(Order = 4)]
@@ -69,7 +66,7 @@ public async Task ClearAll()
6966
Func<Task> action = async () => await webExtensionsApi.Alarms.ClearAll();
7067

7168
// Assert
72-
await action.Should().NotThrowAsync();
69+
await action.ShouldNotThrowAsync();
7370
}
7471
}
7572
}

0 commit comments

Comments
 (0)