public void ThatExecuteSetupsCorrectly()
        {
            MockEnvironmentProvider mockEnvironmentProvider = new MockEnvironmentProvider();

            mockEnvironmentProvider.SetCurrentDirectory(@"c:\DbDeploy");
            EnvironmentProvider.Current = mockEnvironmentProvider;

            try
            {
                IConfigurationService configurationService = new ConfigurationService();
                Container.RegisterInstance(configurationService);

                Mock <IDeploymentService> deploymentServiceMock = new Mock <IDeploymentService>(MockBehavior.Strict);
                deploymentServiceMock.Setup(d => d.BuildDeploymentScript()).Verifiable();
                Container.RegisterInstance(deploymentServiceMock.Object);

                DbDeploy deploy = new DbDeploy();
                deploy.ConnectionString  = "Connection String";
                deploy.DatabaseType      = "mssql";
                deploy.LastChangeToApply = 500;
                deploy.OutputFile        = "Output File";
                deploy.Recursive         = true;
                deploy.RootDirectory     = "Root Directory";
                deploy.SearchPattern     = "*.sql";
                deploy.UndoFile          = "Undo File";

                deploy.Execute();

                Approvals.Verify(configurationService);

                deploy.DatabaseType = "ora";
                deploy.Execute();

                Assert.AreEqual(configurationService.DatabaseManagementSystem, DatabaseTypesEnum.Oracle);

                deploy.DatabaseType = "mysql";
                deploy.Execute();

                Assert.AreEqual(configurationService.DatabaseManagementSystem, DatabaseTypesEnum.MySql);

                deploy.DatabaseType = "BadDBType";
                bool expectedExceptionFound = false;
                try
                {
                    deploy.Execute();
                }
                catch (ArgumentException)
                {
                    expectedExceptionFound = true;
                }

                Assert.IsTrue(expectedExceptionFound, "Expected to receive an argument exception for a bad db type, but did not.");

                deploymentServiceMock.Verify(d => d.BuildDeploymentScript(), Times.Exactly(3));
            }
            finally
            {
                EnvironmentProvider.ResetToDefault();
            }
        }
Exemple #2
0
        public void ThatExecuteSetupsCorrectly()
        {
            IConfigurationService configurationService = new ConfigurationService();
            var deploymentServiceMock = new Mock <IDeploymentService>(MockBehavior.Strict);

            deploymentServiceMock.Setup(d => d.BuildDeploymentScript()).Verifiable();

            Container.RegisterInstance(configurationService);
            Container.RegisterInstance(deploymentServiceMock.Object);

            DbDeploy deploy = new DbDeploy();

            deploy.ConnectionString  = "Connection String";
            deploy.DatabaseType      = "mssql";
            deploy.LastChangeToApply = 500;
            deploy.OutputFile        = "Output File";
            deploy.Recursive         = true;
            deploy.RootDirectory     = "Root Directory";
            deploy.SearchPattern     = "*.sql";
            deploy.UndoFile          = "Undo File";

            deploy.Execute();

            Assert.That(configurationService, Is.EqualTo(deploy.ConfigurationService));

            Assert.That(configurationService.ConnectionString, Is.EqualTo("Connection String"));
            Assert.That(configurationService.DatabaseManagementSystem, Is.EqualTo(DatabaseTypesEnum.SqlServer));
            Assert.That(configurationService.LastChangeToApply, Is.EqualTo(500));
            Assert.That(configurationService.OutputFile, Is.EqualTo("Output File"));
            Assert.That(configurationService.UndoOutputFile, Is.EqualTo("Undo File"));
            Assert.That(configurationService.Recursive, Is.True);
            Assert.That(configurationService.RootDirectory, Is.EqualTo(Path.Combine(Environment.CurrentDirectory, "Root Directory")));
            Assert.That(configurationService.SearchPattern, Is.EqualTo("*.sql"));

            deploy.DatabaseType = "ora";
            deploy.Execute();

            Assert.That(configurationService.DatabaseManagementSystem, Is.EqualTo(DatabaseTypesEnum.Oracle));

            deploy.DatabaseType = "mysql";
            deploy.Execute();

            Assert.That(configurationService.DatabaseManagementSystem, Is.EqualTo(DatabaseTypesEnum.MySql));

            deploy.DatabaseType = "BadDBType";
            Assert.Throws <ArgumentException>(() => deploy.Execute());

            deploymentServiceMock.Verify(d => d.BuildDeploymentScript(), Times.Exactly(3));
        }