Esempio n. 1
0
        public void UpdateBenchmarkDataTest()
        {
            // setup
            var benchmarkCollection = new ProteinBenchmarkService();
            var database            = MockRepository.GenerateMock <IUnitInfoDatabase>();
            var legacyClient        = new LegacyClient {
                BenchmarkService = benchmarkCollection, UnitInfoDatabase = database
            };

            var unitInfo1 = new UnitInfo();

            unitInfo1.OwningClientName = "Owner";
            unitInfo1.OwningClientPath = "Path";
            unitInfo1.ProjectID        = 2669;
            unitInfo1.ProjectRun       = 1;
            unitInfo1.ProjectClone     = 2;
            unitInfo1.ProjectGen       = 3;
            unitInfo1.FinishedTime     = new DateTime(2010, 1, 1);
            var currentUnitInfo = new UnitInfoModel {
                CurrentProtein = new Protein(), UnitInfoData = unitInfo1
            };

            var unitInfo1Clone = unitInfo1.DeepClone();

            unitInfo1Clone.FramesObserved = 4;
            unitInfo1Clone.SetUnitFrame(new UnitFrame {
                TimeOfFrame = TimeSpan.FromMinutes(0), FrameID = 0
            });
            unitInfo1Clone.SetUnitFrame(new UnitFrame {
                TimeOfFrame = TimeSpan.FromMinutes(5), FrameID = 1
            });
            unitInfo1Clone.SetUnitFrame(new UnitFrame {
                TimeOfFrame = TimeSpan.FromMinutes(10), FrameID = 2
            });
            unitInfo1Clone.SetUnitFrame(new UnitFrame {
                TimeOfFrame = TimeSpan.FromMinutes(15), FrameID = 3
            });
            var unitInfoLogic1 = new UnitInfoModel {
                CurrentProtein = new Protein(), UnitInfoData = unitInfo1Clone
            };

            var unitInfo2 = new UnitInfo();

            unitInfo2.OwningClientName = "Owner";
            unitInfo2.OwningClientPath = "Path";
            unitInfo2.ProjectID        = 2669;
            unitInfo2.ProjectRun       = 2;
            unitInfo2.ProjectClone     = 3;
            unitInfo2.ProjectGen       = 4;
            unitInfo2.FinishedTime     = new DateTime(2010, 1, 1);
            var unitInfoLogic2 = new UnitInfoModel {
                CurrentProtein = new Protein(), UnitInfoData = unitInfo2
            };

            var unitInfo3 = new UnitInfo();

            unitInfo3.OwningClientName = "Owner";
            unitInfo3.OwningClientPath = "Path";
            unitInfo3.ProjectID        = 2669;
            unitInfo3.ProjectRun       = 3;
            unitInfo3.ProjectClone     = 4;
            unitInfo3.ProjectGen       = 5;
            unitInfo3.FinishedTime     = new DateTime(2010, 1, 1);
            var unitInfoLogic3 = new UnitInfoModel {
                CurrentProtein = new Protein(), UnitInfoData = unitInfo3
            };

            var parsedUnits = new[] { unitInfoLogic1, unitInfoLogic2, unitInfoLogic3 };

            // arrange
            database.Stub(x => x.Connected).Return(true);
            database.Expect(x => x.Insert(null)).IgnoreArguments().Repeat.Times(3);

            var benchmarkClient = new ProteinBenchmarkSlotIdentifier("Owner", "Path");

            // assert before act
            Assert.AreEqual(false, benchmarkCollection.Contains(benchmarkClient));
            Assert.AreEqual(false, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669));
            Assert.IsNull(benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData));

            // act
            legacyClient.UpdateBenchmarkData(currentUnitInfo, parsedUnits, 2);

            // assert after act
            Assert.AreEqual(true, benchmarkCollection.Contains(benchmarkClient));
            Assert.AreEqual(true, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669));
            Assert.AreEqual(TimeSpan.FromMinutes(5), benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData).AverageFrameTime);

            database.VerifyAllExpectations();
        }
Esempio n. 2
0
      public void UpdateBenchmarkDataTest()
      {
         // setup
         var benchmarkCollection = new ProteinBenchmarkCollection();
         var database = MockRepository.GenerateMock<IUnitInfoDatabase>();
         var legacyClient = new LegacyClient { BenchmarkCollection = benchmarkCollection, UnitInfoDatabase = database };

         var unitInfo1 = new UnitInfo();
         unitInfo1.OwningClientName = "Owner";
         unitInfo1.OwningClientPath = "Path";
         unitInfo1.ProjectID = 2669;
         unitInfo1.ProjectRun = 1;
         unitInfo1.ProjectClone = 2;
         unitInfo1.ProjectGen = 3;
         unitInfo1.FinishedTime = new DateTime(2010, 1, 1);
         var currentUnitInfo = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1 };

         var unitInfo1Clone = unitInfo1.DeepClone();
         unitInfo1Clone.FramesObserved = 4;
         unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(0), FrameID = 0 });
         unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(5), FrameID = 1 });
         unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(10), FrameID = 2 });
         unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(15), FrameID = 3 });
         var unitInfoLogic1 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1Clone };

         var unitInfo2 = new UnitInfo();
         unitInfo2.OwningClientName = "Owner";
         unitInfo2.OwningClientPath = "Path";
         unitInfo2.ProjectID = 2669;
         unitInfo2.ProjectRun = 2;
         unitInfo2.ProjectClone = 3;
         unitInfo2.ProjectGen = 4;
         unitInfo2.FinishedTime = new DateTime(2010, 1, 1);
         var unitInfoLogic2 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo2 };

         var unitInfo3 = new UnitInfo();
         unitInfo3.OwningClientName = "Owner";
         unitInfo3.OwningClientPath = "Path";
         unitInfo3.ProjectID = 2669;
         unitInfo3.ProjectRun = 3;
         unitInfo3.ProjectClone = 4;
         unitInfo3.ProjectGen = 5;
         unitInfo3.FinishedTime = new DateTime(2010, 1, 1);
         var unitInfoLogic3 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo3 };

         var parsedUnits = new[] { unitInfoLogic1, unitInfoLogic2, unitInfoLogic3 };

         // arrange
         database.Stub(x => x.Connected).Return(true);
         database.Expect(x => x.Insert(null)).IgnoreArguments().Repeat.Times(3);

         var benchmarkClient = new BenchmarkClient("Owner", "Path");

         // assert before act
         Assert.AreEqual(false, benchmarkCollection.Contains(benchmarkClient));
         Assert.AreEqual(false, new List<int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669));
         Assert.IsNull(benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData));

         // act
         legacyClient.UpdateBenchmarkData(currentUnitInfo, parsedUnits, 2);

         // assert after act
         Assert.AreEqual(true, benchmarkCollection.Contains(benchmarkClient));
         Assert.AreEqual(true, new List<int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669));
         Assert.AreEqual(TimeSpan.FromMinutes(5), benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData).AverageFrameTime);

         database.VerifyAllExpectations();
      }