Skip to content

Commit

Permalink
Create test for singleton factory, to ensure it properly instantiates…
Browse files Browse the repository at this point in the history
… the singletons
  • Loading branch information
TylerCarrol committed Jun 2, 2024
1 parent db02d13 commit eee9b2b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions TJC.Singleton.Tests/Mocks/Valid/MockSingletonInstantiated.cs
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 TJC.Singleton.Tests/Tests/Instantiated/IsInstantiatedTest.cs
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");
}
}

0 comments on commit eee9b2b

Please sign in to comment.