Exemplo n.º 1
0
        public void GetCreateScript_GetDropScript_ValidConnectionString()
        {
            var statement1       = new ScriptStatement("Test1");
            var statement2       = new ScriptStatement("Test2");
            var fakeCreateResult = new ScriptElementCollection();

            fakeCreateResult.AddElement(statement1);
            fakeCreateResult.AddElement(statement2);
            var fakeDropResult = new ScriptElementCollection();

            fakeDropResult.AddElement(statement2);
            fakeDropResult.AddElement(statement1);

            _innerScriptBuilderMock.Expect(mock => mock.GetCreateScript()).Return(fakeCreateResult);
            _innerScriptBuilderMock.Expect(mock => mock.GetDropScript()).Return(fakeDropResult);

            var createScriptResult = _builder.GetCreateScript();
            var dropScriptResult   = _builder.GetDropScript();

            Assert.That(((ScriptElementCollection)createScriptResult).Elements.Count, Is.EqualTo(2));
            Assert.That(((ScriptStatement)((ScriptElementCollection)createScriptResult).Elements[0]).Statement, Is.EqualTo("USE MyDataBase"));
            Assert.That(((ScriptElementCollection)createScriptResult).Elements[1], Is.SameAs(fakeCreateResult));
            Assert.That(((ScriptElementCollection)dropScriptResult).Elements.Count, Is.EqualTo(2));
            Assert.That(((ScriptStatement)((ScriptElementCollection)dropScriptResult).Elements[0]).Statement, Is.EqualTo("USE MyDataBase"));
            Assert.That(((ScriptElementCollection)dropScriptResult).Elements[1], Is.SameAs(fakeDropResult));
        }
        public IScriptElement GetDropScript()
        {
            var dropScriptElements = new ScriptElementCollection();

            dropScriptElements.AddElement(new ScriptStatement("USE " + GetDatabaseName()));
            dropScriptElements.AddElement(_innerScriptBuilder.GetDropScript());
            return(dropScriptElements);
        }
Exemplo n.º 3
0
        public void Convert_OneScriptElement()
        {
            _fakeCreateElements.AddElement(_scriptElement1);
            _fakeDropElements.AddElement(_scriptElement2);

            var result = _converter.Convert(_scriptBuilderStub);

            Assert.That(result.SetUpScript, Is.EqualTo("Test1\r\n"));
            Assert.That(result.TearDownScript, Is.EqualTo("Test2\r\n"));
        }
 private void AddIndexes(IEnumerable <IIndexDefinition> indexes, EntityNameDefinition ownerName)
 {
     foreach (var index in indexes)
     {
         _createScriptElements.AddElement(_indexScriptElementFactory.GetCreateElement(index, ownerName));
         _dropScriptElements.AddElement(_indexScriptElementFactory.GetDropElement(index, ownerName));
     }
 }
Exemplo n.º 5
0
        public override void SetUp()
        {
            base.SetUp();

            _builder1Mock = MockRepository.GenerateStrictMock <IScriptBuilder>();
            _builder2Mock = MockRepository.GenerateStrictMock <IScriptBuilder>();

            _fakeStatement1 = new ScriptStatement("Fake1");
            _fakeStatement2 = new ScriptStatement("Fake2");
            _fakeStatement3 = new ScriptStatement("Fake3");

            _fakeResultCollection1 = new ScriptElementCollection();
            _fakeResultCollection1.AddElement(_fakeStatement1);

            _fakeResultCollection2 = new ScriptElementCollection();
            _fakeResultCollection2.AddElement(_fakeStatement2);
            _fakeResultCollection2.AddElement(_fakeStatement3);
        }
Exemplo n.º 6
0
        public IScriptElement GetDropScript()
        {
            var scriptElementCollection = new ScriptElementCollection();

            foreach (var scriptBuilder in _scriptBuilders.Reverse())
            {
                scriptElementCollection.AddElement(scriptBuilder.GetDropScript());
            }
            return(scriptElementCollection);
        }
Exemplo n.º 7
0
        public IScriptElement GetCreateScript()
        {
            var scriptElementCollection = new ScriptElementCollection();

            foreach (var scriptBuilder in _scriptBuilders)
            {
                scriptElementCollection.AddElement(scriptBuilder.GetCreateScript());
            }
            return(scriptElementCollection);
        }
        public TableScriptBuilder(ITableScriptElementFactory elementFactory, ICommentScriptElementFactory commentFactory)
        {
            ArgumentUtility.CheckNotNull("elementFactory", elementFactory);
            ArgumentUtility.CheckNotNull("commentFactory", commentFactory);

            _elementFactory       = elementFactory;
            _createScriptElements = new ScriptElementCollection();
            _createScriptElements.AddElement(commentFactory.GetCommentElement("Create all tables"));
            _dropScriptElements = new ScriptElementCollection();
            _dropScriptElements.AddElement(commentFactory.GetCommentElement("Drop all tables"));
        }
        public IndexScriptBuilder(IIndexScriptElementFactory indexScriptElementFactory, ICommentScriptElementFactory commentFactory)
        {
            ArgumentUtility.CheckNotNull("indexScriptElementFactory", indexScriptElementFactory);
            ArgumentUtility.CheckNotNull("commentFactory", commentFactory);

            _indexScriptElementFactory = indexScriptElementFactory;
            _createScriptElements      = new ScriptElementCollection();
            _createScriptElements.AddElement(commentFactory.GetCommentElement("Create indexes for tables that were created above"));
            _dropScriptElements = new ScriptElementCollection();
            _dropScriptElements.AddElement(commentFactory.GetCommentElement("Drop all indexes"));
        }
        public IScriptElement GetCreateElement(T entityDefinition)
        {
            ArgumentUtility.CheckNotNull("entityDefinition", entityDefinition);

            var statements = new ScriptElementCollection();

            statements.AddElement(CreateBatchDelimiterStatement());
            statements.AddElement(
                new ScriptStatement(
                    string.Format(
                        "CREATE VIEW [{0}].[{1}] ({2})\r\n"
                        + "  {3}AS\r\n{4}{5}",
                        entityDefinition.ViewName.SchemaName ?? DefaultSchema,
                        entityDefinition.ViewName.EntityName,
                        GetColumnList(entityDefinition.GetAllColumns()),
                        UseSchemaBinding(entityDefinition) ? "WITH SCHEMABINDING " : string.Empty,
                        GetSelectStatements(entityDefinition),
                        UseCheckOption(entityDefinition) ? "\r\n  WITH CHECK OPTION" : string.Empty)));
            statements.AddElement(CreateBatchDelimiterStatement());
            return(statements);
        }
Exemplo n.º 11
0
        public void AppendToScript_OneElement()
        {
            var script = new List <ScriptStatement> ();

            _elementCollection.AddElement(_elementMock1);

            _elementMock1.Expect(mock => mock.AppendToScript(script));
            _elementMock1.Replay();

            _elementCollection.AppendToScript(script);

            _elementMock1.VerifyAllExpectations();
            Assert.That(script, Is.Empty);
        }
        public SynonymScriptBuilder(
            ISynonymScriptElementFactory <TableDefinition> tableViewElementFactory,
            ISynonymScriptElementFactory <UnionViewDefinition> unionViewElementFactory,
            ISynonymScriptElementFactory <FilterViewDefinition> filterViewElementFactory,
            ISynonymScriptElementFactory <EmptyViewDefinition> emptyViewElementFactory,
            ICommentScriptElementFactory commentFactory)
        {
            ArgumentUtility.CheckNotNull("tableViewElementFactory", tableViewElementFactory);
            ArgumentUtility.CheckNotNull("unionViewElementFactory", unionViewElementFactory);
            ArgumentUtility.CheckNotNull("filterViewElementFactory", filterViewElementFactory);
            ArgumentUtility.CheckNotNull("emptyViewElementFactory", emptyViewElementFactory);
            ArgumentUtility.CheckNotNull("commentFactory", commentFactory);

            _tableViewElementFactory  = tableViewElementFactory;
            _unionViewElementFactory  = unionViewElementFactory;
            _filterViewElementFactory = filterViewElementFactory;
            _emptyViewElementFactory  = emptyViewElementFactory;
            _createScriptElements     = new ScriptElementCollection();
            _createScriptElements.AddElement(commentFactory.GetCommentElement("Create synonyms for tables that were created above"));
            _dropScriptElements = new ScriptElementCollection();
            _dropScriptElements.AddElement(commentFactory.GetCommentElement("Drop all synonyms"));
        }
Exemplo n.º 13
0
        public ViewScriptBuilder(
            IViewScriptElementFactory <TableDefinition> tableViewElementFactory,
            IViewScriptElementFactory <UnionViewDefinition> unionViewElementFactory,
            IViewScriptElementFactory <FilterViewDefinition> filterViewElementFactory,
            IViewScriptElementFactory <EmptyViewDefinition> emptyViewElementFactory,
            ICommentScriptElementFactory commentFactory)
        {
            ArgumentUtility.CheckNotNull("tableViewElementFactory", tableViewElementFactory);
            ArgumentUtility.CheckNotNull("unionViewElementFactory", unionViewElementFactory);
            ArgumentUtility.CheckNotNull("filterViewElementFactory", filterViewElementFactory);
            ArgumentUtility.CheckNotNull("emptyViewElementFactory", emptyViewElementFactory);
            ArgumentUtility.CheckNotNull("commentFactory", commentFactory);

            _tableViewElementFactory  = tableViewElementFactory;
            _unionViewElementFactory  = unionViewElementFactory;
            _filterViewElementFactory = filterViewElementFactory;
            _emptyViewElementFactory  = emptyViewElementFactory;

            _createScriptElements = new ScriptElementCollection();
            _createScriptElements.AddElement(commentFactory.GetCommentElement("Create a view for every class"));
            _dropScriptElements = new ScriptElementCollection();
            _dropScriptElements.AddElement(commentFactory.GetCommentElement("Drop all views"));
        }
 private void AddElements(IScriptElement createElement, IScriptElement dropElement)
 {
     _createScriptElements.AddElement(createElement);
     _dropScriptElements.AddElement(dropElement);
 }
 private void AddTableDefinition(TableDefinition tableDefinition)
 {
     _createScriptElements.AddElement(_elementFactory.GetCreateElement(tableDefinition));
     _dropScriptElements.AddElement(_elementFactory.GetDropElement(tableDefinition));
 }