public void Fail_Deploy_DeploymentFileNotFoundException() { // Setup var parameters = GenerateRandomParameters(); _projectMock.SetupAllProperties(); _projectMock.Setup(p => p.Parameters).Returns(new ReadOnlyDictionary <string, IParameter>(parameters)); _deployArgumentsMock.Setup(d => d.Catalog).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.Folder).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.ProjectName).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.ProjectPassword).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.EraseSensitiveInfo).Returns(Fakes.RandomBool()); _deployArgumentsMock.Setup(d => d.ServerInstance).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.WorkingFolder).Returns(_workingFolder); var deployer = new Deployer.Deployer(_loggerMock.Object, _projectMock.Object, _catalogToolsMock.Object); // Execute var exception = Record.Exception(() => deployer.Deploy(_deployArgumentsMock.Object)); // Assert Assert.NotNull(exception); Assert.IsType <DeploymentFileNotFoundException>(exception); }
public void Fail_Deploy() { // Setup var parameters = GenerateRandomParameters(); _projectMock.SetupAllProperties(); _projectMock.Setup(p => p.Parameters).Returns(new ReadOnlyDictionary <string, IParameter>(parameters)); _deployArgumentsMock.Setup(d => d.Catalog).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.DeploymentFilePath).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.Folder).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.ProjectName).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.ProjectPassword).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.EraseSensitiveInfo).Returns(Fakes.RandomBool()); _deployArgumentsMock.Setup(d => d.ServerInstance).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.WorkingFolder).Returns(Fakes.RandomString()); _catalogToolsMock.Setup(c => c.DeployProject(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <IDictionary <string, SensitiveParameter> >(), It.IsAny <MemoryStream>())) .Throws(new Exception("TEST")); _loggerMock.Setup(l => l.LogMessage(It.IsAny <string>())).Verifiable(); // Execute var deployer = new Deployer.Deployer(_loggerMock.Object, _projectMock.Object, _catalogToolsMock.Object); var exception = Record.Exception(() => deployer.Deploy(_deployArgumentsMock.Object)); // Assert Assert.NotNull(exception); Assert.IsType <Exception>(exception); Assert.Equal("TEST", exception.Message); }
public void Pass_Deploy_ImplicitDeploymentFilePath() { // Setup var parameters = GenerateRandomParameters(); _projectMock.SetupAllProperties(); _projectMock.Setup(p => p.Parameters).Returns(new ReadOnlyDictionary <string, IParameter>(parameters)); _deployArgumentsMock.Setup(d => d.Catalog).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.Folder).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.ProjectName).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.ProjectPassword).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.EraseSensitiveInfo).Returns(Fakes.RandomBool()); _deployArgumentsMock.Setup(d => d.ServerInstance).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.WorkingFolder).Returns(_workingFolder); var realDeploymentFilePath = Path.Combine(_workingFolder, $"{Fakes.RandomString()}.ispac"); File.Create(realDeploymentFilePath).Close(); string receivedDeploymentFilePath = null; _projectMock.Setup(p => p.LoadFromIspac(It.IsAny <string>(), It.IsAny <string>())) .Callback((string deploymentFilePath, string password) => receivedDeploymentFilePath = deploymentFilePath); var deployer = new Deployer.Deployer(_loggerMock.Object, _projectMock.Object, _catalogToolsMock.Object); // Execute deployer.Deploy(_deployArgumentsMock.Object); // Assert Assert.Equal(realDeploymentFilePath, receivedDeploymentFilePath); }
public void Pass_Deploy() { // Setup var parameters = GenerateRandomParameters(); _projectMock.SetupAllProperties(); _projectMock.Setup(p => p.Parameters).Returns(new ReadOnlyDictionary <string, IParameter>(parameters)); _deployArgumentsMock.Setup(d => d.Catalog).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.DeploymentFilePath).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.Folder).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.ProjectName).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.ProjectPassword).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.EraseSensitiveInfo).Returns(Fakes.RandomBool()); _deployArgumentsMock.Setup(d => d.ServerInstance).Returns(Fakes.RandomString()); _deployArgumentsMock.Setup(d => d.WorkingFolder).Returns(Fakes.RandomString()); string passedCatalog = null; string passedServerInstance = null; string passedFolder = null; string passedProjectName = null; bool? passedEraseSensitiveInfo = null; SensitiveParameter[] passedParameters = null; _catalogToolsMock.Setup(c => c.DeployProject(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <IDictionary <string, SensitiveParameter> >(), It.IsAny <MemoryStream>())) .Callback( (string connectionString, string folderName, string projectName, bool eraseSensitiveInfo, IDictionary <string, SensitiveParameter> parametersToDeploy, MemoryStream projectStream) => { var sb = new SqlConnectionStringBuilder(connectionString); passedCatalog = sb.InitialCatalog; passedServerInstance = sb.DataSource; passedFolder = folderName; passedProjectName = projectName; passedEraseSensitiveInfo = eraseSensitiveInfo; passedParameters = parametersToDeploy.Values.ToArray(); }) .Verifiable(); _loggerMock.Setup(l => l.LogMessage(It.IsAny <string>())).Verifiable(); var deployer = new Deployer.Deployer(_loggerMock.Object, _projectMock.Object, _catalogToolsMock.Object); // Execute deployer.Deploy(_deployArgumentsMock.Object); // Assert _loggerMock.Verify(m => m.LogMessage(It.IsAny <string>())); Assert.Equal(_deployArgumentsMock.Object.Catalog, passedCatalog); Assert.Equal(_deployArgumentsMock.Object.ServerInstance, passedServerInstance); Assert.Equal(_deployArgumentsMock.Object.Folder, passedFolder); Assert.Equal(_deployArgumentsMock.Object.ProjectName, passedProjectName); Assert.NotNull(passedEraseSensitiveInfo); Assert.Equal(_deployArgumentsMock.Object.EraseSensitiveInfo, passedEraseSensitiveInfo.Value); foreach (var parameter in parameters.Where(p => p.Value.Sensitive)) { Assert.True(passedParameters.Any(pp => pp.Name == parameter.Key && pp.Value == parameter.Value.Value && pp.DataType == parameter.Value.ParameterDataType)); } }