Changeset 16578


Ignore:
Timestamp:
01/29/19 09:51:03 (3 weeks ago)
Author:
gkronber
Message:

#2520: changed unit tests which load old samples and try storing and loading using the new format to recreate all sample files first

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Tests/HeuristicLab.Persistence.Attic/UseCases.cs

    r16559 r16578  
    3535using HeuristicLab.Persistence.Core;
    3636using HeuristicLab.Persistence.Default.Xml;
     37using HeuristicLab.Tests;
    3738using Microsoft.VisualStudio.TestTools.UnitTesting;
    3839
     
    132133    }
    133134
     135    private void CreateAllSamples() {
     136      var asm = this.GetType().Assembly;
     137      foreach (var t in asm.GetTypes()) {
     138        var attrs = t.GetCustomAttributes<TestClassAttribute>();
     139        if (attrs.Any()) {
     140          try {
     141            var testObj = Activator.CreateInstance(t);
     142            foreach (var mi in t.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) {
     143              var mAttrs = mi.GetCustomAttributes<TestCategoryAttribute>();
     144              var testCategories = mAttrs.SelectMany(mattr => mattr.TestCategories);
     145              if (testCategories.Any(tc => tc == "Samples.Create")) {
     146                mi.Invoke(testObj, new object[0]);
     147              }
     148            }
     149          } catch (Exception) { }
     150        }
     151      }
     152    }
    134153
    135154    [TestMethod]
     
    137156    [TestProperty("Time", "long")]
    138157    public void TestLoadingSamples() {
    139       var path = @"C:\reps\hl-core\branches\2520_PersistenceReintegration\HeuristicLab.Optimizer\3.3\Documents";
     158      CreateAllSamples();
     159      var path = SamplesUtils.SamplesDirectory;
    140160      var serializer = new ProtoBufSerializer();
    141161      foreach (var fileName in Directory.EnumerateFiles(path, "*.hl")) {
     
    162182          var newVersion = serializer.Deserialize(fileName + ".proto");
    163183          Console.WriteLine("File: " + fileName);
    164         }
    165       }
    166     }
     184          File.Delete(fileName + ".proto");
     185        }
     186      }
     187    }
     188
    167189    [TestMethod]
    168190    [TestCategory("Persistence.Attic")]
    169191    [TestProperty("Time", "long")]
    170192    public void TestLoadingRunAndStoreSamples() {
    171       var path = @"C:\reps\hl-core\branches\2520_PersistenceReintegration\HeuristicLab.Optimizer\3.3\Documents";
     193      CreateAllSamples();
     194      var path = SamplesUtils.SamplesDirectory;
    172195      var serializer = new ProtoBufSerializer();
    173196      foreach (var fileName in Directory.EnumerateFiles(path, "*.hl")) {
     
    178201          exec.Paused += (sender, e) => {
    179202            serializer.Serialize(exec, fileName + "_paused.proto");
    180             Console.WriteLine("Paused File: " + fileName);
     203            Console.WriteLine("Serialized paused file: " + fileName);
     204            File.Delete(fileName + "_paused.proto");
    181205          };
    182206          exec.Stopped += (sender, e) => {
    183207            serializer.Serialize(exec, fileName + "_stopped.proto");
    184             Console.WriteLine("Stopped File: " + fileName);
     208            Console.WriteLine("Serialized stopped file: " + fileName);
     209            File.Delete(fileName + "_stopped.proto");
    185210          };
    186211          var t = exec.StartAsync();
Note: See TracChangeset for help on using the changeset viewer.