source: stable/HeuristicLab.Tests/HeuristicLab.Persistence.Attic/PersistenceConsistencyChecks.cs @ 17105

Last change on this file since 17105 was 17105, checked in by mkommend, 3 months ago

#2520: Merged 16584, 16585,16594,16595, 16625, 16658, 16659, 16672, 16707, 16729, 16792, 16796, 16797, 16799, 16819, 16906, 16907, 16908, 16933, 16945, 16992, 16994, 16995, 16996, 16997, 17014, 17015, 17017, 17020, 17021, 17022, 17023, 17024, 17029, 17086, 17087, 17088, 17089 into stable.

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HEAL.Attic;
5using HeuristicLab.PluginInfrastructure;
6using Microsoft.VisualStudio.TestTools.UnitTesting;
7
8namespace HeuristicLab.Tests.Persistence.Attic {
9  [TestClass]
10  public class PersistenceConsistencyChecks {
11    [TestCategory("Persistence.Attic")]
12    [TestCategory("Essential")]
13    [TestProperty("Time", "short")]
14    [TestMethod]
15    public void CheckDuplicateGUIDs() {
16      // easy to produce duplicate GUIDs with copy&paste
17
18      var dict = new Dictionary<Guid, string>();
19      var duplicates = new Dictionary<string, string>();
20      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(object))) {
21        var attr = StorableTypeAttribute.GetStorableTypeAttribute(type);
22        if (attr == null)
23          continue;
24
25        foreach (var guid in attr.Guids) {
26          if (!dict.ContainsKey(guid)) {
27            dict.Add(guid, type.FullName);
28          } else {
29            duplicates.Add(type.FullName, dict[guid]);
30          }
31        }
32      }
33
34      foreach (var kvp in duplicates) {
35        Console.WriteLine($"{kvp.Key} has same GUID as {kvp.Value}");
36      }
37      if (duplicates.Any()) Assert.Fail("Duplicate GUIDs found.");
38    }
39  }
40}
Note: See TracBrowser for help on using the repository browser.