Ejemplo n.º 1
0
        public void CallDeployWithoutFilesWillFail()
        {
            var dsFactory = DefaultMocks.GetServiceFactory();
            var cFactory = DefaultMocks.GetConfFactory();

            Assert.Throws<InvalidOperationException>(() => {
                using (var service = new DeployService(dsFactory.Object, cFactory.Object)) {
                    service.OpenSession(_surveyName);
                    service.Deploy(GetDeployContext(), new byte[0]);
                }
            });
        }
Ejemplo n.º 2
0
        public void IfDeployThrowsExShouldBeHandled(DeployMode mode)
        {
            var cFactory = DefaultMocks.GetConfFactory();

            var validator = new Mock<IValidator>();
            validator.Setup(v => v.IsValidForInstall()).Returns(true);
            validator.Setup(v => v.IsValidForUpdate()).Returns(true);

            var correctDeployers = DefaultMocks.GetMockedDeployers(3).ToList();
            var deployersWithEx = correctDeployers.ToList();
            var deployerWithEx = new Mock<IDeployer>();
            deployerWithEx.Setup(d => d.Name).Returns(string.Format("deployer-{0}", 4));
            deployerWithEx.Setup(d => d.Install()).Throws(new DeployException("deploy ex install"));
            deployerWithEx.Setup(d => d.Update()).Throws(new DeployException("deploy ex update"));
            deployersWithEx.Add(deployerWithEx);

            var settingsMock = new Mock<IConf>();
            settingsMock.Setup(s => s.SurveyPath).Returns(new SurveyPaths(_surveyPath, null));
            settingsMock.Setup(s => s.Survey).Returns(new Survey(null, null, mode));
            settingsMock.Setup(s => s.PackageManager).Returns(new PackageManagerStub());

            var dsFactory = DefaultMocks.GetServiceFactory(mode);
            dsFactory.Setup(f => f.CreateDeployExHandlerObj(It.IsAny<IDeployEvents>(), It.IsAny<IConf>(), It.IsAny<IServiceLogger>(), It.IsAny<ISession>()))
                .Returns(new DeployExceptionHandlerStub());
            dsFactory.Setup(f => f.CreateValidatorsList(It.IsAny<IConf>())).Returns(new List<IValidator> { validator.Object });
            dsFactory.Setup(f => f.CreateDeployersList(It.IsAny<IConf>())).Returns(deployersWithEx.Select(d => d.Object));

            using (var service = new DeployService(dsFactory.Object, cFactory.Object))
                ConsumeService(service, mode);

            if (mode == DeployMode.Install)
                validator.Verify(v => v.IsValidForInstall(), Times.Once());
            else
                validator.Verify(v => v.IsValidForUpdate(), Times.Once());

            foreach (var deployer in correctDeployers)
                if (mode == DeployMode.Install) {
                    deployer.Verify(d => d.Install(), Times.Once());
                    deployer.Verify(d => d.InstallRollback(), Times.Once());
                } else {
                    deployer.Verify(d => d.Update(), Times.Once());
                    deployer.Verify(d => d.UpdateRollback(), Times.Once());
                }
        }
Ejemplo n.º 3
0
        public void ServiceShouldReleaseLockedFolders()
        {
            var dsFactory = DefaultMocks.GetServiceFactory();

            using (var service1 = new DeployService(dsFactory.Object, null)) {
                using (var service2 = new DeployService(dsFactory.Object, null)) {
                    service2.OpenSession(_surveyName);
                    Assert.False(service1.OpenSession(_surveyName));
                }

                Assert.True(service1.OpenSession(_surveyName));
            }
        }
Ejemplo n.º 4
0
        public void ServiceShouldDemandOpenSessionMethod()
        {
            var dsFacory = DefaultMocks.GetServiceFactory();

            var service = new DeployService(dsFacory.Object, null);

            Assert.Throws<AuthenticationException>(() => service.Deploy(GetDeployContext(DeployMode.Install), new byte[10]));
        }
Ejemplo n.º 5
0
        public void ServiceShouldCallAllValidatorsAndDeployers(DeployMode mode)
        {
            var cFactory = DefaultMocks.GetConfFactory();
            var validators = DefaultMocks.GetMockedValidators(3).ToList();
            var deployers = DefaultMocks.GetMockedDeployers(3).ToList();
            var dsFactory = DefaultMocks.GetServiceFactory(mode);
            dsFactory.Setup(f => f.CreateValidatorsList(It.IsAny<IConf>())).Returns(validators.Select(v => v.Object));
            dsFactory.Setup(f => f.CreateDeployersList(It.IsAny<IConf>())).Returns(deployers.Select(v => v.Object));

            using (var service = new DeployService(dsFactory.Object, cFactory.Object))
                ConsumeService(service, mode);

            foreach (var validator in validators)
                if (mode == DeployMode.Install)
                    validator.Verify(v => v.IsValidForInstall(), Times.Once());
                else
                    validator.Verify(v => v.IsValidForUpdate(), Times.Once());
            foreach (var deployer in deployers)
                if (mode == DeployMode.Install)
                    deployer.Verify(d => d.Install(), Times.Once());
                else
                    deployer.Verify(d => d.Update(), Times.Once());
        }
Ejemplo n.º 6
0
        public void IfValidationFailedHadleExAndDontCallDeployers(DeployMode mode)
        {
            var cFactory = DefaultMocks.GetConfFactory();

            var validator = new Mock<IValidator>();
            validator.Setup(v => v.IsValidForInstall()).Returns(false);
            validator.Setup(v => v.IsValidForUpdate()).Returns(false);

            var deployer = new Mock<IDeployer>();
            deployer.Setup(d => d.Install());
            deployer.Setup(d => d.Update());

            var exceptionHandler = new Mock<IDeployExceptionHandler>();
            exceptionHandler.Setup(e => e.HandleValidation(It.IsAny<ValidationException>(), It.IsAny<IDeployEvents>()));

            var dsFactory = DefaultMocks.GetServiceFactory(mode);
            dsFactory.Setup(f => f.CreateDeployExHandlerObj(It.IsAny<IDeployEvents>(), It.IsAny<IConf>(), It.IsAny<IServiceLogger>(), It.IsAny<ISession>()))
                .Returns(exceptionHandler.Object);
            dsFactory.Setup(f => f.CreateValidatorsList(It.IsAny<IConf>())).Returns(new List<IValidator> {validator.Object});
            dsFactory.Setup(f => f.CreateDeployersList(It.IsAny<IConf>())).Returns(new List<IDeployer> {deployer.Object});

            using (var service = new DeployService(dsFactory.Object, cFactory.Object))
                ConsumeService(service, mode);

            if (mode == DeployMode.Install)
                validator.Verify(v => v.IsValidForInstall(), Times.Once());
            else
                validator.Verify(v => v.IsValidForUpdate(), Times.Once());

            deployer.Verify(d => d.Install(), Times.Never());
            deployer.Verify(d => d.Update(), Times.Never());
            exceptionHandler.Verify(e => e.HandleValidation(It.IsAny<ValidationException>(), It.IsAny<IDeployEvents>()), Times.Once());
        }
Ejemplo n.º 7
0
        public void IfFilesTransferWasCorruptedDeployThrows()
        {
            var dsFactory = DefaultMocks.GetServiceFactory();
            var cFactory = DefaultMocks.GetConfFactory();

            Assert.Throws<ArgumentException>(() => {
                using (var service = new DeployService(dsFactory.Object, cFactory.Object)) {
                    service.OpenSession(_surveyName);

                    foreach (var chunk in _files.Chunks)
                        service.SendFilesChunk(chunk);

                    var spoiledFiles = new byte[_files.Bytes.Length];
                    Array.Copy(_files.Bytes, spoiledFiles, _files.Bytes.Length);
                    spoiledFiles[100] = 0;

                    service.Deploy(GetDeployContext(), MD5.Create().ComputeHash(spoiledFiles));
                }
            });
        }