-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4ddc74
commit f88cf00
Showing
5 changed files
with
181 additions
and
109 deletions.
There are no files selected for viewing
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
79 changes: 79 additions & 0 deletions
79
src/NUnitEngine/nunit.engine.core.tests/Internal/ExtensionAssemblyTrackerTests.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,79 @@ | ||
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt | ||
|
||
using System; | ||
using System.ComponentModel; | ||
using System.Reflection; | ||
using NUnit.Engine.Extensibility; | ||
using NUnit.Framework; | ||
|
||
namespace NUnit.Engine.Internal.Tests | ||
{ | ||
public class ExtensionAssemblyTrackerTests | ||
{ | ||
private static readonly Assembly THIS_ASSEMBLY = typeof(ExtensionAssemblyTrackerTests).Assembly; | ||
private static readonly string THIS_ASSEMBLY_PATH = THIS_ASSEMBLY.Location; | ||
private static readonly string THIS_ASSEMBLY_NAME = THIS_ASSEMBLY.GetName().Name; | ||
private static readonly Version THIS_ASSEMBLY_VERSION = THIS_ASSEMBLY.GetName().Version; | ||
private static readonly ExtensionAssembly TEST_EXTENSION_ASSEMBLY = | ||
new ExtensionAssembly(THIS_ASSEMBLY_PATH, false, THIS_ASSEMBLY_NAME, THIS_ASSEMBLY_VERSION); | ||
|
||
private ExtensionAssemblyTracker _tracker; | ||
|
||
[SetUp] | ||
public void CreateTracker() | ||
{ | ||
_tracker = new ExtensionAssemblyTracker(); | ||
} | ||
|
||
[Test] | ||
public void AddToList() | ||
{ | ||
_tracker.Add(TEST_EXTENSION_ASSEMBLY); | ||
|
||
Assert.That(_tracker.Count, Is.EqualTo(1)); | ||
Assert.That(_tracker[0].FilePath, Is.EqualTo(THIS_ASSEMBLY_PATH)); | ||
Assert.That(_tracker[0].AssemblyName, Is.EqualTo(THIS_ASSEMBLY_NAME)); | ||
Assert.That(_tracker[0].AssemblyVersion, Is.EqualTo(THIS_ASSEMBLY_VERSION)); | ||
} | ||
|
||
[Test] | ||
public void AddUpdatesNameIndex() | ||
{ | ||
_tracker.Add(TEST_EXTENSION_ASSEMBLY); | ||
|
||
Assert.That(_tracker.ByName.ContainsKey(THIS_ASSEMBLY_NAME)); | ||
Assert.That(_tracker.ByName[THIS_ASSEMBLY_NAME].AssemblyName, Is.EqualTo(THIS_ASSEMBLY_NAME)); | ||
Assert.That(_tracker.ByName[THIS_ASSEMBLY_NAME].FilePath, Is.EqualTo(THIS_ASSEMBLY_PATH)); | ||
Assert.That(_tracker.ByName[THIS_ASSEMBLY_NAME].AssemblyVersion, Is.EqualTo(THIS_ASSEMBLY_VERSION)); | ||
} | ||
[Test] | ||
public void AddUpdatesPathIndex() | ||
{ | ||
_tracker.Add(TEST_EXTENSION_ASSEMBLY); | ||
|
||
Assert.That(_tracker.ByPath.ContainsKey(THIS_ASSEMBLY_PATH)); | ||
Assert.That(_tracker.ByPath[THIS_ASSEMBLY_PATH].AssemblyName, Is.EqualTo(THIS_ASSEMBLY_NAME)); | ||
Assert.That(_tracker.ByPath[THIS_ASSEMBLY_PATH].FilePath, Is.EqualTo(THIS_ASSEMBLY_PATH)); | ||
Assert.That(_tracker.ByPath[THIS_ASSEMBLY_PATH].AssemblyVersion, Is.EqualTo(THIS_ASSEMBLY_VERSION)); | ||
} | ||
|
||
[Test] | ||
public void AddDuplicatePathThrowsArgumentException() | ||
{ | ||
_tracker.Add(TEST_EXTENSION_ASSEMBLY); | ||
|
||
Assert.That(() => | ||
_tracker.Add(TEST_EXTENSION_ASSEMBLY), | ||
Throws.TypeOf<System.ArgumentException>()); | ||
} | ||
|
||
[Test] | ||
public void AddDuplicateAssemblyNameThrowsArgumentException() | ||
{ | ||
_tracker.Add(TEST_EXTENSION_ASSEMBLY); | ||
|
||
Assert.That(() => _tracker.Add(new ExtensionAssembly("Some/Other/Path", false, THIS_ASSEMBLY_NAME, THIS_ASSEMBLY_VERSION)), | ||
Throws.TypeOf<System.ArgumentException>()); | ||
} | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/NUnitEngine/nunit.engine.core/Internal/ExtensionAssemblyTracker.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,25 @@ | ||
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt | ||
|
||
using NUnit.Engine.Extensibility; | ||
using System.Collections.Generic; | ||
|
||
namespace NUnit.Engine.Internal | ||
{ | ||
/// <summary> | ||
/// This is a simple utility class used by the ExtensionManager to keep track of ExtensionAssemblies. | ||
/// It is a List of ExtensionAssemblies and also provides indices by file path and assembly name. | ||
/// It allows writing tests to show that no duplicate extension assemblies are loaded. | ||
/// </summary> | ||
internal class ExtensionAssemblyTracker : List<ExtensionAssembly> | ||
{ | ||
public Dictionary<string, ExtensionAssembly> ByPath = new Dictionary<string, ExtensionAssembly>(); | ||
public Dictionary<string, ExtensionAssembly> ByName = new Dictionary<string, ExtensionAssembly>(); | ||
|
||
public new void Add(ExtensionAssembly assembly) | ||
{ | ||
base.Add(assembly); | ||
ByPath.Add(assembly.FilePath, assembly); | ||
ByName.Add(assembly.AssemblyName, assembly); | ||
} | ||
} | ||
} |
Oops, something went wrong.