コード例 #1
0
        void Run()
        {
            var eventPublisher = new EventPublisher();
            var connection     = new Mock <IEnvironmentConnection>();

            connection.Setup(e => e.ServerEvents).Returns(eventPublisher);
            connection.Setup(e => e.ExecuteCommand(It.IsAny <StringBuilder>(), It.IsAny <Guid>())).Returns(new StringBuilder());

            var envMock = new Mock <IServer>();

            envMock.Setup(e => e.Connection).Returns(connection.Object);
            envMock.Setup(e => e.ResourceRepository.DeployResource(It.IsAny <IResourceModel>(), It.IsAny <string>())).Verifiable();
            envMock.Setup(e => e.ResourceRepository.SaveTests(It.IsAny <IResourceModel>(), It.IsAny <List <IServiceTestModelTO> >())).Verifiable();
            envMock.Setup(e => e.IsConnected).Returns(true);

            var sourceMock = new Mock <IServer>();

            sourceMock.Setup(e => e.Connection).Returns(connection.Object);
            sourceMock.Setup(e => e.ResourceRepository.LoadResourceTestsForDeploy(It.IsAny <Guid>())).Returns(new List <IServiceTestModelTO>()).Verifiable();
            sourceMock.Setup(e => e.IsConnected).Returns(true);

            var dtoMock = new Mock <IDeployDto>();

            dtoMock.Setup(d => d.ResourceModels).Returns(CreateModels(envMock.Object));

            var ds = new DeployService();

            ds.Deploy(dtoMock.Object, sourceMock.Object, envMock.Object);

            envMock.Verify(e => e.ResourceRepository.DeployResource(It.IsAny <IResourceModel>(), It.IsAny <string>()), Times.Exactly(_numModels));
        }
コード例 #2
0
ファイル: DeployServiceTests.cs プロジェクト: wurdum/deployer
        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]));
        }
コード例 #3
0
ファイル: DeployServiceTests.cs プロジェクト: wurdum/deployer
        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]);
                }
            });
        }
コード例 #4
0
        public void DeployService_GivenTrue_ShouldDeployResourcesAndTestsAndTriggers()
        {
            //---------------Set up test pack-------------------
            var eventPublisher = new EventPublisher();
            var connection     = new Mock <IEnvironmentConnection>();

            connection.Setup(e => e.ServerEvents).Returns(eventPublisher);
            connection.Setup(e => e.ExecuteCommand(It.IsAny <StringBuilder>(), It.IsAny <Guid>())).Returns(new StringBuilder());

            var envMock = new Mock <IServer>();

            envMock.Setup(e => e.Connection).Returns(connection.Object);
            envMock.Setup(e => e.ResourceRepository.DeployResource(It.IsAny <IResourceModel>(), It.IsAny <string>())).Verifiable();
            envMock.Setup(e => e.ResourceRepository.SaveTests(It.IsAny <IResourceModel>(), It.IsAny <List <IServiceTestModelTO> >())).Verifiable();
            envMock.Setup(e => e.ResourceRepository.SaveQueue(It.IsAny <ITriggerQueue>())).Verifiable();
            envMock.Setup(e => e.IsConnected).Returns(true);

            var sourceMock = new Mock <IServer>();

            sourceMock.Setup(e => e.Connection).Returns(connection.Object);
            sourceMock.Setup(e => e.ResourceRepository.LoadResourceTestsForDeploy(It.IsAny <Guid>())).Returns(new List <IServiceTestModelTO>()).Verifiable();
            var triggerQueues = new List <ITriggerQueue> {
                new TriggerQueue {
                    QueueName = "Queue 1"
                }
            };

            sourceMock.Setup(e => e.ResourceRepository.LoadResourceTriggersForDeploy(It.IsAny <Guid>())).Returns(triggerQueues).Verifiable();
            sourceMock.Setup(e => e.IsConnected).Returns(true);
            var dtoMock = new Mock <IDeployDto>();

            dtoMock.Setup(d => d.ResourceModels).Returns(CreateModels(envMock.Object));
            dtoMock.Setup(d => d.DeployTests).Returns(true);
            dtoMock.Setup(d => d.DeployTriggers).Returns(true);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var ds = new DeployService();

            ds.Deploy(dtoMock.Object, sourceMock.Object, envMock.Object);
            //---------------Test Result -----------------------
            sourceMock.Verify(e => e.ResourceRepository.LoadResourceTestsForDeploy(It.IsAny <Guid>()), Times.AtLeastOnce);
            envMock.Verify(e => e.ResourceRepository.SaveTests(It.IsAny <IResourceModel>(), It.IsAny <List <IServiceTestModelTO> >()), Times.AtLeastOnce);
            envMock.Verify(e => e.ResourceRepository.DeployResource(It.IsAny <IResourceModel>(), It.IsAny <string>()), Times.AtLeastOnce);
            sourceMock.Verify(e => e.ResourceRepository.LoadResourceTriggersForDeploy(It.IsAny <Guid>()), Times.AtLeastOnce);
            envMock.Verify(e => e.ResourceRepository.SaveQueue(It.IsAny <ITriggerQueue>()), Times.AtLeastOnce);
        }
コード例 #5
0
ファイル: DeployServiceTests.cs プロジェクト: wurdum/deployer
        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));
                }
            });
        }