public void GetService() { SqlServer2000Platform sqlServer2000Platform = new SqlServer2000Platform(); IServiceProvider serviceProvider = new ServiceProvider(); serviceProvider.RegisterService(sqlServer2000Platform); Assert.AreSame(sqlServer2000Platform, serviceProvider.GetService<IDbPlatform>()); Assert.AreSame(sqlServer2000Platform, serviceProvider.GetService(typeof(IDbPlatform))); Assert.AreSame(sqlServer2000Platform, serviceProvider.GetService<SqlServer2000Platform>()); serviceProvider.RegisterService(typeof(IDbTypeMapper), delegate { return new SqlServer2000TypeMapper(); }); IDbTypeMapper dbTypeMapper = serviceProvider.GetService<IDbTypeMapper>(); Assert.IsNotNull(dbTypeMapper); Assert.AreNotSame(dbTypeMapper, serviceProvider.GetService<IDbTypeMapper>()); serviceProvider.RegisterService<IDbNamingStrategy>(delegate { return new SqlServer2000NamingStrategy(); }); IDbNamingStrategy dbNamingStrategy = serviceProvider.GetService<IDbNamingStrategy>(); Assert.IsNotNull(dbNamingStrategy); Assert.AreNotSame(dbNamingStrategy, serviceProvider.GetService<IDbNamingStrategy>()); }
public void GenerateScript() { IAstNode astNode; using (Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("octalforty.Wizardby.Tests.Resources.Blog.mdl")) { IMdlParser mdlParser = new MdlParser(MdlParserTestFixture.CreateScanner(new StreamReader(resourceStream, Encoding.UTF8))); astNode = mdlParser.Parse(); } // using IDbPlatform platform = new SqlServer2000Platform(); Environment environment = new Environment(); IMdlCompiler compiler = new MdlCompiler(new NullCodeGenerator(), environment); compiler.RemoveCompilerStage<DowngradeGenerationStage>(); compiler.RemoveCompilerStage<UpgradeGenerationStage>(); compiler.AddCompilerStageAfter<AstFlattenerCompilerStage>(new DbNamingCompilerStage(platform.NamingStrategy)); compiler.Compile(astNode, MdlCompilationOptions.All); DbStatementBatchWriter batchWriter = new DbStatementBatchWriter(); IDbScriptGenerator scriptGenerator = platform.Dialect.CreateScriptGenerator(batchWriter); //scriptGenerator.SetEnvironment(environment); foreach(IVersionNode versionNode in Algorithms.Filter<IAstNode, IVersionNode>(astNode.ChildNodes)) versionNode.Accept(scriptGenerator); System.Console.WriteLine(batchWriter.GetStatementBatches()[0].Clean()); Assert.AreEqual(@"create table [SchemaInfo] ( [Version] bigint not null ); create table [Author] ( [ID] int not null identity , [FirstName] nvarchar(200) not null , [LastName] nvarchar(200) not null , [EmailAddress] nvarchar(200) not null , [Login] nvarchar(200) not null , [Password] varbinary(64) null , primary key (ID) ); create table [Tag] ( [ID] int not null identity , [Name] nvarchar(200) not null , primary key (ID) ); create table [Blog] ( [ID] int not null identity , [Name] nvarchar(200) not null , [Description] nvarchar(max) not null , primary key (ID) ); create table [BlogPost] ( [ID] int not null identity , [Title] nvarchar(200) not null , [Slug] nvarchar(200) not null , [BlogID] int not null , [AuthorID] int not null , primary key (ID) ); create table [BlogPostTagJunction] ( [BlogPostID] int not null, [TagID] int not null, ); create unique nonclustered index [UQ_Version] on [SchemaInfo] ([Version]); create unique nonclustered index [IX_EmailAddress] on [Author] ([EmailAddress]); create unique nonclustered index [IX_Login] on [Author] ([Login]); alter table [BlogPost] add constraint [FK1] foreign key ([BlogID]) references [Blog] ([ID]); alter table [BlogPost] add constraint [FK2] foreign key ([AuthorID]) references [Author] ([ID]); alter table [BlogPostTagJunction] add constraint [FK3] foreign key ([BlogPostID]) references [BlogPost] ([ID]); alter table [BlogPostTagJunction] add constraint [FK4] foreign key ([TagID]) references [Tag] ([ID]); create table [BlogPostComment] ( [ID] int not null identity primary key, [BlogPostID] int not null, [AuthorEmailAddress] nvarchar(200) not null, [Content] nvarchar(max) not null, ); alter table [BlogPostComment] add constraint [FK5] foreign key ([BlogPostID]) references [BlogPost] ([ID]); create table [Media] ( [ID] int not null identity primary key, [TypeID] int , [Name] nvarchar(200) not null, [MimeType] nvarchar(200) not null, [Length] int , [BlogPostID] int null, [BlogPostCommentID] int null, ); create table [User] ( [ID] int not null identity primary key, [Login] nvarchar(200) not null, [Password] varbinary(64) not null, ); alter table [Media] add constraint [DF_MimeType] default ('text/xml') for [MimeType]; alter table [Media] add constraint [FK10] foreign key ([BlogPostID]) references [BlogPost] ([ID]); alter table [Media] add constraint [FK11] foreign key ([BlogPostCommentID]) references [BlogPostComment] ([ID]); create unique nonclustered index [IX_Login] on [User] ([ID], [Login] desc); create table [Forum] ( [ID] int not null identity primary key, [Name] nvarchar(200) not null, [ModeratorUserID] int not null, ); alter table [Forum] add constraint [FK_FOO] foreign key ([ModeratorUserID]) references [User] ([ID]); drop index [IX_Login] on [User]; create unique nonclustered index [IX_Login] on [User] ([ID], [Login] desc); create table [BlogAuthorJunction] ( [BlogID] int not null, [AuthorID] int not null, ); alter table [BlogAuthorJunction] add constraint [FK12] foreign key ([BlogID]) references [Blog] ([ID]); alter table [BlogAuthorJunction] add constraint [FK13] foreign key ([AuthorID]) references [Author] ([ID]); alter table [Forum] add [Slug] nvarchar(200) not null; alter table [Forum] drop column [Slug]; alter table [Forum] add [Slug] nvarchar(200) not null; alter table [Forum] alter column [Slug] nvarchar(200) null; alter table [Forum] drop constraint [FK_FOO]; drop table [Forum]; alter table [BlogPostTagJunction] drop constraint [FK4]; drop table [Tag]; ".Clean(), batchWriter.GetStatementBatches()[0].Clean()); }