-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create test for singleton factory, to ensure it properly instantiates…
… the singletons
- Loading branch information
1 parent
db02d13
commit eee9b2b
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
TJC.Singleton.Tests/Mocks/Valid/MockSingletonInstantiated.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace TJC.Singleton.Tests.Mocks.Valid; | ||
|
||
internal class MockSingletonInstantiated : SingletonBaseClass<MockSingletonInstantiated>, IIdentifier | ||
{ | ||
private MockSingletonInstantiated() {}//=> IsInstantiated = true; | ||
|
||
public Guid Id { get; } = Guid.NewGuid(); | ||
|
||
//public static bool IsInstantiated { get; private set; } | ||
} |
16 changes: 16 additions & 0 deletions
16
TJC.Singleton.Tests/Tests/Instantiated/IsInstantiatedTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using TJC.Singleton.Factories; | ||
|
||
namespace TJC.Singleton.Tests.Tests.Instantiated; | ||
|
||
[TestClass] | ||
public class IsInstantiatedTest | ||
{ | ||
[TestMethod] | ||
public void SingletonGetInstantiatedAfterBeingReferencedTest() | ||
{ | ||
// MockSingletonInstantiated can only be used in this test and nowhere else, since object instances can persist between tests | ||
Assert.IsFalse(MockSingletonInstantiated.IsInstantiated, $"{nameof(MockSingletonInstantiated)} was already instantiated"); | ||
SingletonFactory.InstantiatedAll(trace: true); | ||
Assert.IsTrue(MockSingletonInstantiated.IsInstantiated, $"{nameof(MockSingletonInstantiated)} is not instantiated"); | ||
} | ||
} |