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 async Task ApplicationUpdatePresenter_DownloadClicked_ShowsMessageBoxWhenDownloadFails()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var updateFile = new ApplicationUpdateFile {
                    Description = "Foo", Name = "Foo.zip", HttpAddress = @"C:\DoesNotExist\Foo.zip"
                };
                var update = new ApplicationUpdate
                {
                    UpdateFiles = new List <ApplicationUpdateFile> {
                        updateFile
                    }
                };
                var model = new ApplicationUpdateModel(update);
                model.SelectedUpdateFile = update.UpdateFiles.First();

                var messageBox = new MockMessageBoxPresenter();
                using (var presenter = new MockDialogApplicationUpdatePresenter(model, messageBox))
                {
                    presenter.ShowDialog(null);
                    Assert.IsTrue(presenter.MockDialog.Shown);
                    // Act
                    var saveFile = new MockFileDialogPresenterReturnsFileName(_ => DialogResult.OK, artifacts.GetRandomFilePath());
                    await presenter.DownloadClick(saveFile);

                    // Assert
                    Assert.AreEqual(1, messageBox.Invocations.Count);
                    Assert.IsTrue(presenter.MockDialog.Shown);
                    Assert.AreEqual(1, saveFile.Invocations.Count);
                }
            }
        }
        public async Task FahClientMessages_UpdateMessageAsync_ReturnsNotificationThatClientDataShouldBeUpdatedWhenSlotInformationHasChangedAfterLogIsRetrieved()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages  = new FahClientMessages(fahClient);
                var slotInfo  = CreateMessage(FahClientMessageType.SlotInfo, "[ { \"id\": \"00\" } ]");
                await messages.UpdateMessageAsync(slotInfo);

                var logRestart = CreateMessage(FahClientMessageType.LogRestart, "\"Log\"");
                await messages.UpdateMessageAsync(logRestart);

                slotInfo = CreateMessage(FahClientMessageType.SlotInfo, "[ { \"id\": \"00\", \"description\": \"cpu:15\" } ]");
                var slotOptions = CreateMessage(FahClientMessageType.SlotOptions, "{ \"machine-id\": \"0\" }");
                // Act
                var result = await messages.UpdateMessageAsync(slotInfo);

                // Assert
                Assert.IsTrue(messages.LogIsRetrieved);
                Assert.IsFalse(result.SlotsUpdated);
                Assert.IsFalse(result.ExecuteRetrieval);
                // Act
                result = await messages.UpdateMessageAsync(slotOptions);

                // Assert
                Assert.IsTrue(messages.LogIsRetrieved);
                Assert.IsTrue(result.SlotsUpdated);
                Assert.IsTrue(result.ExecuteRetrieval);
            }
        }
        public void ProteinBenchmarkService_ValidateProteinBenchmarkEqualityComparerMatchesWithoutConsideringClientIdentifierGuid()
        {
            using (var artifacts = new ArtifactFolder())
            {
                var container = CreateTestDataContainer(artifacts.GetRandomFilePath(), "BenchmarkCache_0_9_13.dat");

                var benchmarksWithGuid            = container.Data.Where(x => x.SlotIdentifier.ClientIdentifier.HasGuid).ToList();
                var benchmarksWithGuidIdentifiers = benchmarksWithGuid.Select(x => x.SlotIdentifier).Distinct().ToList();
                foreach (var identifier in benchmarksWithGuidIdentifiers)
                {
                    Console.WriteLine(identifier);
                }

                var identifierMatchesWhenGuidIsNotConsidered = new Func <ProteinBenchmark, bool>(b =>
                                                                                                 benchmarksWithGuidIdentifiers.Any(x => SlotIdentifier.ProteinBenchmarkEqualityComparer.Equals(b.SlotIdentifier, x)));

                var allBenchmarks         = container.Data.Where(b => identifierMatchesWhenGuidIsNotConsidered(b)).ToList();
                var benchmarksWithoutGuid = allBenchmarks.Where(b => !b.SlotIdentifier.ClientIdentifier.HasGuid).ToList();

                Console.WriteLine($"Benchmarks with Guid: {benchmarksWithGuid.Count}");
                Console.WriteLine($"Benchmarks without Guid: {benchmarksWithoutGuid.Count}");
                Console.WriteLine($"All Benchmarks: {allBenchmarks.Count}");

                Assert.AreEqual(benchmarksWithGuid.Count + benchmarksWithoutGuid.Count, allBenchmarks.Count);
            }
        }
        public void ClientSettingsFileSerializer_RoundTrip_FromFile()
        {
            // Arrange
            var guid   = Guid.NewGuid();
            var toFile = new List <ClientSettings> {
                new ClientSettings
                {
                    ClientType = ClientType.FahClient,
                    Name       = "Foo",
                    Server     = "Bar",
                    Port       = 12345,
                    Password   = "******",
                    Guid       = guid
                }
            };
            var serializer = new ClientSettingsFileSerializer(null);

            using (var artifacts = new ArtifactFolder())
            {
                string path = artifacts.GetRandomFilePath();
                // Act
                serializer.Serialize(path, toFile);
                var fromFile = serializer.Deserialize(path);
                // Assert
                Assert.AreEqual(toFile.Count, fromFile.Count);
                var to   = toFile.First();
                var from = fromFile.First();
                Assert.AreEqual(to.ClientType, from.ClientType);
                Assert.AreEqual(to.Name, from.Name);
                Assert.AreEqual(to.Server, from.Server);
                Assert.AreEqual(to.Port, from.Port);
                Assert.AreEqual(to.Password, from.Password);
                Assert.AreEqual(to.Guid, from.Guid);
            }
        }
Example #6
0
        public void WebArtifactBuilder_Build_CreatesDirectoryWithXmlHtmlAndLogFiles()
        {
            using (var appDataFolder = new ArtifactFolder())
            {
                var preferences = CreatePreferences(appDataFolder.Path);
                preferences.Set(Preference.WebGenCopyHtml, true);
                preferences.Set(Preference.WebGenCopyFAHlog, true);

                string cacheDirectory = preferences.Get <string>(Preference.CacheDirectory);
                Directory.CreateDirectory(cacheDirectory);

                var slots = CreateSlotModelCollection();
                foreach (var slot in slots)
                {
                    using (var stream = File.Create(Path.Combine(cacheDirectory, $"{slot.Name}-log.txt")))
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.WriteLine(slot.Name);
                        }
                }

                using (var artifacts = new ArtifactFolder())
                {
                    var artifactBuilder = new WebArtifactBuilder(null, preferences, artifacts.Path);
                    var path            = artifactBuilder.Build(slots);

                    Assert.IsTrue(Directory.EnumerateFiles(path).Any(x => Path.GetExtension(x) == ".xml"));
                    Assert.IsTrue(Directory.EnumerateFiles(path).Any(x => Path.GetExtension(x) == ".html"));
                    Assert.IsTrue(Directory.EnumerateFiles(path).Any(x => Path.GetExtension(x) == ".txt"));
                }
            }
        }
 public void ProteinBenchmarkService_GetSlotIdentifiers_ReturnsDistinctValuesFromAllBenchmarks()
 {
     // Arrange
     using (var artifacts = new ArtifactFolder())
     {
         var container        = CreateTestDataContainer(artifacts.GetRandomFilePath());
         var benchmarkService = new ProteinBenchmarkService(container);
         // Act
         var identifiers = benchmarkService.GetSlotIdentifiers();
         // Assert
         Assert.AreEqual(11, identifiers.Count);
     }
 }
 public void ProteinBenchmarkService_GetBenchmarks_ForAllSlotsAndSpecificProjects()
 {
     // Arrange
     using (var artifacts = new ArtifactFolder())
     {
         var container        = CreateTestDataContainer(artifacts.GetRandomFilePath());
         var benchmarkService = new ProteinBenchmarkService(container);
         // Act
         var benchmarks = benchmarkService.GetBenchmarks(SlotIdentifier.AllSlots, new[] { 9039, 9032 });
         // Assert
         Assert.AreEqual(8, benchmarks.Count);
     }
 }
 public void ProteinBenchmarkService_RemoveAll_ForSpecificSlot()
 {
     // Arrange
     using (var artifacts = new ArtifactFolder())
     {
         var container        = CreateTestDataContainer(artifacts.GetRandomFilePath());
         var benchmarkService = new ProteinBenchmarkService(container);
         // Act
         benchmarkService.RemoveAll(benchmarkService.GetSlotIdentifiers().First());
         // Assert
         Assert.AreEqual(647, container.Data.Count);
     }
 }
 public void ProteinBenchmarkService_RemoveAll_ForAllSlotsAndSpecificProject()
 {
     // Arrange
     using (var artifacts = new ArtifactFolder())
     {
         var container        = CreateTestDataContainer(artifacts.GetRandomFilePath());
         var benchmarkService = new ProteinBenchmarkService(container);
         // Act
         benchmarkService.RemoveAll(SlotIdentifier.AllSlots, 9039);
         // Assert
         Assert.AreEqual(688, container.Data.Count);
     }
 }
 public void ProteinBenchmarkService_GetBenchmarkProjects_ForSpecificSlot()
 {
     // Arrange
     using (var artifacts = new ArtifactFolder())
     {
         var container        = CreateTestDataContainer(artifacts.GetRandomFilePath());
         var benchmarkService = new ProteinBenchmarkService(container);
         // Act
         var projects = benchmarkService.GetBenchmarkProjects(benchmarkService.GetSlotIdentifiers().First());
         // Assert
         Assert.AreEqual(45, projects.Count);
     }
 }
Example #12
0
        public void ApplicationUpdateFile_Verify_ThrowsWhenFileSizeDoesNotMatch()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                string path = artifacts.GetRandomFilePath();
                File.WriteAllText(path, "FoobarFizzbizz");

                var updateFile = new ApplicationUpdateFile {
                    Size = 0
                };
                // Act
                Assert.Throws <IOException>(() => updateFile.Verify(path));
            }
        }
Example #13
0
        public void ProteinBenchmark_WriteWithDataContractFileSerializer()
        {
            // Arrange
            var data       = CreateTestBenchmarkData();
            var serializer = new DataContractFileSerializer <List <ProteinBenchmark> >();

            using (var artifacts = new ArtifactFolder())
            {
                string path = artifacts.GetRandomFilePath();
                // Act
                serializer.Serialize(path, data);
                // Assert
                var fromXml = serializer.Deserialize(path);
                ValidateTestBenchmarkData(fromXml);
            }
        }
        public async Task FahClientMessages_UpdateMessageAsync_LogIsNotRetrievedUntilMessageLengthIsNotLarge()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient  = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages   = new FahClientMessages(fahClient);
                var logText    = new String(Enumerable.Repeat('a', UInt16.MaxValue).ToArray());
                var logRestart = CreateMessage(FahClientMessageType.LogRestart, $"\"{logText}\"");
                // Act
                await messages.UpdateMessageAsync(logRestart);

                // Assert
                Assert.IsFalse(messages.LogIsRetrieved);
            }
        }
        public async Task FahClientMessages_UpdateMessageAsync_WritesLogMessagesToCachedClientLogFile()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient  = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages   = new FahClientMessages(fahClient);
                var logRestart = CreateMessage(FahClientMessageType.LogRestart, "\"Log\"");
                // Act
                await messages.UpdateMessageAsync(logRestart);

                // Assert
                string path = Path.Combine(fahClient.Preferences.Get <string>(Preference.CacheDirectory), fahClient.Settings.ClientLogFileName);
                Assert.IsTrue(File.Exists(path));
            }
        }
        public async Task FahClientMessages_UpdateMessageAsync_StoresLogMessagesInFahClientLog()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient  = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages   = new FahClientMessages(fahClient);
                var logRestart = CreateMessage(FahClientMessageType.LogRestart, "\"Log\"");
                // Act
                var result = await messages.UpdateMessageAsync(logRestart);

                // Assert
                Assert.AreEqual(1, messages.Log.ClientRuns[0].LogLines.Count);
                Assert.IsFalse(result.SlotsUpdated);
                Assert.IsTrue(result.ExecuteRetrieval);
            }
        }
Example #17
0
        public void WebArtifactBuilder_Build_CreatesDirectoryWithXmlAndHtmlFiles()
        {
            var preferences = CreatePreferences();

            preferences.Set(Preference.WebGenCopyHtml, true);

            var slots = CreateSlotModelCollection();

            using (var artifacts = new ArtifactFolder())
            {
                var artifactBuilder = new WebArtifactBuilder(null, preferences, artifacts.Path);
                var path            = artifactBuilder.Build(slots);

                Assert.IsTrue(Directory.EnumerateFiles(path).Any(x => Path.GetExtension(x) == ".xml"));
                Assert.IsTrue(Directory.EnumerateFiles(path).Any(x => Path.GetExtension(x) == ".html"));
                Assert.IsFalse(Directory.EnumerateFiles(path).Any(x => Path.GetExtension(x) == ".txt"));
            }
        }
Example #18
0
 public void ProteinBenchmarkDataContainer_Write_ToDisk()
 {
     // Arrange
     using (var artifacts = new ArtifactFolder())
     {
         var collection = new ProteinBenchmarkDataContainer
         {
             FilePath = artifacts.GetRandomFilePath(), Data = CreateTestBenchmarkData(),
         };
         // Act
         collection.Write();
         // Assert
         // clear the data and read it
         collection.Data = null;
         collection.Read();
         ValidateTestBenchmarkData(collection.Data);
     }
 }
        public void ClientSettingsFileSerializer_Serialize_GeneratesGuidValuesWhenGuidIsEmpty()
        {
            // Arrange
            var toFile = new List <ClientSettings> {
                new ClientSettings()
            };
            var serializer = new ClientSettingsFileSerializer(null);

            using (var artifacts = new ArtifactFolder())
            {
                string path = artifacts.GetRandomFilePath();
                // Act
                serializer.Serialize(path, toFile);
                var fromFile = serializer.Deserialize(path);
                // Assert
                var from = fromFile.First();
                Assert.AreNotEqual(Guid.Empty, from.Guid);
            }
        }
        public async Task FahClientMessages_Clear_RemovesAllMessageData()
        {
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages  = new FahClientMessages(fahClient);
                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.Heartbeat, String.Empty));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.Info, "[ ]"));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.Options, "{ }"));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.SlotInfo, "[ { \"id\": \"00\" } ]"));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.SlotOptions, "{ \"machine-id\": \"0\" }"));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.QueueInfo, "[ { \"id\": \"01\", \"slot\": 0 } ]"));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.LogRestart, "\"Log\""));

                // Assert (pre-condition)
                Assert.IsNotNull(messages.Heartbeat);
                Assert.IsNotNull(messages.Info);
                Assert.IsNotNull(messages.Options);
                Assert.IsNotNull(messages.SlotCollection);
                Assert.AreNotEqual(0, messages.SlotOptionsCollection.Count);
                Assert.IsNotNull(messages.UnitCollection);
                Assert.AreNotEqual(0, messages.Log.ClientRuns.Count);
                Assert.IsTrue(messages.LogIsRetrieved);
                // Act
                messages.Clear();
                // Assert
                Assert.IsNull(messages.Heartbeat);
                Assert.IsNull(messages.Info);
                Assert.IsNull(messages.Options);
                Assert.IsNull(messages.SlotCollection);
                Assert.AreEqual(0, messages.SlotOptionsCollection.Count);
                Assert.IsNull(messages.UnitCollection);
                Assert.AreEqual(0, messages.Log.ClientRuns.Count);
                Assert.IsFalse(messages.LogIsRetrieved);
            }
        }
        public async Task FahClientMessages_UpdateMessageAsync_ExecutesQueueInfoCommandWhenLogIsRetrieved()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient  = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var connection = (MockFahClientConnection)fahClient.Connection;
                var messages   = new FahClientMessages(fahClient);
                var logRestart = CreateMessage(FahClientMessageType.LogRestart, "\"Log\"");
                // Act
                await messages.UpdateMessageAsync(logRestart);

                // Assert
                Assert.IsTrue(messages.LogIsRetrieved);
                Assert.AreEqual(1, connection.Commands.Count);
                var command = connection.Commands[0];
                Assert.AreEqual("queue-info", command.CommandText);
                Assert.IsTrue(command.Executed);
            }
        }
        public void ClientSettingsManager_Write_WritesTheClientSettingsToDisk()
        {
            // Arrange
            var client = new NullClient();

            client.Settings = new ClientSettings {
                Name = "test"
            };
            using (var artifacts = new ArtifactFolder())
            {
                var    manager = new ClientSettingsManager(null);
                string path    = Path.ChangeExtension(artifacts.GetRandomFilePath(), ".hfmx");
                // Act
                manager.Write(new[] { client.Settings }, path, 1);
                // Assert
                Assert.AreEqual(path, manager.FileName);
                Assert.AreEqual(1, manager.FilterIndex);
                Assert.AreEqual(".hfmx", manager.FileExtension);
            }
        }
Example #23
0
        public void ApplicationUpdateFile_Verify_ThrowsWhenMD5DoesNotMatch()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                string path = artifacts.GetRandomFilePath();
                File.WriteAllText(path, "FoobarFizzbizz");

                var fileInfo = new FileInfo(path);

                var hash = new Hash(HashProvider.SHA1);
                var sha1 = hash.Calculate(File.OpenRead(path));

                var updateFile = new ApplicationUpdateFile {
                    Size = (int)fileInfo.Length, SHA1 = sha1.ToHex(), MD5 = "DoesNotMatch"
                };
                // Act
                Assert.Throws <IOException>(() => updateFile.Verify(path));
            }
        }
Example #24
0
        public void WebArtifactDeployment_Deploy_DeploysArtifactsToTargetPath(bool copyXml, bool copyHtml, bool copyLog, int expected)
        {
            using (var appDataFolder = new ArtifactFolder())
            {
                var preferences = CreatePreferences(appDataFolder.Path);
                preferences.Set(Preference.WebGenCopyXml, copyXml);
                preferences.Set(Preference.WebGenCopyHtml, copyHtml);
                preferences.Set(Preference.WebGenCopyFAHlog, copyLog);

                string cacheDirectory = preferences.Get <string>(Preference.CacheDirectory);
                Directory.CreateDirectory(cacheDirectory);

                var slots = CreateSlotModelCollection();
                foreach (var slot in slots)
                {
                    using (var stream = File.Create(Path.Combine(cacheDirectory, $"{slot.Name}-log.txt")))
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.WriteLine(slot.Name);
                        }
                }

                using (var artifacts = new ArtifactFolder())
                {
                    var artifactBuilder = new WebArtifactBuilder(null, preferences, artifacts.Path);
                    var path            = artifactBuilder.Build(slots);

                    using (var deployFolder = new ArtifactFolder())
                    {
                        preferences.Set(Preference.WebDeploymentRoot, deployFolder.Path);
                        var deployment = WebArtifactDeployment.Create(WebDeploymentType.Path, null, preferences);
                        deployment.Deploy(path);

                        Assert.AreEqual(expected, Directory.GetFiles(deployFolder.Path).Length);
                    }
                }
            }
        }
        public async Task ApplicationUpdatePresenter_DownloadClicked_WhenFileTypeIsExecutableSetsLocalFilePathAndReadyToBeExecuted()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                string sourceFile = artifacts.GetRandomFilePath();
                string targetFile = artifacts.GetRandomFilePath();

                var model = CreateUpdateModel(sourceFile, ApplicationUpdateFileType.Executable);
                using (var presenter = new MockDialogApplicationUpdatePresenter(model))
                {
                    presenter.ShowDialog(null);
                    // Act
                    var saveFile = new MockFileDialogPresenterReturnsFileName(_ => DialogResult.OK, targetFile);
                    await presenter.DownloadClick(saveFile);

                    // Assert
                    Assert.AreEqual(targetFile, model.SelectedUpdateFileLocalFilePath);
                    Assert.IsTrue(model.SelectedUpdateFileIsReadyToBeExecuted);
                    Assert.AreEqual(1, saveFile.Invocations.Count);
                }
            }
        }
        public async Task FahClientMessages_UpdateMessageAsync_ReturnsNotificationThatClientDataShouldBeUpdatedWhenUnitInformationHasChangedAfterLogIsRetrieved()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages  = new FahClientMessages(fahClient);
                var queueInfo = CreateMessage(FahClientMessageType.QueueInfo, "[ { \"id\": \"01\", \"slot\": 0, \"percentdone\": \"8%\" } ]");
                await messages.UpdateMessageAsync(queueInfo);

                var logRestart = CreateMessage(FahClientMessageType.LogRestart, "\"Log\"");
                await messages.UpdateMessageAsync(logRestart);

                queueInfo = CreateMessage(FahClientMessageType.QueueInfo, "[ { \"id\": \"01\", \"slot\": 0, \"percentdone\": \"9%\" } ]");
                // Act
                var result = await messages.UpdateMessageAsync(queueInfo);

                // Assert
                Assert.IsTrue(messages.LogIsRetrieved);
                Assert.IsFalse(result.SlotsUpdated);
                Assert.IsTrue(result.ExecuteRetrieval);
            }
        }
Example #27
0
        private void SetupTestDataFileCopies()
        {
            _artifacts = new ArtifactFolder();

            // sometimes the file is not finished
            // copying before we attempt to open
            // the copied file.  Halt the thread
            // for a bit to ensure the copy has
            // completed.

            _testDataFileCopy = _artifacts.GetRandomFilePath();
            File.Copy(TestDataFile, _testDataFileCopy, true);
            Thread.Sleep(100);

            _testData2FileCopy = _artifacts.GetRandomFilePath();
            File.Copy(TestData2File, _testData2FileCopy, true);
            Thread.Sleep(100);

            _testDataFileUpgradedCopy = _artifacts.GetRandomFilePath();
            File.Copy(TestDataFileUpgraded, _testDataFileUpgradedCopy, true);
            Thread.Sleep(100);

            _testScratchFile = _artifacts.GetRandomFilePath();
        }
        public async Task ApplicationUpdatePresenter_DownloadClicked_DownloadsSetsDialogResultOKAndCloses()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                string sourceFile = artifacts.GetRandomFilePath();
                string targetFile = artifacts.GetRandomFilePath();

                var model = CreateUpdateModel(sourceFile, ApplicationUpdateFileType.Executable);
                using (var presenter = new MockDialogApplicationUpdatePresenter(model))
                {
                    presenter.ShowDialog(null);
                    Assert.IsTrue(presenter.MockDialog.Shown);
                    // Act
                    var saveFile = new MockFileDialogPresenterReturnsFileName(_ => DialogResult.OK, targetFile);
                    await presenter.DownloadClick(saveFile);

                    // Assert
                    Assert.IsFalse(presenter.MockDialog.Shown);
                    Assert.AreEqual(DialogResult.OK, presenter.Dialog.DialogResult);
                    Assert.AreEqual(1, saveFile.Invocations.Count);
                }
            }
        }
        public void ApplicationUpdateService_GetApplicationUpdate_ReturnsObject()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                string path   = artifacts.GetRandomFilePath();
                var    update = new ApplicationUpdate {
                    Version = "1.2.3.4"
                };

                using (FileStream stream = File.OpenWrite(path))
                {
                    new ApplicationUpdateSerializer().Serialize(stream, update);
                }
                var uri = new Uri(path);

                var service = new ApplicationUpdateService(null);
                // Act
                var result = service.GetApplicationUpdate(uri);
                // Assert
                Assert.IsNotNull(result);
                Assert.AreEqual("1.2.3.4", update.Version);
            }
        }