Example #1
0
        public void Synchronization_ParameterDefinitionChanged()
        {
            string expectedMessage =
                "Parameter @startNumber is declared as 'DECLARE @startNumber AS int;' but in the Catalogue it appears as 'DECLARE @startNumber AS datetime;'";

            AnyTableSqlParameter parameter = (AnyTableSqlParameter)_function.TableInfoCreated.GetAllParameters().Single(p => p.ParameterName.Equals("@startNumber"));

            parameter.ParameterSQL = "DECLARE @startNumber AS datetime;";
            parameter.SaveToDatabase();

            var syncer = new TableInfoSynchronizer(_function.TableInfoCreated);

            var ex = Assert.Throws <Exception>(() => syncer.Synchronize(new ThrowImmediatelyCheckNotifier()));

            Assert.IsTrue(ex.Message.Contains(expectedMessage));

            //no changes should yet have taken place since we didn't accept it yet
            Assert.IsTrue(parameter.HasLocalChanges().Evaluation == ChangeDescription.NoChanges);

            //sync should have proposed to adjusting the datatype
            Assert.IsTrue(syncer.Synchronize(new AcceptAllCheckNotifier()));

            //now parameter should have the correct datatype
            Assert.IsTrue(parameter.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyDifferent);
            var diff = parameter.HasLocalChanges().Differences.Single();

            Assert.AreEqual("DECLARE @startNumber AS datetime;", diff.LocalValue);
            Assert.AreEqual("DECLARE @startNumber AS int;", diff.DatabaseValue);
        }
Example #2
0
        public void Synchronization_ExtraParameter()
        {
            string expectedMessage =
                "MyAwesomeFunction is a Table Valued Function, in the Catalogue it has a parameter called @fish but this parameter no longer appears in the underlying database";

            var excessParameter = new AnyTableSqlParameter(CatalogueRepository, _function.TableInfoCreated, "DECLARE @fish as int");
            var checker         = new ToMemoryCheckNotifier();

            _function.TableInfoCreated.Check(checker);

            Assert.IsTrue(checker.Messages.Any(m => m.Result == CheckResult.Fail
                                               &&
                                               m.Message.Contains(expectedMessage)));

            var syncer = new TableInfoSynchronizer(_function.TableInfoCreated);

            var ex = Assert.Throws <Exception>(() => syncer.Synchronize(new ThrowImmediatelyCheckNotifier()));

            Assert.IsTrue(ex.Message.Contains(expectedMessage));

            //no changes yet
            Assert.IsTrue(excessParameter.HasLocalChanges().Evaluation == ChangeDescription.NoChanges);

            //sync should have proposed to drop the excess parameter (see above), accept the change
            Assert.IsTrue(syncer.Synchronize(new AcceptAllCheckNotifier()));

            //now parameter shouldnt be there
            Assert.IsTrue(excessParameter.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyWasDeleted);
        }