PageRenderTime 178ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/HFM.Instances.Tests/UnitInfoContainerTests.cs

http://hfm-net.googlecode.com/
C# | 136 lines | 102 code | 16 blank | 18 comment | 4 complexity | bad41be3a7ef71bcd0001de95e41d07f MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0, LGPL-2.1
  1. /*
  2. * HFM.NET - UnitInfo Container Class Tests
  3. * Copyright (C) 2009-2011 Ryan Harlamert (harlam357)
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; version 2
  8. * of the License. See the included file GPLv2.TXT.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. using System;
  20. using NUnit.Framework;
  21. using HFM.Framework.DataTypes;
  22. namespace HFM.Instances.Tests
  23. {
  24. [TestFixture]
  25. public class UnitInfoContainerTests
  26. {
  27. UnitInfoCollection _collection;
  28. [SetUp]
  29. public void Init()
  30. {
  31. _collection = LoadTestCollection();
  32. ValidateTestCollection(_collection);
  33. }
  34. [Test]
  35. public void ProtoBufSerializationTest()
  36. {
  37. UnitInfoContainer.Serialize(_collection, "UnitInfoProtoBufTest.dat");
  38. UnitInfoCollection collection2 = UnitInfoContainer.Deserialize("UnitInfoProtoBufTest.dat");
  39. ValidateTestCollection(collection2);
  40. }
  41. [Test]
  42. public void ProtoBufDeserializeFileNotFoundTest()
  43. {
  44. UnitInfoCollection testCollection = UnitInfoContainer.Deserialize("FileNotFound.dat");
  45. Assert.IsNull(testCollection);
  46. }
  47. private static UnitInfoCollection LoadTestCollection()
  48. {
  49. var testCollection = new UnitInfoCollection();
  50. for (int i = 0; i < 10; i++)
  51. {
  52. var unitInfo = new UnitInfo();
  53. unitInfo.OwningInstanceName = "TestOwner";
  54. unitInfo.OwningInstancePath = "TestPath";
  55. unitInfo.UnitRetrievalTime = new DateTime((2000 + i), 1, 1, 0, 0, 0);
  56. unitInfo.FoldingID = "TestID";
  57. unitInfo.Team = 32;
  58. unitInfo.TypeOfClient = ClientType.Standard;
  59. unitInfo.DownloadTime = new DateTime(2000, 2, 2, 0, 0, 0);
  60. unitInfo.DueTime = new DateTime(2000, 3, 3, 0, 0, 0);
  61. unitInfo.UnitStartTimeStamp = TimeSpan.FromHours(i + 1);
  62. unitInfo.FinishedTime = new DateTime(2000, 4, 4, 0, 0, 0);
  63. unitInfo.CoreVersion = "2.10";
  64. unitInfo.ProjectID = 2669;
  65. unitInfo.ProjectRun = 1;
  66. unitInfo.ProjectClone = 2;
  67. unitInfo.ProjectGen = 3;
  68. unitInfo.ProteinName = "Protein";
  69. unitInfo.ProteinTag = "ProteinTag";
  70. unitInfo.UnitResult = WorkUnitResult.CoreOutdated;
  71. unitInfo.RawFramesComplete = 2500;
  72. unitInfo.RawFramesTotal = 250000;
  73. for (int j = 0; j < 4; j++)
  74. {
  75. var unitFrame = new UnitFrame { FrameID = j, TimeOfFrame = TimeSpan.FromMinutes(j + 1) };
  76. unitInfo.UnitFrames.Add(j, unitFrame);
  77. }
  78. unitInfo.FramesObserved = 4;
  79. testCollection.UnitInfoList.Add(unitInfo);
  80. }
  81. return testCollection;
  82. }
  83. private static void ValidateTestCollection(UnitInfoCollection collection)
  84. {
  85. for (int i = 0; i < 10; i++)
  86. {
  87. UnitInfo unitInfo = collection.UnitInfoList[i];
  88. Assert.AreEqual("TestOwner", unitInfo.OwningInstanceName);
  89. Assert.AreEqual("TestPath", unitInfo.OwningInstancePath);
  90. Assert.AreEqual(new DateTime((2000 + i), 1, 1, 0, 0, 0), unitInfo.UnitRetrievalTime);
  91. Assert.AreEqual("TestID", unitInfo.FoldingID);
  92. Assert.AreEqual(32, unitInfo.Team);
  93. Assert.AreEqual(ClientType.Standard, unitInfo.TypeOfClient);
  94. Assert.AreEqual(new DateTime(2000, 2, 2, 0, 0, 0), unitInfo.DownloadTime);
  95. Assert.AreEqual(new DateTime(2000, 3, 3, 0, 0, 0), unitInfo.DueTime);
  96. Assert.AreEqual(TimeSpan.FromHours(i + 1), unitInfo.UnitStartTimeStamp);
  97. Assert.AreEqual(new DateTime(2000, 4, 4, 0, 0, 0), unitInfo.FinishedTime);
  98. Assert.AreEqual("2.10", unitInfo.CoreVersion);
  99. Assert.AreEqual(2669, unitInfo.ProjectID);
  100. Assert.AreEqual(1, unitInfo.ProjectRun);
  101. Assert.AreEqual(2, unitInfo.ProjectClone);
  102. Assert.AreEqual(3, unitInfo.ProjectGen);
  103. Assert.AreEqual("Protein", unitInfo.ProteinName);
  104. Assert.AreEqual("ProteinTag", unitInfo.ProteinTag);
  105. Assert.AreEqual(WorkUnitResult.CoreOutdated, unitInfo.UnitResult);
  106. Assert.AreEqual(2500, unitInfo.RawFramesComplete);
  107. Assert.AreEqual(250000, unitInfo.RawFramesTotal);
  108. IUnitFrame unitFrame = null;
  109. for (int j = 0; j < 4; j++)
  110. {
  111. unitFrame = unitInfo.UnitFrames[j];
  112. Assert.AreEqual(j, unitFrame.FrameID);
  113. Assert.AreEqual(TimeSpan.FromMinutes(j + 1), unitFrame.TimeOfFrame);
  114. }
  115. Assert.AreEqual(4, unitInfo.FramesObserved);
  116. Assert.AreEqual(unitFrame, unitInfo.CurrentFrame);
  117. }
  118. }
  119. }
  120. }