public void Analyze_WhenExceptionThrown_EmailIsSent()
        {
            var mocks = new MockRepository();
            var stubWebService = mocks.Stub<IWebService>();
            var mockEmailSender = mocks.DynamicMock<IEmailSender>();

            using (mocks.Record())
            {
                stubWebService.LogError("Anything");
                LastCall.Constraints(Is.Anything());
                LastCall.Throw(new Exception("Fake Exception"));

                mockEmailSender.SendEmail("to", "subject", "Fake Exception");
            }

            var logAnalyzer = new LogAnalyzer
            {
                EmailSender = mockEmailSender,
                WebService = stubWebService
            };

            logAnalyzer.Analyze("abc.txt");

            mocks.Verify(mockEmailSender);
        }
Beispiel #2
0
        public void ClearEntriesForDirectory()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IFilesStorageProviderV30 filesProv = mocks.DynamicMock<IFilesStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            string dirName = Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(filesProv, "/Dir/Sub/");
            Expect.Call(aclManager.DeleteEntriesForResource(dirName)).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            AuthWriter.ClearEntriesForDirectory(filesProv, "/Dir/Sub/");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
 public void Undo_Test_기존에_입력된_내용이_없을때()
 {
     MockRepository mocks= new MockRepository();
     ICommandListener listener= mocks.DynamicMock<myInfoController>();
     myInfo mi= mocks.Stub<myInfo>();
     MyInfoInsertUpdateCommand myIUCMD = new MyInfoInsertUpdateCommand(mi,listener);
     myIUCMD.preMyInfo = null;
     using(mocks.Record())
     {
         listener.Delete(mi);
     }
     myIUCMD.Undo();
     mocks.Verify(listener);
 }
 public void execute_기존에_입력된_정보가_하나도_없고_파라미터는_정상인_경우()
 {
     MockRepository mocks = new MockRepository();
     ICommandListener listener = mocks.DynamicMock<myInfoController>();
     myInfo myInfo = mocks.Stub<myInfo>();
     MyInfoInsertUpdateCommand myInfoCommand = new MyInfoInsertUpdateCommand(myInfo, listener);
     using (mocks.Record())
     {
         myInfoCommand.preMyInfo = null;
         listener.Insert(myInfo);
         LastCall.Return(true);
     }
     myInfoCommand.execute();
     mocks.Verify(listener);
 }
Beispiel #5
0
 public void execute_업데이트과정_정상적으로_거치는지_검증()
 {
     MockRepository mocks = new MockRepository();
     UserInfo stubData = mocks.Stub<UserInfo>();
     stubData.id = "id";
     stubData.password = "******";
     ICommandListener mockListener = mocks.DynamicMock<UserAuthController>();
     UpdateUserInfo uui = new UpdateUserInfo(stubData, mockListener);
     using (mocks.Record())
     {
         mockListener.Select(stubData);
         mockListener.Update(stubData,stubData);
         LastCall.Return(true);
     }
     uui.execute();
     mocks.Verify(mockListener);
 }
        public void Init_Upgrade()
        {
            string testDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString());
            Directory.CreateDirectory(testDir);

            MockRepository mocks = new MockRepository();
            IHostV30 host = mocks.DynamicMock<IHostV30>();
            Expect.Call(host.GetSettingValue(SettingName.PublicDirectory)).Return(testDir).Repeat.AtLeastOnce();
            Expect.Call(host.GetSettingValue(SettingName.AdministratorsGroup)).Return("Administrators").Repeat.Once();
            Expect.Call(host.GetSettingValue(SettingName.UsersGroup)).Return("Users").Repeat.Once();

            Expect.Call(host.UpgradeSecurityFlagsToGroupsAcl(null, null)).IgnoreArguments().Repeat.Times(1).Return(true);

            mocks.Replay(host);

            string file = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "Users.cs");

            File.WriteAllText(file, "user|PASSHASH|[email protected]|Inactive|2008/10/31 15:15:15|USER\r\nsuperuser|SUPERPASSHASH|[email protected]|Active|2008/10/31 15:15:16|ADMIN");

            UsersStorageProvider prov = new UsersStorageProvider();
            prov.Init(host, "");

            UserInfo[] users = prov.GetUsers();

            Assert.AreEqual(2, users.Length, "Wrong user count");

            Assert.AreEqual("superuser", users[0].Username, "Wrong username");
            Assert.AreEqual("*****@*****.**", users[0].Email, "Wrong email");
            Assert.IsTrue(users[0].Active, "User should be active");
            Assert.AreEqual("2008/10/31 15:15:16", users[0].DateTime.ToString("yyyy'/'MM'/'dd' 'HH':'mm':'ss"), "Wrong date/time");
            Assert.AreEqual(1, users[0].Groups.Length, "Wrong user count");
            Assert.AreEqual("Administrators", users[0].Groups[0], "Wrong group");

            Assert.AreEqual("user", users[1].Username, "Wrong username");
            Assert.AreEqual("*****@*****.**", users[1].Email, "Wrong email");
            Assert.IsFalse(users[1].Active, "User should be inactive");
            Assert.AreEqual("2008/10/31 15:15:15", users[1].DateTime.ToString("yyyy'/'MM'/'dd' 'HH':'mm':'ss"), "Wrong date/time");
            Assert.AreEqual(1, users[1].Groups.Length, "Wrong user count");
            Assert.AreEqual("Users", users[1].Groups[0], "Wrong group");

            mocks.Verify(host);

            Directory.Delete(testDir, true);
        }
        public void Analyze_ShortFileName_LogsError()
        {
            var mocks = new MockRepository();
            var mockWebService = mocks.DynamicMock<IWebService>();

            using (mocks.Record())
            {
                mockWebService.LogError("Short FileName:abc.txt");
            }

            var logAnalyzer = new LogAnalyzer
            {
                WebService = mockWebService
            };

            logAnalyzer.Analyze("abc.txt");

            mocks.Verify(mockWebService);
        }
Beispiel #8
0
 public void execute_Test_정상적으로입력_Return_True()
 {
     //Arrange
     MockRepository mocks = new MockRepository();
     object uInfo = null;
     UserInfo LoginInfo=mocks.Stub<UserInfo>();
              LoginInfo.id = "id";
              LoginInfo.password = "******";
     ICommandListener mockCMDListener = mocks.DynamicMock<UserAuthController>();
     Login login = new Login(mockCMDListener, LoginInfo);
     using (mocks.Record())
     {
         mockCMDListener.Select(LoginInfo);
     }
     //Act
     bool isOK = login.execute(out uInfo);
     //Assert
     mocks.Verify(mockCMDListener);
 }
        public void execute_Out타입_파라미터_있는_메서드_Test_정상적으로_로직_실행_하는지()
        {
            MockRepository mocks = new MockRepository();

            InstanceContext ClientCallback = mocks.Stub<InstanceContext>();
            ISQLWebService stubService     = mocks.Stub<SQLWebServiceClient>(new object[] {ClientCallback});
            IDataModel dbModel             = mocks.Stub<SQLDataServiceModel>();
            ((SQLDataServiceModel)dbModel).sqlService = stubService;
            ((SQLDataServiceModel)dbModel).EncryptionSeed = "1234";
            IDataQueryRepository SQLQueryHouse= mocks.Stub<SQLDataQueryRepository>();
            IDataModel localDataModel = mocks.Stub<LocalDataFileService>();

            IDataQueryRepository localQueryHouse = mocks.Stub<LocalDataQueryRepository>();
            object[] paramList = { dbModel,localDataModel,SQLQueryHouse,localQueryHouse};
            ICommandListener mockCMDListener = mocks.Stub<WorkInfoController>(paramList);
            WorkInfoSelectCommand selectCommand = new WorkInfoSelectCommand(mockCMDListener);
            object returnValue = new object();
            using (mocks.Record())
            {
                selectCommand.execute(out returnValue);
            }
            mocks.Verify(mockCMDListener);
        }
Beispiel #10
0
        public void SetPermissionForPage_User_Grant()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.StoreEntry(Actions.ForPages.ResourceMasterPrefix + "Page",
                Actions.ForPages.ModifyPage, "U.User", Value.Grant)).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            Assert.IsTrue(AuthWriter.SetPermissionForPage(AuthStatus.Grant, new PageInfo("Page", null, DateTime.Now),
                Actions.ForPages.ModifyPage, new UserInfo("User", "User", "*****@*****.**", true, DateTime.Now, null)),
                "SetPermissionForPage should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
Beispiel #11
0
        public void ProcessDirectoryRenaming()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IFilesStorageProviderV30 filesProv = MockFilesProvider();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.RenameResource(
                Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(filesProv, "/Dir/"),
                Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(filesProv, "/Dir2/"))).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            Assert.IsTrue(AuthWriter.ProcessDirectoryRenaming(filesProv, "/Dir/", "/Dir2/"), "ProcessDirectoryRenaming should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
Beispiel #12
0
        public void RetrieveSubjectsForDirectory_Root()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IFilesStorageProviderV30 filesProv = mocks.DynamicMock<IFilesStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            string dirName = Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(filesProv, "/");
            Expect.Call(aclManager.RetrieveEntriesForResource(dirName)).Return(
                new AclEntry[] {
                    new AclEntry(dirName, Actions.ForDirectories.List, "U.User1", Value.Grant),
                    new AclEntry(dirName, Actions.ForDirectories.UploadFiles, "U.User", Value.Grant),
                    new AclEntry(dirName, Actions.ForDirectories.DownloadFiles, "G.Group", Value.Grant),
                    new AclEntry(dirName, Actions.ForDirectories.CreateDirectories, "U.User", Value.Deny) });

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;

            SubjectInfo[] infos = AuthReader.RetrieveSubjectsForDirectory(filesProv, "/");

            Assert.AreEqual(3, infos.Length, "Wrong info count");

            Array.Sort(infos, delegate(SubjectInfo x, SubjectInfo y) { return x.Name.CompareTo(y.Name); });
            Assert.AreEqual("Group", infos[0].Name, "Wrong subject name");
            Assert.AreEqual(SubjectType.Group, infos[0].Type, "Wrong subject type");
            Assert.AreEqual("User", infos[1].Name, "Wrong subject name");
            Assert.AreEqual(SubjectType.User, infos[1].Type, "Wrong subject type");
            Assert.AreEqual("User1", infos[2].Name, "Wrong subject name");
            Assert.AreEqual(SubjectType.User, infos[2].Type, "Wrong subject type");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
Beispiel #13
0
 public void execute_Test_정상적인_값을_파라미터로_주고_정상적으로_입력되는지()
 {
     MockRepository mocks = new MockRepository();
     UserInfo data= mocks.Stub<UserInfo>();
     ICommandListener mockCommandListener= mocks.DynamicMock<UserAuthController>();
     MakeAuth MakeUserCommand = new MakeAuth(data, mockCommandListener);
     using (mocks.Record())
     {
         data.id = "id";
         data.password = "******";
         data.userAuth = "userAuth";
         data.userType = 사용자등급.일반사용자;
         mockCommandListener.Insert(data);
         LastCall.Return(true);
     }
     MakeUserCommand.execute();
     mocks.Verify(mockCommandListener);
 }
Beispiel #14
0
        public void SetPermissionForDirectory_User_Grant()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IFilesStorageProviderV30 filesProv = mocks.DynamicMock<IFilesStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.StoreEntry(
                Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(filesProv, "/"),
                Actions.ForDirectories.DownloadFiles, "U.User", Value.Grant)).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            Assert.IsTrue(AuthWriter.SetPermissionForDirectory(AuthStatus.Grant, filesProv, "/", Actions.ForDirectories.DownloadFiles,
                new UserInfo("User", "User", "*****@*****.**", true, DateTime.Now, null)),
                "SetPermissionForDirectory should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
Beispiel #15
0
        public void RemoveEntriesForPage_User()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.RetrieveEntriesForSubject("U.User")).Return(
                new AclEntry[] {
                    new AclEntry(Actions.ForPages.ResourceMasterPrefix + "Page", Actions.ForPages.ManagePage, "U.User", Value.Grant),
                    new AclEntry(Actions.ForPages.ResourceMasterPrefix + "Page", Actions.ForPages.ManageCategories, "U.User", Value.Deny),
                    new AclEntry(Actions.ForPages.ResourceMasterPrefix + "Sub.Page", Actions.ForPages.ManagePage, "U.User", Value.Grant),
                    new AclEntry(Actions.ForGlobals.ResourceMasterPrefix, Actions.ForGlobals.ManageNavigationPaths, "U.User", Value.Grant) });

            Expect.Call(aclManager.DeleteEntry(Actions.ForPages.ResourceMasterPrefix + "Page",
                Actions.ForPages.ManagePage, "U.User")).Return(true);
            Expect.Call(aclManager.DeleteEntry(Actions.ForPages.ResourceMasterPrefix + "Page",
                Actions.ForPages.ManageCategories, "U.User")).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;

            Assert.IsTrue(AuthWriter.RemoveEntriesForPage(new UserInfo("User", "User", "*****@*****.**", true, DateTime.Now, null),
                new PageInfo("Page", null, DateTime.Now)), "RemoveEntriesForPage should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
Beispiel #16
0
        public void RemoveEntriesForNamespace_Group_Sub()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.RetrieveEntriesForSubject("G.Group")).Return(
                new AclEntry[] {
                    new AclEntry(Actions.ForNamespaces.ResourceMasterPrefix + "Sub", Actions.ForNamespaces.ManagePages, "G.Group", Value.Grant),
                    new AclEntry(Actions.ForNamespaces.ResourceMasterPrefix + "Sub", Actions.ForNamespaces.ManageCategories, "G.Group", Value.Grant),
                    new AclEntry(Actions.ForNamespaces.ResourceMasterPrefix, Actions.ForNamespaces.ModifyPages, "G.Group", Value.Grant),
                    new AclEntry(Actions.ForGlobals.ResourceMasterPrefix, Actions.ForGlobals.ManageNavigationPaths, "G.Group", Value.Grant) });

            Expect.Call(aclManager.DeleteEntry(Actions.ForNamespaces.ResourceMasterPrefix + "Sub",
                Actions.ForNamespaces.ManagePages, "G.Group")).Return(true);
            Expect.Call(aclManager.DeleteEntry(Actions.ForNamespaces.ResourceMasterPrefix + "Sub",
                Actions.ForNamespaces.ManageCategories, "G.Group")).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;

            Assert.IsTrue(AuthWriter.RemoveEntriesForNamespace(new UserGroup("Group", "Group", null), new NamespaceInfo("Sub", null, null)), "RemoveEntriesForNamespace should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
        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);
        }
Beispiel #18
0
        public void ProcessNamespaceRenaming()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.RenameResource(Actions.ForNamespaces.ResourceMasterPrefix + "NS", Actions.ForNamespaces.ResourceMasterPrefix + "NS_Renamed")).Return(true);
            Expect.Call(aclManager.RenameResource(Actions.ForPages.ResourceMasterPrefix + "NS.Page1", Actions.ForPages.ResourceMasterPrefix + "NS_Renamed.Page1")).Return(true);
            Expect.Call(aclManager.RenameResource(Actions.ForPages.ResourceMasterPrefix + "NS.Page2", Actions.ForPages.ResourceMasterPrefix + "NS_Renamed.Page2")).Return(true);
            Expect.Call(aclManager.RenameResource(Actions.ForPages.ResourceMasterPrefix + "NS.Page3", Actions.ForPages.ResourceMasterPrefix + "NS_Renamed.Page3")).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            Assert.IsTrue(AuthWriter.ProcessNamespaceRenaming("NS", new List<string>() { "Page1", "Page2", "Page3" }, "NS_Renamed"));

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
Beispiel #19
0
        public void ProcessPageRenaming()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.RenameResource(Actions.ForPages.ResourceMasterPrefix + "NS.Page", Actions.ForPages.ResourceMasterPrefix + "NS.Renamed")).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            Assert.IsTrue(AuthWriter.ProcessPageRenaming("NS.Page", "NS.Renamed"), "ProcessPageRenaming should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
        public void Select_Test_파라미터가_없는_Select메서드_테스트()
        {
            MockRepository mocks = new MockRepository();
            //[1] IDataModel 파라미터 구성
            SQLDataServiceModel mockDataModel = mocks.DynamicMock<SQLDataServiceModel>();
            ISQLWebService stubSQLWebService = mocks.Stub<ISQLWebService>(mocks.Stub<InstanceContext>());
            mockDataModel.EncryptionSeed = "1234";
            mockDataModel.sqlService = stubSQLWebService;

            //[2] IDataQueryRepository 파라미터 구성
            IDataQueryRepository stubQueryReposit = mocks.Stub<SQLDataQueryRepository>();

            //[3] stub과 mock객체 사용해서 테스트 하고자 하는 객체 생성
            UserAuthController uac = new UserAuthController(mockDataModel, stubQueryReposit);
            using (mocks.Record())
            {
                string query = stubQueryReposit.SelectUserAuth();
                mockDataModel.GetData(query);
            }
            uac.Select();
            mocks.Verify(mockDataModel);
        }
Beispiel #21
0
        public void RemoveEntriesForDirectory_Sub_User()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IFilesStorageProviderV30 filesProv = mocks.DynamicMock<IFilesStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            string dirName = Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(filesProv, "/Dir/Sub/");
            Expect.Call(aclManager.RetrieveEntriesForSubject("U.User")).Return(
                new AclEntry[] {
                    new AclEntry(dirName, Actions.ForDirectories.List, "U.User", Value.Grant),
                    new AclEntry(dirName, Actions.ForDirectories.UploadFiles, "U.User", Value.Deny),
                    new AclEntry("D." + AuthTools.GetDirectoryName(filesProv, "/"), Actions.ForDirectories.UploadFiles, "U.User", Value.Grant),
                    new AclEntry(Actions.ForGlobals.ResourceMasterPrefix, Actions.ForGlobals.ManageNavigationPaths, "U.User", Value.Grant) });

            Expect.Call(aclManager.DeleteEntry(dirName, Actions.ForDirectories.List, "U.User")).Return(true);
            Expect.Call(aclManager.DeleteEntry(dirName, Actions.ForDirectories.UploadFiles, "U.User")).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;

            Assert.IsTrue(AuthWriter.RemoveEntriesForDirectory(new UserInfo("User", "User", "*****@*****.**", true, DateTime.Now, null),
                filesProv, "/Dir/Sub/"), "RemoveEntriesForPage should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
        public void TestProperties_UsingMock()
        {
            var repository = new MockRepository();
            var mock = repository.DynamicMock<IBasicProperties>();

            Expect.Call(mock.GetSetProperty).Return("one");
            Expect.Call(mock.GetOnlyProperty).Return("anyoldthing");
            mock.SetOnlyProperty = "two";

            repository.Replay(mock);

            var typeFactory = new CustomStringTypeFactory();
            typeFactory.ReturnValues.Enqueue("one");
            typeFactory.ReturnValues.Enqueue("two");

            var tester = new PropertyTester(mock, typeFactory);
            tester.IgnoredProperties.Add("ConstructorArguments");
            tester.TestProperties();
            repository.Verify(mock);
        }
Beispiel #23
0
        public void ClearEntriesForNamespace()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.DeleteEntriesForResource(Actions.ForNamespaces.ResourceMasterPrefix + "NS")).Return(true);
            Expect.Call(aclManager.DeleteEntriesForResource(Actions.ForPages.ResourceMasterPrefix + "NS.Page1")).Return(true);
            Expect.Call(aclManager.DeleteEntriesForResource(Actions.ForPages.ResourceMasterPrefix + "NS.Page2")).Return(true);
            Expect.Call(aclManager.DeleteEntriesForResource(Actions.ForPages.ResourceMasterPrefix + "NS.Page3")).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            AuthWriter.ClearEntriesForNamespace("NS", new List<string>() { "Page1", "Page2", "Page3" });

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
Beispiel #24
0
        public void SetPermissionForGlobals_Group_Delete()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.DeleteEntry(Actions.ForGlobals.ResourceMasterPrefix,
                Actions.ForGlobals.ManageMetaFiles, "G.Group")).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            Assert.IsTrue(AuthWriter.SetPermissionForGlobals(AuthStatus.Delete, Actions.ForGlobals.ManageMetaFiles,
                new UserGroup("Group", "Descr", null)), "SetPermissionForGlobals should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
Beispiel #25
0
        public void SetPermissionForDirectory_Group_Deny()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IFilesStorageProviderV30 filesProv = mocks.DynamicMock<IFilesStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.StoreEntry(
                Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(filesProv, "/"),
                Actions.ForDirectories.CreateDirectories, "G.Group", Value.Deny)).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            Assert.IsTrue(AuthWriter.SetPermissionForDirectory(AuthStatus.Deny, filesProv, "/", Actions.ForDirectories.CreateDirectories,
                new UserGroup("Group", "Group", null)), "SetPermissionForDirectory should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
Beispiel #26
0
        public void SetPermissionForNamespace_Group_Grant()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.StoreEntry(Actions.ForNamespaces.ResourceMasterPrefix,
                Actions.ForNamespaces.CreatePages, "G.Group", Value.Grant)).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            Assert.IsTrue(AuthWriter.SetPermissionForNamespace(AuthStatus.Grant, null,
                Actions.ForNamespaces.CreatePages, new UserGroup("Group", "Descr", null)),
                "SetPermissionForNamespace should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
        public void Init_Upgrade()
        {
            string testDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString());
            Directory.CreateDirectory(testDir);

            MockRepository mocks = new MockRepository();
            IHostV30 host = mocks.DynamicMock<IHostV30>();
            Expect.Call(host.GetSettingValue(SettingName.PublicDirectory)).Return(testDir).Repeat.AtLeastOnce();

            Expect.Call(host.UpgradePageStatusToAcl(null, 'L')).IgnoreArguments().Repeat.Twice().Return(true);

            mocks.Replay(host);

            string file = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "Pages.cs");
            string categoriesFile = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "Categories.cs");
            string navPathsFile = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "NavigationPaths.cs");
            string directory = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "Pages");
            string messagesDirectory = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), "Messages");
            Directory.CreateDirectory(directory);
            Directory.CreateDirectory(messagesDirectory);

            // Structure (Keywords and Description are new in v3)
            // Page Title
            // Username|DateTime[|Comment] --- Comment is optional
            // ##PAGE##
            // Content...

            File.WriteAllText(Path.Combine(directory, "Page1.cs"), "Title1\r\nSYSTEM|2008/10/30 20:20:20|Comment\r\n##PAGE##\r\nContent...");
            File.WriteAllText(Path.Combine(directory, "Page2.cs"), "Title2\r\nSYSTEM|2008/10/30 20:20:20\r\n##PAGE\r\nContent. [[Page.3]] [Page.3|Link to update].");
            File.WriteAllText(Path.Combine(directory, "Page.3.cs"), "Title3\r\nSYSTEM|2008/10/30 20:20:20|Comment\r\n##PAGE\r\nContent...");

            // ID|Username|Subject|DateTime|ParentID|Body
            File.WriteAllText(Path.Combine(messagesDirectory, "Page.3.cs"), "0|User|Hello|2008/10/30 21:21:21|-1|Blah\r\n");

            // Structure
            // [Namespace.]PageName|PageFile|Status|DateTime
            File.WriteAllText(file, "Page1|Page1.cs|NORMAL|2008/10/30 20:20:20\r\nPage2|Page2.cs|PUBLIC\r\nPage.3|Page.3.cs|LOCKED");

            File.WriteAllText(categoriesFile, "Cat1|Page.3\r\nCat.2|Page1|Page2\r\n");

            File.WriteAllText(navPathsFile, "Path1|Page1|Page.3\r\nPath2|Page2\r\n");

            PagesStorageProvider prov = new PagesStorageProvider();
            prov.Init(host, "");

            PageInfo[] pages = prov.GetPages(null);

            Assert.AreEqual(3, pages.Length, "Wrong page count");
            Assert.AreEqual("Page1", pages[0].FullName, "Wrong name");
            Assert.AreEqual("Page2", pages[1].FullName, "Wrong name");
            Assert.AreEqual("Page_3", pages[2].FullName, "Wrong name");
            //Assert.IsFalse(prov.GetContent(pages[1]).Content.Contains("Page.3"), "Content should not contain 'Page.3'");
            //Assert.IsTrue(prov.GetContent(pages[1]).Content.Contains("Page_3"), "Content should contain 'Page_3'");

            Message[] messages = prov.GetMessages(pages[2]);
            Assert.AreEqual(1, messages.Length, "Wrong message count");
            Assert.AreEqual("Hello", messages[0].Subject, "Wrong subject");

            CategoryInfo[] categories = prov.GetCategories(null);

            Assert.AreEqual(2, categories.Length, "Wrong category count");
            Assert.AreEqual("Cat1", categories[0].FullName, "Wrong name");
            Assert.AreEqual(1, categories[0].Pages.Length, "Wrong page count");
            Assert.AreEqual("Page_3", categories[0].Pages[0], "Wrong page");
            Assert.AreEqual("Cat_2", categories[1].FullName, "Wrong name");
            Assert.AreEqual(2, categories[1].Pages.Length, "Wrong page count");
            Assert.AreEqual("Page1", categories[1].Pages[0], "Wrong page");
            Assert.AreEqual("Page2", categories[1].Pages[1], "Wrong page");

            NavigationPath[] navPaths = prov.GetNavigationPaths(null);

            Assert.AreEqual(2, navPaths.Length, "Wrong nav path count");
            Assert.AreEqual("Path1", navPaths[0].FullName, "Wrong name");
            Assert.AreEqual(2, navPaths[0].Pages.Length, "Wrong page count");
            Assert.AreEqual("Page1", navPaths[0].Pages[0], "Wrong page");
            Assert.AreEqual("Page_3", navPaths[0].Pages[1], "Wrong page");
            Assert.AreEqual(1, navPaths[1].Pages.Length, "Wrong page count");
            Assert.AreEqual("Page2", navPaths[1].Pages[0], "Wrong page");

            mocks.Verify(host);

            // Simulate another startup - upgrade not needed anymore

            mocks.BackToRecord(host);
            Expect.Call(host.GetSettingValue(SettingName.PublicDirectory)).Return(testDir).Repeat.AtLeastOnce();
            Expect.Call(host.UpgradePageStatusToAcl(null, 'L')).IgnoreArguments().Repeat.Times(0).Return(false);

            mocks.Replay(host);

            prov = new PagesStorageProvider();
            prov.Init(host, "");

            mocks.Verify(host);

            Directory.Delete(testDir, true);
        }
Beispiel #28
0
        public void SetPermissionForNamespace_User_Delete()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.DeleteEntry(Actions.ForNamespaces.ResourceMasterPrefix + "NS",
                Actions.ForNamespaces.ReadPages, "U.User")).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            Assert.IsTrue(AuthWriter.SetPermissionForNamespace(AuthStatus.Delete, new NamespaceInfo("NS", null, null),
                Actions.ForNamespaces.ReadPages, new UserInfo("User", "User", "*****@*****.**", true, DateTime.Now, null)),
                "SetPermissionForNamespace should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }
Beispiel #29
0
 public void Undo_Test_입력했던_파라미터_기록이_남아있는_경우()
 {
     MockRepository mocks = new MockRepository();
     UserInfo data = mocks.Stub<UserInfo>();
              data.id = "id";
              data.password = "******";
              data.userAuth = "userAuth";
     ICommandListener mockCommandListener = mocks.DynamicMock<UserAuthController>();
     MakeAuth MakeUserCommand = new MakeAuth(data, mockCommandListener);
     using (mocks.Record())
     {
         mockCommandListener.Delete(data);
     }
     MakeUserCommand.Undo();
     mocks.Verify(mockCommandListener);
 }
Beispiel #30
0
        public void SetPermissionForPage_Group_Deny()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            Expect.Call(aclManager.StoreEntry(Actions.ForPages.ResourceMasterPrefix + "Page",
                Actions.ForPages.ManageCategories, "G.Group", Value.Deny)).Return(true);

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;
            Assert.IsTrue(AuthWriter.SetPermissionForPage(AuthStatus.Deny, new PageInfo("Page", null, DateTime.Now),
                Actions.ForPages.ManageCategories, new UserGroup("Group", "Group", null)), "SetPermissionForPage should return true");

            mocks.Verify(prov);
            mocks.Verify(aclManager);
        }