public void ProteinBenchmarkService_Update_CreatesNewBenchmark()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var container           = CreateTestDataContainer(artifacts.GetRandomFilePath());
                int containerCount      = container.Data.Count;
                var benchmarkService    = new ProteinBenchmarkService(container);
                var clientGuid          = Guid.NewGuid();
                var slotIdentifier      = new SlotIdentifier(new ClientIdentifier("New Client", "10.9.8.1", ClientSettings.DefaultPort, clientGuid), 0);
                var benchmarkIdentifier = new ProteinBenchmarkIdentifier(Int32.MaxValue, Processor, Threads);
                var frameTimes          = new[]
                {
                    TimeSpan.FromMinutes(1.0),
                    TimeSpan.FromMinutes(1.2),
                    TimeSpan.FromMinutes(1.1)
                };
                // Act
                benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes);
                // Assert
                Assert.AreEqual(containerCount + 1, container.Data.Count);
                var benchmark = benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier);
                Assert.IsNotNull(benchmark);
                Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier);
                Assert.AreEqual(clientGuid, benchmark.SlotIdentifier.ClientIdentifier.Guid);
                Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier);

                Assert.AreEqual(3, benchmark.FrameTimes.Count);
                Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmark.FrameTimes[0].Duration);
                Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmark.FrameTimes[1].Duration);
                Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmark.FrameTimes[2].Duration);
            }
        }
        public void ProteinBenchmarkService_Update_BenchmarkWithoutProcessorAndThreadsMatchesBenchmarkIdentifierByProjectID()
        {
            const int projectID = 9039;

            var container      = new ProteinBenchmarkDataContainer();
            var slotIdentifier = new SlotIdentifier(new ClientIdentifier("Foo", "192.168.1.194", ClientSettings.DefaultPort, Guid.NewGuid()), 0);

            container.Data.Add(new ProteinBenchmark {
                ProjectID = projectID
            }
                               .UpdateFromSlotIdentifier(slotIdentifier));
            var benchmarkService = new ProteinBenchmarkService(container);

            var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID, Processor, Threads);
            var frameTimes = new[] { 1.0, 1.2, 1.1 }.Select(TimeSpan.FromMinutes);

            // Act
            var benchmark = benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes);

            // Assert
            Assert.AreEqual(1, container.Data.Count);
            Assert.IsNotNull(benchmark);
            Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier);
            Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier);

            var benchmarkFrameTimes = benchmark.FrameTimes.Take(3).ToList();

            Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmarkFrameTimes[0].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmarkFrameTimes[1].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmarkFrameTimes[2].Duration);
        }
        public void ProteinBenchmarkService_Update_AddsFrameTimes()
        {
            var       guid      = Guid.NewGuid();
            const int slotID    = 0;
            const int projectID = 9039;

            var container = new ProteinBenchmarkDataContainer();

            container.Data.Add(new ProteinBenchmark {
                SourceGuid = guid, SourceSlotID = slotID, ProjectID = projectID
            });
            var benchmarkService = new ProteinBenchmarkService(container);

            var slotIdentifier = new SlotIdentifier(new ClientIdentifier(null, null, ClientSettings.NoPort, guid), slotID);
            var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID);
            var frameTimes = new[] { 1.0, 1.2, 1.1 }.Select(TimeSpan.FromMinutes);

            // Act
            var benchmark = benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes);

            // Assert
            Assert.AreEqual(1, container.Data.Count);
            Assert.IsNotNull(benchmark);
            Assert.AreEqual(3, benchmark.FrameTimes.Count);
            Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmark.FrameTimes[0].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmark.FrameTimes[1].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmark.FrameTimes[2].Duration);
        }
        public void ProteinBenchmarkService_Update_BenchmarkWithoutGuidMatchesSlotIdentifierByNameAndPath()
        {
            var       guid      = Guid.NewGuid();
            const int slotID    = 0;
            const int projectID = 9039;

            var container = new ProteinBenchmarkDataContainer();

            container.Data.Add(new ProteinBenchmark
            {
                SourceName   = "Foo",
                SourcePath   = "192.168.1.194:36330",
                SourceGuid   = Guid.Empty,
                SourceSlotID = slotID,
                ProjectID    = projectID,
                FrameTimes   = new[] { 1.4, 1.6, 1.5 }.Select(ProteinBenchmarkFrameTime.FromMinutes).ToList()
            });
            var benchmarkService = new ProteinBenchmarkService(container);

            var slotIdentifier = new SlotIdentifier(new ClientIdentifier("Foo", "192.168.1.194", ClientSettings.DefaultPort, guid), slotID);
            var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID);
            var frameTimes = new[] { 1.0, 1.2, 1.1 }.Select(TimeSpan.FromMinutes);

            // Act
            var benchmark = benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes);

            // Assert
            Assert.AreEqual(1, container.Data.Count);
            Assert.IsNotNull(benchmark);
            Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier);
            Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier);

            var benchmarkFrameTimes = benchmark.FrameTimes.Take(3).ToList();

            Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmarkFrameTimes[0].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmarkFrameTimes[1].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmarkFrameTimes[2].Duration);
        }
        public void ProteinBenchmarkService_Update_ThrowsWhenFrameTimesIsNull()
        {
            var benchmarkService = new ProteinBenchmarkService(new ProteinBenchmarkDataContainer());

            Assert.Throws <ArgumentNullException>(() => benchmarkService.Update(new SlotIdentifier(), new ProteinBenchmarkIdentifier(), null));
        }
        public void ProteinBenchmarkService_Update_ThrowsWhenSlotIdentifierIsAllSlots()
        {
            var benchmarkService = new ProteinBenchmarkService(new ProteinBenchmarkDataContainer());

            Assert.Throws <ArgumentException>(() => benchmarkService.Update(SlotIdentifier.AllSlots, new ProteinBenchmarkIdentifier(), new List <TimeSpan>()));
        }