Inheritance: ISelfUpdateService
Ejemplo n.º 1
0
        public void Constructor_AllParametersAreSet_ObjectIsInstantiated()
        {
            // Arrange
            var userInterface = new Mock<IUserInterface>();
            var applicationInformation = new ApplicationInformation();
            var packageRepositoryBrowser = new Mock<IPackageRepositoryBrowser>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            // Act
            var selfUpdateService = new SelfUpdateService(
                userInterface.Object, applicationInformation, packageRepositoryBrowser.Object, filesystemAccessor.Object);

            // Assert
            Assert.IsNotNull(selfUpdateService);
        }
Ejemplo n.º 2
0
        public void SelfUpdate_ExePathIsInvalid_ArgumentExceptionIsThrown(string exePath)
        {
            // Arrange
            var version = new Version(1, 0, 0);

            var userInterface = new Mock<IUserInterface>();
            var applicationInformation = new ApplicationInformation();
            var packageRepositoryBrowser = new Mock<IPackageRepositoryBrowser>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            var selfUpdateService = new SelfUpdateService(
                userInterface.Object, applicationInformation, packageRepositoryBrowser.Object, filesystemAccessor.Object);

            // Act
            selfUpdateService.SelfUpdate(exePath, version);
        }
Ejemplo n.º 3
0
        public void SelfUpdate_VersionIsNull_ArgumentNullExceptionIsThrown()
        {
            // Arrange
            string exePath = "NuDeploy.exe";
            Version version = null;

            var userInterface = new Mock<IUserInterface>();
            var applicationInformation = new ApplicationInformation();
            var packageRepositoryBrowser = new Mock<IPackageRepositoryBrowser>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            var selfUpdateService = new SelfUpdateService(
                userInterface.Object, applicationInformation, packageRepositoryBrowser.Object, filesystemAccessor.Object);

            // Act
            selfUpdateService.SelfUpdate(exePath, version);
        }
Ejemplo n.º 4
0
        public void SelfUpdate_PackageIsNotFound_ResultIsFalse()
        {
            // Arrange
            string exePath = "NuDeploy.exe";
            var version = new Version(1, 0, 0);

            var userInterface = new Mock<IUserInterface>();
            var applicationInformation = new ApplicationInformation();
            var packageRepositoryBrowser = new Mock<IPackageRepositoryBrowser>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            var selfUpdateService = new SelfUpdateService(
                userInterface.Object, applicationInformation, packageRepositoryBrowser.Object, filesystemAccessor.Object);

            // Act
            bool result = selfUpdateService.SelfUpdate(exePath, version);

            // Assert
            Assert.IsFalse(result);
        }
Ejemplo n.º 5
0
        public void SelfUpdate_PackageIsFound_VersionIsOlderThanCurrentVersion_ResultIsFalse()
        {
            // Arrange
            string exePath = "NuDeploy.exe";
            var version = new Version(2, 0, 0, 0);

            var userInterface = new Mock<IUserInterface>();
            var applicationInformation = new ApplicationInformation();
            var packageRepositoryBrowser = new Mock<IPackageRepositoryBrowser>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            var packageMock = new Mock<IPackage>();
            packageMock.Setup(p => p.Version).Returns(new SemanticVersion(1, 0, 0, 0));

            packageRepositoryBrowser.Setup(p => p.FindPackage(It.IsAny<string>())).Returns(packageMock.Object);

            var selfUpdateService = new SelfUpdateService(
                userInterface.Object, applicationInformation, packageRepositoryBrowser.Object, filesystemAccessor.Object);

            // Act
            bool result = selfUpdateService.SelfUpdate(exePath, version);

            // Assert
            Assert.IsFalse(result);
        }
Ejemplo n.º 6
0
        public void SelfUpdate_PackageIsFound_VersionIsNewerThanTheCurrentVersion_PackageContainsNoExeWhichNameMatchesTheApplication_ResultIsFalse()
        {
            // Arrange
            string exePath = "NuDeploy.exe";
            var version = new Version(1, 0, 0, 0);

            var userInterface = new Mock<IUserInterface>();
            var applicationInformation = new ApplicationInformation { NameOfExecutable = exePath };
            var packageRepositoryBrowser = new Mock<IPackageRepositoryBrowser>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            var packageFileMock = new Mock<IPackageFile>();
            packageFileMock.Setup(f => f.Path).Returns("tools\\" + "SomeOtherApplicationName.exe");

            var packageMock = new Mock<IPackage>();
            packageMock.Setup(p => p.Version).Returns(new SemanticVersion(2, 0, 0, 0));
            packageMock.Setup(p => p.GetFiles()).Returns(new List<IPackageFile> { packageFileMock.Object });

            packageRepositoryBrowser.Setup(p => p.FindPackage(It.IsAny<string>())).Returns(packageMock.Object);

            var selfUpdateService = new SelfUpdateService(
                userInterface.Object, applicationInformation, packageRepositoryBrowser.Object, filesystemAccessor.Object);

            // Act
            bool result = selfUpdateService.SelfUpdate(exePath, version);

            // Assert
            Assert.IsFalse(result);
        }
Ejemplo n.º 7
0
        public void SelfUpdate_PackageIsFound_VersionIsNewerThanTheCurrentVersion_PackageContainsExeWhichNameMatchesTheApplication_UpdateTargetStreamIsNull_ResultIsFalse()
        {
            // Arrange
            string exePath = "NuDeploy.exe";
            var version = new Version(1, 0, 0, 0);

            var userInterface = new Mock<IUserInterface>();
            var applicationInformation = new ApplicationInformation { NameOfExecutable = exePath };
            var packageRepositoryBrowser = new Mock<IPackageRepositoryBrowser>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            var packageContent = "Content of the update package";
            var packageContentStream = TestUtilities.GetStreamReaderForText(packageContent).BaseStream;

            var packageFileMock = new Mock<IPackageFile>();
            packageFileMock.Setup(f => f.Path).Returns("tools\\" + exePath);
            packageFileMock.Setup(f => f.GetStream()).Returns(packageContentStream);

            var packageMock = new Mock<IPackage>();
            packageMock.Setup(p => p.Version).Returns(new SemanticVersion(2, 0, 0, 0));
            packageMock.Setup(p => p.GetFiles()).Returns(new List<IPackageFile> { packageFileMock.Object });

            packageRepositoryBrowser.Setup(p => p.FindPackage(It.IsAny<string>())).Returns(packageMock.Object);

            Stream targetStream = null;
            filesystemAccessor.Setup(f => f.GetWriteStream(exePath)).Returns(targetStream);

            var selfUpdateService = new SelfUpdateService(
                userInterface.Object, applicationInformation, packageRepositoryBrowser.Object, filesystemAccessor.Object);

            // Act
            bool result = selfUpdateService.SelfUpdate(exePath, version);

            // Assert
            Assert.IsFalse(result);
        }
Ejemplo n.º 8
0
        public void SelfUpdate_PackageIsFound_VersionIsNewerThanTheCurrentVersion_PackageContainsExeWhichNameMatchesTheApplication_PackageContentIsWrittenToExecutable()
        {
            // Arrange
            string exePath = "NuDeploy.exe";
            var version = new Version(1, 0, 0, 0);

            var userInterface = new Mock<IUserInterface>();
            var applicationInformation = new ApplicationInformation { NameOfExecutable = exePath };
            var packageRepositoryBrowser = new Mock<IPackageRepositoryBrowser>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            var packageContent = "Content of the update package";
            var packageContentStream = TestUtilities.GetStreamReaderForText(packageContent).BaseStream;

            var packageFileMock = new Mock<IPackageFile>();
            packageFileMock.Setup(f => f.Path).Returns("tools\\" + exePath);
            packageFileMock.Setup(f => f.GetStream()).Returns(packageContentStream);

            var packageMock = new Mock<IPackage>();
            packageMock.Setup(p => p.Version).Returns(new SemanticVersion(2, 0, 0, 0));
            packageMock.Setup(p => p.GetFiles()).Returns(new List<IPackageFile> { packageFileMock.Object });

            var targetStream = new MemoryStream();
            filesystemAccessor.Setup(f => f.GetWriteStream(exePath)).Returns(targetStream);

            packageRepositoryBrowser.Setup(p => p.FindPackage(It.IsAny<string>())).Returns(packageMock.Object);

            var selfUpdateService = new SelfUpdateService(
                userInterface.Object, applicationInformation, packageRepositoryBrowser.Object, filesystemAccessor.Object);

            // Act
            bool result = selfUpdateService.SelfUpdate(exePath, version);

            // Assert
            var bytes = targetStream.ReadAllBytes();
            string newContentOfOldFile = Encoding.UTF8.GetString(bytes);
            filesystemAccessor.Verify(f => f.GetWriteStream(exePath), Times.Once());
            Assert.AreEqual(packageContent, newContentOfOldFile);
            Assert.IsTrue(result);
        }
Ejemplo n.º 9
0
        public void SelfUpdate_PackageIsFound_VersionIsNewerThanTheCurrentVersion_PackageContainsExeWhichNameMatchesTheApplication_CurrentExeIsMovedToNewLocation()
        {
            // Arrange
            string exePath = "NuDeploy.exe";
            var version = new Version(1, 0, 0, 0);

            var userInterface = new Mock<IUserInterface>();
            var applicationInformation = new ApplicationInformation { NameOfExecutable = exePath };
            var packageRepositoryBrowser = new Mock<IPackageRepositoryBrowser>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            var packageFileMock = new Mock<IPackageFile>();
            packageFileMock.Setup(f => f.Path).Returns("tools\\" + exePath);

            var packageMock = new Mock<IPackage>();
            packageMock.Setup(p => p.Version).Returns(new SemanticVersion(2, 0, 0, 0));
            packageMock.Setup(p => p.GetFiles()).Returns(new List<IPackageFile> { packageFileMock.Object });

            packageRepositoryBrowser.Setup(p => p.FindPackage(It.IsAny<string>())).Returns(packageMock.Object);

            var selfUpdateService = new SelfUpdateService(
                userInterface.Object, applicationInformation, packageRepositoryBrowser.Object, filesystemAccessor.Object);

            // Act
            selfUpdateService.SelfUpdate(exePath, version);

            // Assert
            filesystemAccessor.Verify(
                f => f.MoveFile(exePath, It.Is<string>(s => s.Equals(exePath, StringComparison.OrdinalIgnoreCase) == false)), Times.Once());
        }