Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Tests/HeuristicLab.Persistence.Attic/PersistenceConsistencyChecks.cs @ 16988

Last change on this file since 16988 was 16988, checked in by gkronber, 5 years ago

#2925: Merge r16894:16983 from trunk to branch

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      //get all non-generic and instantiable classes which implement IContentView
21      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(object))) {
22        var attr = StorableTypeAttribute.GetStorableTypeAttribute(type);
23        if (attr == null)
24          continue;
25
26        foreach (var guid in attr.Guids) {
27          if (!dict.ContainsKey(guid)) {
28            dict.Add(guid, type.FullName);
29          } else {
30            duplicates.Add(type.FullName, dict[guid]);
31          }
32        }
33      }
34
35      foreach (var kvp in duplicates) {
36        Console.WriteLine($"{kvp.Key} has same GUID as {kvp.Value}");
37      }
38      if (duplicates.Any()) Assert.Fail("Duplicate GUIDs found.");
39    }
40  }
41}
Note: See TracBrowser for help on using the repository browser.