Ejemplo n.º 1
0
        public void AskForUpdate_NewVersionYes_StartUpdate()
        {
            var dialogs    = Substitute.For <IDialogs>();
            var fileSystem = Substitute.For <IFileSystem>();
            var processApi = Substitute.For <IProcess>();
            var sut        = new ApplicationUpdate(dialogs, fileSystem, processApi);
            var releases   = GithubReleaseExtensionTests.CreateRelease("2.1");

            dialogs.ShowMessageBox(
                Arg.Any <string>(),
                Arg.Any <string>(),
                MessageBoxButton.YesNo, Arg.Any <MessageBoxImage>(),
                Arg.Any <MessageBoxResult>(), Arg.Any <MessageBoxOptions>())
            .Returns(MessageBoxResult.Yes);

            sut.AskForUpdate(releases, "2.0").Should().BeTrue();
            dialogs.DidNotReceive().ShowMessageBox(
                Arg.Any <string>(),
                Arg.Any <string>(),
                MessageBoxButton.OK, Arg.Any <MessageBoxImage>(),
                Arg.Any <MessageBoxResult>(), Arg.Any <MessageBoxOptions>());
            dialogs.Received(1).ShowMessageBox(
                Arg.Any <string>(),
                Arg.Any <string>(),
                MessageBoxButton.YesNo, Arg.Any <MessageBoxImage>(),
                Arg.Any <MessageBoxResult>(), Arg.Any <MessageBoxOptions>());
        }
Ejemplo n.º 2
0
        public void StartUpdateProcess_NewVersionYes_StartUpdate()
        {
            var dialogs    = Substitute.For <IDialogs>();
            var fileSystem = Substitute.For <IFileSystem>();
            var processApi = Substitute.For <IProcess>();

            processApi.Start(Arg.Any <ProcessStartInfo>())
            .Returns(Process.Start(new ProcessStartInfo("cmd.exe", "/c ping 127.0.0.1")));
            var sut = new ApplicationUpdate(dialogs, fileSystem, processApi)
            {
                WaitTimeMilliseconds = 0
            };
            var releases = GithubReleaseExtensionTests.CreateRelease("2.1");

            dialogs.ShowMessageBox(
                Arg.Any <string>(),
                Arg.Any <string>(),
                MessageBoxButton.YesNo, Arg.Any <MessageBoxImage>(),
                Arg.Any <MessageBoxResult>(), Arg.Any <MessageBoxOptions>())
            .Returns(MessageBoxResult.Yes);
            sut.AskForUpdate(releases, "2.0").Should().BeTrue();

            sut.StartUpdateProcess().Should().BeTrue();

            fileSystem.Received(1).WriteAllTextIntoFile(
                Arg.Is <string>(x => x.Contains(Path.GetTempPath())), Arg.Any <string>());
            processApi.Received(1).Start(Arg.Is <ProcessStartInfo>(i => i.FileName == "powershell"));
        }
Ejemplo n.º 3
0
        public void StartUpdateProcess_UpdateProcessFailed_UpdateAborted()
        {
            var dialogs    = Substitute.For <IDialogs>();
            var fileSystem = Substitute.For <IFileSystem>();
            var processApi = Substitute.For <IProcess>();

            processApi.Start(Arg.Any <ProcessStartInfo>())
            .Returns(Process.Start(new ProcessStartInfo("cmd.exe", "/c exit 5")));
            var sut = new ApplicationUpdate(dialogs, fileSystem, processApi)
            {
                WaitTimeMilliseconds = 1000
            };
            var releases = GithubReleaseExtensionTests.CreateRelease("2.1");

            sut.AskForUpdate(releases, "2.0");

            sut.StartUpdateProcess().Should().BeFalse();
            dialogs.Received(1).ShowMessageBox(
                Arg.Is <string>(s => s.Contains("code 5.")), Resources.Header_CheckForUpdates, icon: MessageBoxImage.Error);
        }