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)); }
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])); }
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]); } }); }
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); }
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)); } }); }