2008-11-26 19:15:36 +00:00
|
|
|
|
#region CPL License
|
|
|
|
|
/*
|
|
|
|
|
Nuclex Framework
|
2017-01-21 21:33:55 +00:00
|
|
|
|
Copyright (C) 2002-2017 Nuclex Development Labs
|
2008-11-26 19:15:36 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the IBM Common Public License as
|
|
|
|
|
published by the IBM Corporation; either version 1.0 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
IBM Common Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the IBM Common Public
|
|
|
|
|
License along with this library
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
#if UNITTEST
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
namespace Nuclex.Support {
|
|
|
|
|
|
|
|
|
|
/// <summary>Unit Test for the shared instance provider class</summary>
|
|
|
|
|
[TestFixture]
|
2012-02-29 16:27:43 +00:00
|
|
|
|
internal class SharedTest {
|
2008-11-26 19:15:36 +00:00
|
|
|
|
|
|
|
|
|
#region class Dummy
|
|
|
|
|
|
|
|
|
|
/// <summary>Dummy class for testing the shared instance provider</summary>
|
|
|
|
|
private class Dummy {
|
|
|
|
|
/// <summary>Initializes a new dummy</summary>
|
|
|
|
|
public Dummy() {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion // class Dummy
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies that the shared instance provider returns the same instance of a class
|
|
|
|
|
/// when asked for the same class twice.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSameInstance() {
|
2019-02-02 12:47:07 +00:00
|
|
|
|
#pragma warning disable 0618
|
2008-11-26 19:15:36 +00:00
|
|
|
|
Dummy dummyInstance = Shared<Dummy>.Instance;
|
|
|
|
|
Dummy otherDummyInstance = Shared<Dummy>.Instance;
|
2019-02-02 12:47:07 +00:00
|
|
|
|
#pragma warning restore 0618
|
2008-11-26 19:15:36 +00:00
|
|
|
|
|
|
|
|
|
// Make sure they're the same instance. We could have put an instance counter in
|
|
|
|
|
// the dummy class, but this might or might not work well across multiple tests
|
|
|
|
|
// because the order in which tests are executed is undefined and Shared<> changes
|
|
|
|
|
// its global state when the first test is run by remembering the instance.
|
|
|
|
|
//
|
|
|
|
|
// Maybe this really is a defect in Shared<> and the class should be equipped with
|
|
|
|
|
// a method such as Discard() or Dispose() to get rid of the instance?
|
2009-01-08 20:14:14 +00:00
|
|
|
|
Assert.AreSame(dummyInstance, otherDummyInstance);
|
2008-11-26 19:15:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Nuclex.Support
|
|
|
|
|
|
|
|
|
|
#endif // UNITTEST
|