public IPagesStorageProviderV30 GetProvider() { SqlServerPagesStorageProvider prov = new SqlServerPagesStorageProvider(); prov.Init(MockHost(), ConnString + InitialCatalog); return(prov); }
/// <summary> /// Gets the instance of the index to test. /// </summary> /// <returns>The instance of the index.</returns> protected override IIndex GetIndex() { SqlServerPagesStorageProvider prov = GetProvider() as SqlServerPagesStorageProvider; prov.SetFlags(true); return(prov.Index); }
public override IPagesStorageProviderV40 GetProvider() { SqlServerPagesStorageProvider prov = new SqlServerPagesStorageProvider(); prov.SetUp(MockHost(), ConnString + InitialCatalog); prov.Init(MockHost(), ConnString + InitialCatalog, null); return(prov); }
public IPagesStorageProviderV30 GetProvider() { SqlServerPagesStorageProvider prov = new SqlServerPagesStorageProvider(); prov.Init(MockHost(), ConnString + InitialCatalog); return prov; }
public void Init_Upgrade( ) { FixtureTearDown( ); SqlConnection cn = new SqlConnection(ConnString); cn.Open( ); SqlCommand cmd = cn.CreateCommand( ); cmd.CommandText = "create database [ScrewTurnWikiTest];"; cmd.ExecuteNonQuery( ); cn.Close( ); cn = new SqlConnection(ConnString + InitialCatalog); cn.Open( ); cmd = cn.CreateCommand( ); cmd.CommandText = @"CREATE TABLE [PagesProviderVersion] ( [Version] varchar(12) PRIMARY KEY ); INSERT INTO [PagesProviderVersion] ([Version]) VALUES ('Irrelevant'); create table [Page] ( [Name] nvarchar(128) primary key, [Status] char not null default ('N'), -- (P)ublic, N(ormal), (L)ocked [CreationDateTime] datetime not null ); create table [PageContent] ( [Page] nvarchar(128) references [Page]([Name]) on update cascade on delete cascade, [Revision] int not null default ((-1)), -- -1 for Current Revision [Title] nvarchar(256) not null, [DateTime] datetime not null, [Username] nvarchar(64) not null, [Content] ntext not null, [Comment] nvarchar(128) not null, primary key ([Page], [Revision]) ); create table [Category] ( [Name] nvarchar(128) primary key ); create table [CategoryBinding] ( [Category] nvarchar(128) references [Category]([Name]) on update cascade on delete cascade, [Page] nvarchar(128) references [Page]([Name]) on update cascade on delete cascade, primary key ([Category], [Page]) ); create table [Message] ( [ID] int primary key identity, [Page] nvarchar(128) references [Page]([Name]) on update cascade on delete cascade, [Parent] int not null, -- -1 for no parent [Username] nvarchar(64) not null, [DateTime] datetime not null, [Subject] nvarchar(128) not null, [Body] ntext not null ); create table [Snippet] ( [Name] nvarchar(128) primary key, [Content] ntext not null ); create table [NavigationPath] ( [Name] nvarchar(128) not null primary key ); create table [NavigationPathBinding] ( [NavigationPath] nvarchar(128) not null references [NavigationPath]([Name]) on delete cascade, [Page] nvarchar(128) not null references [Page]([Name]) on update cascade on delete cascade, [Number] int not null, primary key ([NavigationPath], [Page], [Number]) ); insert into [Page] ([Name], [Status], [CreationDateTime]) values ('Page1', 'N', '2008/12/31 12:12:12'); insert into [Page] ([Name], [Status], [CreationDateTime]) values ('Page2', 'L', '2008/12/31 12:12:12'); insert into [Page] ([Name], [Status], [CreationDateTime]) values ('Page.WithDot', 'P', '2008/12/31 12:12:12'); insert into [PageContent] ([Page], [Revision], [Title], [DateTime], [Username], [Content], [Comment]) values ('Page1', -1, 'Page1 Title', '2008/12/31 14:14:14', 'SYSTEM', 'Test Content 1', 'Comment 1'); insert into [PageContent] ([Page], [Revision], [Title], [DateTime], [Username], [Content], [Comment]) values ('Page1', 0, 'Page1 Title 0', '2008/12/31 12:12:12', 'SYSTEM', 'Test Content 0', ''); insert into [PageContent] ([Page], [Revision], [Title], [DateTime], [Username], [Content], [Comment]) values ('Page2', -1, 'Page2 Title', '2008/12/31 14:14:14', 'SYSTEM', 'Test Content 2', 'Comment 2'); insert into [PageContent] ([Page], [Revision], [Title], [DateTime], [Username], [Content], [Comment]) values ('Page.WithDot', -1, 'Page.WithDot Title', '2008/12/31 14:14:14', 'SYSTEM', 'Test Content 3', 'Comment 3'); insert into [Category] ([Name]) values ('Cat1'); insert into [Category] ([Name]) values ('Cat2'); insert into [Category] ([Name]) values ('Cat.WithDot'); insert into [CategoryBinding] ([Category], [Page]) values ('Cat1', 'Page1'); insert into [CategoryBinding] ([Category], [Page]) values ('Cat2', 'Page1'); insert into [CategoryBinding] ([Category], [Page]) values ('Cat1', 'Page2'); insert into [CategoryBinding] ([Category], [Page]) values ('Cat2', 'Page.WithDot'); insert into [CategoryBinding] ([Category], [Page]) values ('Cat.WithDot', 'Page.WithDot'); insert into [Message] ([Page], [Parent], [Username], [DateTime], [Subject], [Body]) values ('Page1', -1, 'SYSTEM', '2008/12/31 16:16:16', 'Test 1', 'Body 1'); insert into [Message] ([Page], [Parent], [Username], [DateTime], [Subject], [Body]) values ('Page1', 0, 'SYSTEM', '2008/12/31 16:16:16', 'Test 1.1', 'Body 1.1'); insert into [Message] ([Page], [Parent], [Username], [DateTime], [Subject], [Body]) values ('Page.WithDot', -1, 'SYSTEM', '2008/12/31 16:16:16', 'Test dot', 'Body dot'); insert into [Snippet] ([Name], [Content]) values ('Snip', 'Content'); insert into [NavigationPath] ([Name]) values ('Path'); insert into [NavigationPathBinding] ([NavigationPath], [Page], [Number]) values ('Path', 'Page1', 1); insert into [NavigationPathBinding] ([NavigationPath], [Page], [Number]) values ('Path', 'Page2', 2); insert into [NavigationPathBinding] ([NavigationPath], [Page], [Number]) values ('Path', 'Page.WithDot', 3);"; bool done = false; try { cmd.ExecuteNonQuery( ); done = true; } catch (SqlException sqlex) { Console.WriteLine(sqlex); } finally { cn.Close( ); } if (!done) { throw new Exception("Could not generate v2 test database"); } MockRepository mocks = new MockRepository( ); IHostV30 host = mocks.DynamicMock <IHostV30>( ); Expect.Call(host.UpgradePageStatusToAcl(null, 'L')).IgnoreArguments( ).Repeat.Twice( ).Return(true); mocks.Replay(host); SqlServerPagesStorageProvider prov = new SqlServerPagesStorageProvider( ); prov.Init(host, ConnString + InitialCatalog); Snippet[] snippets = prov.GetSnippets( ); Assert.AreEqual(1, snippets.Length, "Wrong snippet count"); Assert.AreEqual("Snip", snippets[0].Name, "Wrong snippet name"); Assert.AreEqual("Content", snippets[0].Content, "Wrong snippet content"); PageInfo[] pages = prov.GetPages(null); Assert.AreEqual(3, pages.Length, "Wrong page count"); Assert.AreEqual("Page_WithDot", pages[0].FullName, "Wrong page name"); Assert.AreEqual("Page1", pages[1].FullName, "Wrong page name"); Assert.AreEqual("Page2", pages[2].FullName, "Wrong page name"); Assert.AreEqual("Test Content 3", prov.GetContent(pages[0]).Content, "Wrong content"); Assert.AreEqual("Test Content 1", prov.GetContent(pages[1]).Content, "Wrong content"); Assert.AreEqual("Test Content 0", prov.GetBackupContent(pages[1], 0).Content, "Wrong backup content"); Assert.AreEqual("Test Content 2", prov.GetContent(pages[2]).Content, "Wrong content"); Message[] messages = prov.GetMessages(pages[0]); Assert.AreEqual(1, messages.Length, "Wrong message count"); Assert.AreEqual("Test dot", messages[0].Subject, "Wrong message subject"); CategoryInfo[] categories = prov.GetCategories(null); Assert.AreEqual(3, categories.Length, "Wrong category count"); Assert.AreEqual("Cat_WithDot", categories[0].FullName, "Wrong category name"); Assert.AreEqual(1, categories[0].Pages.Length, "Wrong page count"); Assert.AreEqual("Page_WithDot", categories[0].Pages[0], "Wrong page"); Assert.AreEqual("Cat1", categories[1].FullName, "Wrong category name"); Assert.AreEqual("Page1", categories[1].Pages[0], "Wrong page"); Assert.AreEqual("Page2", categories[1].Pages[1], "Wrong page"); Assert.AreEqual("Cat2", categories[2].FullName, "Wrong category name"); Assert.AreEqual("Page_WithDot", categories[2].Pages[0], "Wrong page"); Assert.AreEqual("Page1", categories[2].Pages[1], "Wrong page"); NavigationPath[] paths = prov.GetNavigationPaths(null); Assert.AreEqual(1, paths.Length, "Wrong navigation path count"); Assert.AreEqual("Path", paths[0].FullName, "Wrong navigation path name"); Assert.AreEqual("Page1", paths[0].Pages[0], "Wrong page"); Assert.AreEqual("Page2", paths[0].Pages[1], "Wrong page"); Assert.AreEqual("Page_WithDot", paths[0].Pages[2], "Wrong page"); mocks.Verify(host); }
public void SetUp_InvalidConnString(string c) { SqlServerPagesStorageProvider prov = new SqlServerPagesStorageProvider(); prov.SetUp(MockHost(), c); }
public void Init_Upgrade() { FixtureTearDown(); SqlConnection cn = new SqlConnection(ConnString); cn.Open(); SqlCommand cmd = cn.CreateCommand(); cmd.CommandText = "create database [ScrewTurnWikiTest];"; cmd.ExecuteNonQuery(); cn.Close(); cn = new SqlConnection(ConnString + InitialCatalog); cn.Open(); cmd = cn.CreateCommand(); cmd.CommandText = @"CREATE TABLE [PagesProviderVersion] ( [Version] varchar(12) PRIMARY KEY ); INSERT INTO [PagesProviderVersion] ([Version]) VALUES ('Irrelevant'); create table [Page] ( [Name] nvarchar(128) primary key, [Status] char not null default ('N'), -- (P)ublic, N(ormal), (L)ocked [CreationDateTime] datetime not null ); create table [PageContent] ( [Page] nvarchar(128) references [Page]([Name]) on update cascade on delete cascade, [Revision] int not null default ((-1)), -- -1 for Current Revision [Title] nvarchar(256) not null, [DateTime] datetime not null, [Username] nvarchar(64) not null, [Content] ntext not null, [Comment] nvarchar(128) not null, primary key ([Page], [Revision]) ); create table [Category] ( [Name] nvarchar(128) primary key ); create table [CategoryBinding] ( [Category] nvarchar(128) references [Category]([Name]) on update cascade on delete cascade, [Page] nvarchar(128) references [Page]([Name]) on update cascade on delete cascade, primary key ([Category], [Page]) ); create table [Message] ( [ID] int primary key identity, [Page] nvarchar(128) references [Page]([Name]) on update cascade on delete cascade, [Parent] int not null, -- -1 for no parent [Username] nvarchar(64) not null, [DateTime] datetime not null, [Subject] nvarchar(128) not null, [Body] ntext not null ); create table [Snippet] ( [Name] nvarchar(128) primary key, [Content] ntext not null ); create table [NavigationPath] ( [Name] nvarchar(128) not null primary key ); create table [NavigationPathBinding] ( [NavigationPath] nvarchar(128) not null references [NavigationPath]([Name]) on delete cascade, [Page] nvarchar(128) not null references [Page]([Name]) on update cascade on delete cascade, [Number] int not null, primary key ([NavigationPath], [Page], [Number]) ); insert into [Page] ([Name], [Status], [CreationDateTime]) values ('Page1', 'N', '2008/12/31 12:12:12'); insert into [Page] ([Name], [Status], [CreationDateTime]) values ('Page2', 'L', '2008/12/31 12:12:12'); insert into [Page] ([Name], [Status], [CreationDateTime]) values ('Page.WithDot', 'P', '2008/12/31 12:12:12'); insert into [PageContent] ([Page], [Revision], [Title], [DateTime], [Username], [Content], [Comment]) values ('Page1', -1, 'Page1 Title', '2008/12/31 14:14:14', 'SYSTEM', 'Test Content 1', 'Comment 1'); insert into [PageContent] ([Page], [Revision], [Title], [DateTime], [Username], [Content], [Comment]) values ('Page1', 0, 'Page1 Title 0', '2008/12/31 12:12:12', 'SYSTEM', 'Test Content 0', ''); insert into [PageContent] ([Page], [Revision], [Title], [DateTime], [Username], [Content], [Comment]) values ('Page2', -1, 'Page2 Title', '2008/12/31 14:14:14', 'SYSTEM', 'Test Content 2', 'Comment 2'); insert into [PageContent] ([Page], [Revision], [Title], [DateTime], [Username], [Content], [Comment]) values ('Page.WithDot', -1, 'Page.WithDot Title', '2008/12/31 14:14:14', 'SYSTEM', 'Test Content 3', 'Comment 3'); insert into [Category] ([Name]) values ('Cat1'); insert into [Category] ([Name]) values ('Cat2'); insert into [Category] ([Name]) values ('Cat.WithDot'); insert into [CategoryBinding] ([Category], [Page]) values ('Cat1', 'Page1'); insert into [CategoryBinding] ([Category], [Page]) values ('Cat2', 'Page1'); insert into [CategoryBinding] ([Category], [Page]) values ('Cat1', 'Page2'); insert into [CategoryBinding] ([Category], [Page]) values ('Cat2', 'Page.WithDot'); insert into [CategoryBinding] ([Category], [Page]) values ('Cat.WithDot', 'Page.WithDot'); insert into [Message] ([Page], [Parent], [Username], [DateTime], [Subject], [Body]) values ('Page1', -1, 'SYSTEM', '2008/12/31 16:16:16', 'Test 1', 'Body 1'); insert into [Message] ([Page], [Parent], [Username], [DateTime], [Subject], [Body]) values ('Page1', 0, 'SYSTEM', '2008/12/31 16:16:16', 'Test 1.1', 'Body 1.1'); insert into [Message] ([Page], [Parent], [Username], [DateTime], [Subject], [Body]) values ('Page.WithDot', -1, 'SYSTEM', '2008/12/31 16:16:16', 'Test dot', 'Body dot'); insert into [Snippet] ([Name], [Content]) values ('Snip', 'Content'); insert into [NavigationPath] ([Name]) values ('Path'); insert into [NavigationPathBinding] ([NavigationPath], [Page], [Number]) values ('Path', 'Page1', 1); insert into [NavigationPathBinding] ([NavigationPath], [Page], [Number]) values ('Path', 'Page2', 2); insert into [NavigationPathBinding] ([NavigationPath], [Page], [Number]) values ('Path', 'Page.WithDot', 3);"; bool done = false; try { cmd.ExecuteNonQuery(); done = true; } catch(SqlException sqlex) { Console.WriteLine(sqlex); } finally { cn.Close(); } if(!done) throw new Exception("Could not generate v2 test database"); MockRepository mocks = new MockRepository(); IHostV30 host = mocks.DynamicMock<IHostV30>(); Expect.Call(host.UpgradePageStatusToAcl(null, 'L')).IgnoreArguments().Repeat.Twice().Return(true); mocks.Replay(host); SqlServerPagesStorageProvider prov = new SqlServerPagesStorageProvider(); prov.Init(host, ConnString + InitialCatalog); Snippet[] snippets = prov.GetSnippets(); Assert.AreEqual(1, snippets.Length, "Wrong snippet count"); Assert.AreEqual("Snip", snippets[0].Name, "Wrong snippet name"); Assert.AreEqual("Content", snippets[0].Content, "Wrong snippet content"); PageInfo[] pages = prov.GetPages(null); Assert.AreEqual(3, pages.Length, "Wrong page count"); Assert.AreEqual("Page_WithDot", pages[0].FullName, "Wrong page name"); Assert.AreEqual("Page1", pages[1].FullName, "Wrong page name"); Assert.AreEqual("Page2", pages[2].FullName, "Wrong page name"); Assert.AreEqual("Test Content 3", prov.GetContent(pages[0]).Content, "Wrong content"); Assert.AreEqual("Test Content 1", prov.GetContent(pages[1]).Content, "Wrong content"); Assert.AreEqual("Test Content 0", prov.GetBackupContent(pages[1], 0).Content, "Wrong backup content"); Assert.AreEqual("Test Content 2", prov.GetContent(pages[2]).Content, "Wrong content"); Message[] messages = prov.GetMessages(pages[0]); Assert.AreEqual(1, messages.Length, "Wrong message count"); Assert.AreEqual("Test dot", messages[0].Subject, "Wrong message subject"); CategoryInfo[] categories = prov.GetCategories(null); Assert.AreEqual(3, categories.Length, "Wrong category count"); Assert.AreEqual("Cat_WithDot", categories[0].FullName, "Wrong category name"); Assert.AreEqual(1, categories[0].Pages.Length, "Wrong page count"); Assert.AreEqual("Page_WithDot", categories[0].Pages[0], "Wrong page"); Assert.AreEqual("Cat1", categories[1].FullName, "Wrong category name"); Assert.AreEqual("Page1", categories[1].Pages[0], "Wrong page"); Assert.AreEqual("Page2", categories[1].Pages[1], "Wrong page"); Assert.AreEqual("Cat2", categories[2].FullName, "Wrong category name"); Assert.AreEqual("Page_WithDot", categories[2].Pages[0], "Wrong page"); Assert.AreEqual("Page1", categories[2].Pages[1], "Wrong page"); NavigationPath[] paths = prov.GetNavigationPaths(null); Assert.AreEqual(1, paths.Length, "Wrong navigation path count"); Assert.AreEqual("Path", paths[0].FullName, "Wrong navigation path name"); Assert.AreEqual("Page1", paths[0].Pages[0], "Wrong page"); Assert.AreEqual("Page2", paths[0].Pages[1], "Wrong page"); Assert.AreEqual("Page_WithDot", paths[0].Pages[2], "Wrong page"); mocks.Verify(host); }