Skip to content

Commit 5e71c5c

Browse files
committed
Test added to verify that I don't forget to pick a valid test name.
1 parent 2f447d4 commit 5e71c5c

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

src/SimpleInjector.Integration.Web.Tests.Unit/HttpContextScope.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static WebApplication()
6161
public class HttpContextScopeTests
6262
{
6363
[TestMethod]
64-
public void MethodUnderTest_Scenario_Behavior()
64+
public void ctor_Always_SetsHttpContextCurrentForCurrentThread()
6565
{
6666
// Arrange
6767
Assert.IsNull(HttpContext.Current, "Test setup failed");
@@ -72,12 +72,25 @@ public void MethodUnderTest_Scenario_Behavior()
7272
// Assert
7373
Assert.IsNotNull(HttpContext.Current, "HttpContext.Current should be set.");
7474
}
75+
}
76+
77+
[TestMethod]
78+
public void Dispose_Always_ClearsHttpContextCurrentForCurrentThread()
79+
{
80+
// Arrange
81+
Assert.IsNull(HttpContext.Current, "Test setup failed");
82+
83+
// Act
84+
using (new HttpContextScope())
85+
{
86+
}
7587

88+
// Assert
7689
Assert.IsNull(HttpContext.Current, "HttpContext.Current should be null after disposing.");
7790
}
7891

7992
[TestMethod]
80-
public void MethodUnderTest_Scenario_Behavior2()
93+
public void ctor_Never_SetsHttpContextCurrentOnDifferentThread()
8194
{
8295
// Arrange
8396
Assert.IsNull(HttpContext.Current, "Test setup failed");

src/SimpleInjector.Tests.Unit/DecoratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ supported by this method. Please supply the open generic type 'ICommandHandler<>
24742474
}
24752475

24762476
[TestMethod]
2477-
public void MethodUnderTest_Scenario_Behaviorx()
2477+
public void InjectedScopeDecorateeFactory_WhenSuppliedWithAScopeInstance_CreatesScopedInstancesBasedOnThatScope()
24782478
{
24792479
// Arrange
24802480
var container = ContainerFactory.New();

src/SimpleInjector.Tests.Unit/ScopedLifestyleTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ public void GetInstance_ResolvingAnInstanceDependingOnScopeWithoutAnActiveScopeA
10861086
}
10871087

10881088
[TestMethod]
1089-
public void MethodUnderTest_Scenario_Behavior()
1089+
public void Verify_RegistrationDependingOnScopeWithDefaultScopedLifestyleSet_Succeeds()
10901090
{
10911091
var container = ContainerFactory.New();
10921092
container.Options.DefaultScopedLifestyle = new ThreadScopedLifestyle();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace SimpleInjector.Tests.Unit
2+
{
3+
using System.Linq;
4+
using System.Reflection;
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
7+
[TestClass]
8+
public class TestTests
9+
{
10+
[TestMethod]
11+
public void VerifyIfAllTestMethodsHaveAValidName()
12+
{
13+
var invalidlyNamedTestMethods =
14+
from type in this.GetType().Assembly.GetTypes()
15+
from m in type.GetMethods()
16+
where m.GetCustomAttributes<TestMethodAttribute>(true).Any() && (
17+
m.Name.Contains("MethodUnderTest")
18+
|| m.Name.Contains("_Scenario")
19+
|| m.Name.Contains("_Behavior"))
20+
select m;
21+
22+
var method = invalidlyNamedTestMethods.FirstOrDefault();
23+
24+
// Act
25+
Assert.IsNull(method,
26+
$"There is a test method, named {method?.Name} in class {method?.DeclaringType?.Name} that is not a good test name.");
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)