コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
 public void ApplicationUpdatePresenter_CancelClicked_SetsDialogResultCancelAndCloses()
 {
     // Arrange
     using (var presenter = new MockDialogApplicationUpdatePresenter(new ApplicationUpdateModel(new ApplicationUpdate())))
     {
         presenter.ShowDialog(null);
         Assert.IsTrue(presenter.MockDialog.Shown);
         // Act
         presenter.CancelClick();
         // Assert
         Assert.IsFalse(presenter.MockDialog.Shown);
         Assert.AreEqual(DialogResult.Cancel, presenter.Dialog.DialogResult);
     }
 }
コード例 #3
0
        public async Task ApplicationUpdatePresenter_DownloadClicked_DoesNothingWhenThereIsNoSelectedUpdateFile()
        {
            // Arrange
            var model = CreateUpdateModel("foo", ApplicationUpdateFileType.Executable);

            using (var presenter = new MockDialogApplicationUpdatePresenter(model))
            {
                presenter.ShowDialog(null);
                model.SelectedUpdateFile = null;
                Assert.IsTrue(presenter.MockDialog.Shown);
                // Act
                var saveFile = new MockFileDialogPresenterReturnsFileName(null, "bar");
                await presenter.DownloadClick(saveFile);

                // Assert
                Assert.IsTrue(presenter.MockDialog.Shown);
                Assert.AreEqual(0, saveFile.Invocations.Count);
            }
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        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);
                }
            }
        }