Beispiel #1
0
        public void CreateDeployFilesAsync_ArgumentNullException_PreviousVersionDacpacPath()
        {
            // Arrange
            var        xfsMock = Mock.Of <IXmlFormatService>();
            IDacAccess da      = new DacAccess(xfsMock);

            // Act & Assert
            // ReSharper disable AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(() => da.CreateDeployFilesAsync(null, null, null, false, false));
            // ReSharper restore AssignNullToNotNullAttribute
        }
Beispiel #2
0
        public void CreateDeployFilesAsync_InvalidOperationException_CreateNoOutput()
        {
            // Arrange
            var        xfsMock = Mock.Of <IXmlFormatService>();
            IDacAccess da      = new DacAccess(xfsMock);
            var        previousVersionDacpacPath = "path1";
            var        newVersionDacpacPath      = "path2";
            var        publishProfilePath        = "path3";

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => da.CreateDeployFilesAsync(previousVersionDacpacPath, newVersionDacpacPath, publishProfilePath, false, false));
        }
Beispiel #3
0
        public async Task CreateDeployFilesAsync_CorrectCreation_WithPreAndPostDeploymentScripts_Async()
        {
            // Arrange
            var xfsMock = new Mock <IXmlFormatService>();

            xfsMock.Setup(m => m.FormatDeployReport(It.IsNotNull <string>())).Returns((string s) => s);
            var        tempPreviousVersionDacpacPath = WriteEmbeddedResourceToTemporaryFile("TestDatabase_Empty.dacpac");
            var        tempNewVersionDacpacPath      = WriteEmbeddedResourceToTemporaryFile("TestDatabase_WithPreAndPostDeployment.dacpac");
            var        tempPublishProfilePath        = WriteEmbeddedResourceToTemporaryFile("TestDatabase.publish.xml");
            IDacAccess da = new DacAccess(xfsMock.Object);

            // Act
            var result = await da.CreateDeployFilesAsync(tempPreviousVersionDacpacPath, tempNewVersionDacpacPath, tempPublishProfilePath, true, true);

            // Assert
            Assert.IsNotNull(result.DeployScriptContent);
            Assert.IsNotNull(result.DeployReportContent);
            Assert.AreEqual("-- Pre-deployment script content goes here\r\nGO\r\n", result.PreDeploymentScript);
            Assert.AreEqual("-- Post-deployment script content goes here\r\nGO\r\n", result.PostDeploymentScript);
            Assert.IsNull(result.Errors);
            xfsMock.Verify(m => m.FormatDeployReport(It.IsNotNull <string>()), Times.Once);
            // Verify script
            var productionIndex = result.DeployScriptContent.IndexOf("PRODUCTION", StringComparison.InvariantCulture);

            Assert.IsTrue(productionIndex > 0);
            var onErrorIndex = result.DeployScriptContent.IndexOf(":on error exit", StringComparison.InvariantCulture);

            Assert.IsTrue(onErrorIndex > productionIndex);
            var changeDatabaseIndex = result.DeployScriptContent.IndexOf("USE [$(DatabaseName)]", StringComparison.InvariantCulture);

            Assert.IsTrue(changeDatabaseIndex > onErrorIndex);
            var preDeploymentIndex = result.DeployScriptContent.IndexOf(result.PreDeploymentScript, StringComparison.InvariantCulture);

            Assert.IsTrue(preDeploymentIndex > changeDatabaseIndex);
            var createAuthorPrintIndex = result.DeployScriptContent.IndexOf("[dbo].[Author]...';", StringComparison.InvariantCulture);

            Assert.IsTrue(createAuthorPrintIndex > preDeploymentIndex);
            var createAuthorTableIndex = result.DeployScriptContent.IndexOf("CREATE TABLE [dbo].[Author]", StringComparison.InvariantCulture);

            Assert.IsTrue(createAuthorTableIndex > createAuthorPrintIndex);
            var postDeploymentIndex = result.DeployScriptContent.IndexOf(result.PostDeploymentScript, StringComparison.InvariantCulture);

            Assert.IsTrue(postDeploymentIndex > createAuthorTableIndex);
            // Verify report
            Assert.AreEqual(@"<?xml version=""1.0"" encoding=""utf-8""?><DeploymentReport xmlns=""http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02""><Alerts />" +
                            @"<Operations><Operation Name=""Create""><Item Value=""[dbo].[Author]"" Type=""SqlTable"" /><Item Value=""[dbo].[DF_Birthday_Today]"" Type=""SqlDefaultConstraint"" /></Operation>" +
                            @"</Operations></DeploymentReport>",
                            result.DeployReportContent);
        }