Last change
on this file since 17376 was
17019,
checked in by abeham, 5 years ago
|
#2520: fixed unit test to check for duplicate GUIDs (includes NonDiscoverable types)
|
File size:
1.3 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using HEAL.Attic;
|
---|
5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Tests.Persistence.Attic {
|
---|
8 | [TestClass]
|
---|
9 | public class PersistenceConsistencyChecks {
|
---|
10 | [TestCategory("Persistence.Attic")]
|
---|
11 | [TestCategory("Essential")]
|
---|
12 | [TestProperty("Time", "short")]
|
---|
13 | [TestMethod]
|
---|
14 | public void CheckDuplicateGUIDs() {
|
---|
15 | // easy to produce duplicate GUIDs with copy&paste
|
---|
16 | var dict = new Dictionary<Guid, string>();
|
---|
17 | var duplicates = new Dictionary<string, string>();
|
---|
18 | // using AppDomain instead of ApplicationManager so that NonDiscoverableTypes are also checked
|
---|
19 | foreach (Type type in AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())) {
|
---|
20 | var attr = StorableTypeAttribute.GetStorableTypeAttribute(type);
|
---|
21 | if (attr == null)
|
---|
22 | continue;
|
---|
23 |
|
---|
24 | foreach (var guid in attr.Guids) {
|
---|
25 | if (!dict.ContainsKey(guid)) {
|
---|
26 | dict.Add(guid, type.FullName);
|
---|
27 | } else {
|
---|
28 | duplicates.Add(type.FullName, dict[guid]);
|
---|
29 | }
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | foreach (var kvp in duplicates) {
|
---|
34 | Console.WriteLine($"{kvp.Key} has same GUID as {kvp.Value}");
|
---|
35 | }
|
---|
36 |
|
---|
37 | if (duplicates.Any()) Assert.Fail("Duplicate GUIDs found.");
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.