Example #1
0
        public void Delete_LoadData()
        {
            IAclManager manager = MockAclManager();

            AclStorer storer = new AclStorer(manager, testFile);

            manager.StoreEntry("Res1", "Action1", "U.User", Value.Grant);
            manager.StoreEntry("Res2", "Action2", "G.Group", Value.Deny);
            manager.StoreEntry("Res3", "Action1", "U.User", Value.Grant);
            manager.StoreEntry("Res3", "Action2", "G.Group", Value.Deny);

            manager.DeleteEntriesForResource("Res3");

            storer.Dispose();
            storer = null;

            manager = MockAclManager();

            storer = new AclStorer(manager, testFile);
            storer.LoadData();

            Assert.AreEqual(2, manager.TotalEntries, "Wrong entry count");

            AclEntry[] allEntries = manager.RetrieveAllEntries();
            Assert.AreEqual(2, allEntries.Length, "Wrong entry count");

            Array.Sort(allEntries, delegate(AclEntry x, AclEntry y) { return(x.Subject.CompareTo(y.Subject)); });
            AssertAclEntriesAreEqual(new AclEntry("Res2", "Action2", "G.Group", Value.Deny), allEntries[0]);
            AssertAclEntriesAreEqual(new AclEntry("Res1", "Action1", "U.User", Value.Grant), allEntries[1]);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AclService"/>
 /// </summary>
 /// <param name="manager">A <see cref="IAclManager"/> for the policies (default: in memory)</param>
 public AclService(IAclManager manager = null)
 {
     if (manager == null)
     {
         manager = new InMemoryManager();
     }
     Manager = manager;
 }
Example #3
0
        public void Constructor()
        {
            IAclManager manager = MockAclManager();

            AclStorer storer = new AclStorer(manager, testFile);

            Assert.AreSame(manager, storer.AclManager, "Wrong ACL Manager instance");
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:AclStorer" /> class.
        /// </summary>
        /// <param name="aclManager">The instance of the ACL Manager to handle.</param>
        /// <param name="file">The storage file.</param>
        public AclStorer(IAclManager aclManager, string file)
            : base(aclManager)
        {
            if(file == null) throw new ArgumentNullException("file");
            if(file.Length == 0) throw new ArgumentException("File cannot be empty", "file");

            this.file = file;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:AclStorerBase" /> abstract class.
        /// </summary>
        /// <param name="aclManager">The instance of the ACL Manager to handle.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="aclManager"/> is <c>null</c>.</exception>
        public AclStorerBase(IAclManager aclManager)
        {
            _aclManager = aclManager ?? throw new ArgumentNullException("aclManager");

            aclChangedHandler = new EventHandler <AclChangedEventArgs>(aclManager_AclChanged);

            _aclManager.AclChanged += aclChangedHandler;
        }
Example #6
0
        public async Task DeletePolicy_DeleteTestPolicy_ReturnsTrue()
        {
            Manager = await GetManagerAsync();

            var policy = await Manager.AddPolicyAsync(TestData.PolicyCreationRequest);

            PoliciesToDelete.Add(policy);
            Assert.IsTrue(await Manager.DeletePolicyAsync(policy.Id));
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:AclStorerBase" /> abstract class.
        /// </summary>
        /// <param name="aclManager">The instance of the ACL Manager to handle.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="aclManager"/> is <c>null</c>.</exception>
        public AclStorerBase(IAclManager aclManager)
        {
            if(aclManager == null) throw new ArgumentNullException("aclManager");

            this.aclManager = aclManager;

            aclChangedHandler = new EventHandler<AclChangedEventArgs>(aclManager_AclChanged);

            this.aclManager.AclChanged += aclChangedHandler;
        }
Example #8
0
        public async Task AddPolicy_AddTestPolicy_ReturnsCorrectPolicy()
        {
            Manager = await GetManagerAsync();

            var policy = await Manager.AddPolicyAsync(TestData.PolicyCreationRequest);

            PoliciesToDelete.Add(policy);
            AssertPolicyCreationRequestsAreEqual(TestData.PolicyCreationRequest, policy);
            Assert.IsTrue(Guid.TryParse(policy.Id, out var guid));
        }
Example #9
0
        public async Task AddPolicy_AddTestPolicy_Succeeds()
        {
            Manager = await GetManagerAsync();

            var policy = await Manager.AddPolicyAsync(TestData.PolicyCreationRequest);

            PoliciesToDelete.Add(policy);
            var result = await Manager.GetPolicyByIdAsync(policy.Id);

            AssertPoliciesAreEqual(policy, result);
        }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:AclStorerBase" /> abstract class.
        /// </summary>
        /// <param name="aclManager">The instance of the ACL Manager to handle.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="aclManager"/> is <c>null</c>.</exception>
        protected AclStorerBase(IAclManager aclManager)
        {
            if (aclManager == null)
            {
                throw new ArgumentNullException("aclManager");
            }

            this.aclManager = aclManager;

            AclChangedHandler = aclManager_AclChanged;

            this.aclManager.AclChanged += AclChangedHandler;
        }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:AclStorerBase" /> abstract class.
        /// </summary>
        /// <param name="aclManager">The instance of the ACL Manager to handle.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="aclManager"/> is <c>null</c>.</exception>
        public AclStorerBase(IAclManager aclManager)
        {
            if (aclManager == null)
            {
                throw new ArgumentNullException("aclManager");
            }

            this.aclManager = aclManager;

            aclChangedHandler = new EventHandler <AclChangedEventArgs>(aclManager_AclChanged);

            this.aclManager.AclChanged += aclChangedHandler;
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:AclStorer" /> class.
        /// </summary>
        /// <param name="aclManager">The instance of the ACL Manager to handle.</param>
        /// <param name="file">The storage file.</param>
        public AclStorer(IAclManager aclManager, string file)
            : base(aclManager)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (file.Length == 0)
            {
                throw new ArgumentException("File cannot be empty", "file");
            }

            _file = file;
        }
Example #13
0
        public async Task GetAllPolicies_GetFullList_ReturnsCompleteList()
        {
            Manager = await GetManagerAsync();

            foreach (var pcr in TestData.PolicyCreationRequests)
            {
                var policy = await Manager.AddPolicyAsync(pcr);

                PoliciesToDelete.Add(policy);
            }
            var policies = await Manager.GetAllPoliciesAsync();

            Assert.AreEqual(TestData.PolicyCreationRequests.Count, policies.Count);
        }
Example #14
0
        public async Task UpdatePolicy_UpdateTestPolicy_ReturnsUpdatedPolicy()
        {
            Manager = await GetManagerAsync();

            var policy = await Manager.AddPolicyAsync(TestData.PolicyCreationRequest);

            PoliciesToDelete.Add(policy);
            var updatePolicy = new Policy(TestData.UpdatePolicyCreationRequest)
            {
                Id = policy.Id
            };
            var updatedPolicy = await Manager.UpdatePolicyAsync(updatePolicy);

            AssertPoliciesAreEqual(updatePolicy, updatedPolicy);
        }
Example #15
0
        public async Task UpdatePolicy_UpdateTestPolicy_Succeeds()
        {
            Manager = await GetManagerAsync();

            var policy = await Manager.AddPolicyAsync(TestData.PolicyCreationRequest);

            PoliciesToDelete.Add(policy);
            var updatePolicy = new Policy(TestData.UpdatePolicyCreationRequest)
            {
                Id = policy.Id
            };
            var updatedPolicy = await Manager.UpdatePolicyAsync(updatePolicy);

            var result = await Manager.GetPolicyByIdAsync(policy.Id);

            AssertPoliciesAreEqual(updatePolicy, result);
        }
        /// <summary>
        /// Initializes the Storage Provider.
        /// </summary>
        /// <param name="host">The Host of the Component.</param>
        /// <param name="config">The Configuration data, if any.</param>
        /// <param name="wiki">The wiki.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="host"/> or <paramref name="config"/> are <c>null</c>.</exception>
        /// <exception cref="InvalidConfigurationException">If <paramref name="config"/> is not valid or is incorrect.</exception>
        public void Init(IHostV40 host, string config, string wiki)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (config == "")
            {
                config = Config.GetConnectionString();
            }

            _host = host;
            _wiki = string.IsNullOrEmpty(wiki) ? "root" : wiki.ToLowerInvariant();

            _context = TableStorage.GetContext(config);

            _aclManager = new AzureTableStorageAclManager(StoreEntry, DeleteEntries, RenameAclResource, RetrieveAllAclEntries, RetrieveAclEntriesForResource, RetrieveAclEntriesForSubject);
        }
        /// <summary>
        /// Initializes the Storage Provider.
        /// </summary>
        /// <param name="host">The Host of the Component.</param>
        /// <param name="config">The Configuration data, if any.</param>
        /// <exception cref="ArgumentNullException">If <b>host</b> or <b>config</b> are <c>null</c>.</exception>
        /// <exception cref="InvalidConfigurationException">If <b>config</b> is not valid or is incorrect.</exception>
        public void Init(IHostV30 host, string config)
        {
            if(host == null) throw new ArgumentNullException("host");
            if(config == null) throw new ArgumentNullException("config");

            this.host = host;

            if(!LocalProvidersTools.CheckWritePermissions(host.GetSettingValue(SettingName.PublicDirectory))) {
                throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
            }

            // Create all needed pluginAssemblies
            if(!File.Exists(GetFullPath(LogFile))) {
                File.Create(GetFullPath(LogFile)).Close();
            }

            if(!File.Exists(GetFullPath(ConfigFile))) {
                File.Create(GetFullPath(ConfigFile)).Close();
                isFirstStart = true;
            }

            if(!File.Exists(GetFullPath(RecentChangesFile))) {
                File.Create(GetFullPath(RecentChangesFile)).Close();
            }

            if(!File.Exists(GetFullPath(HtmlHeadFile))) {
                File.Create(GetFullPath(HtmlHeadFile)).Close();
            }

            if(!File.Exists(GetFullPath(HeaderFile))) {
                File.Create(GetFullPath(HeaderFile)).Close();
            }

            if(!File.Exists(GetFullPath(SidebarFile))) {
                File.Create(GetFullPath(SidebarFile)).Close();
            }

            if(!File.Exists(GetFullPath(FooterFile))) {
                File.Create(GetFullPath(FooterFile)).Close();
            }

            if(!File.Exists(GetFullPath(PageHeaderFile))) {
                File.Create(GetFullPath(PageHeaderFile)).Close();
            }

            if(!File.Exists(GetFullPath(PageFooterFile))) {
                File.Create(GetFullPath(PageFooterFile)).Close();
            }

            if(!File.Exists(GetFullPath(AccountActivationMessageFile))) {
                File.Create(GetFullPath(AccountActivationMessageFile)).Close();
            }

            if(!File.Exists(GetFullPath(PasswordResetProcedureMessageFile))) {
                File.Create(GetFullPath(PasswordResetProcedureMessageFile)).Close();
            }

            if(!File.Exists(GetFullPath(EditNoticeFile))) {
                File.Create(GetFullPath(EditNoticeFile)).Close();
            }

            if(!File.Exists(GetFullPath(LoginNoticeFile))) {
                File.Create(GetFullPath(LoginNoticeFile)).Close();
            }

            if(!File.Exists(GetFullPath(AccessDeniedNoticeFile))) {
                File.Create(GetFullPath(AccessDeniedNoticeFile)).Close();
            }

            if(!File.Exists(GetFullPath(RegisterNoticeFile))) {
                File.Create(GetFullPath(RegisterNoticeFile)).Close();
            }

            if(!File.Exists(GetFullPath(PageChangeMessageFile))) {
                File.Create(GetFullPath(PageChangeMessageFile)).Close();
            }

            if(!File.Exists(GetFullPath(DiscussionChangeMessageFile))) {
                File.Create(GetFullPath(DiscussionChangeMessageFile)).Close();
            }

            if(!File.Exists(GetFullPath(ApproveDraftMessageFile))) {
                File.Create(GetFullPath(ApproveDraftMessageFile)).Close();
            }

            if(!Directory.Exists(GetFullPath(PluginsDirectory))) {
                Directory.CreateDirectory(GetFullPath(PluginsDirectory));
            }

            if(!Directory.Exists(GetFullPathForPlugin(PluginsConfigDirectory))) {
                Directory.CreateDirectory(GetFullPathForPlugin(PluginsConfigDirectory));
            }

            if(!File.Exists(GetFullPathForPlugin(PluginsStatusFile))) {
                File.Create(GetFullPathForPlugin(PluginsStatusFile)).Close();
            }

            if(!File.Exists(GetFullPath(LinksFile))) {
                File.Create(GetFullPath(LinksFile)).Close();
            }

            LoadConfig();

            // Initialize ACL Manager and Storer
            aclManager = new StandardAclManager();
            aclStorer = new AclStorer(aclManager, GetFullPath(AclFile));
            aclStorer.LoadData();
        }
Example #18
0
        private IAclManager MockAclManager()
        {
            IAclManager manager = mocks.DynamicMock <AclManagerBase>();

            return(manager);
        }
		/// <summary>
		/// Initializes the Storage Provider.
		/// </summary>
		/// <param name="host">The Host of the Component.</param>
		/// <param name="config">The Configuration data, if any.</param>
		/// <remarks>If the configuration string is not valid, the methoud should throw a <see cref="InvalidConfigurationException"/>.</remarks>
		public new void Init(IHostV30 host, string config) {
			base.Init(host, config);

			aclManager = new OracleAclManager(StoreEntry, DeleteEntries, RenameAclResource, RetrieveAllAclEntries, RetrieveAclEntriesForResource, RetrieveAclEntriesForSubject);
		}
Example #20
0
        public void CopySettingsStorageProviderData()
        {
            MockRepository mocks = new MockRepository();

            ISettingsStorageProviderV30 source      = mocks.StrictMock <ISettingsStorageProviderV30>();
            ISettingsStorageProviderV30 destination = mocks.StrictMock <ISettingsStorageProviderV30>();
            IAclManager sourceAclManager            = mocks.StrictMock <IAclManager>();
            IAclManager destinationAclManager       = mocks.StrictMock <IAclManager>();

            // Setup SOURCE ---------------------

            // Settings
            Dictionary <string, string> settings = new Dictionary <string, string>()
            {
                { "Set1", "Value1" },
                { "Set2", "Value2" }
            };

            Expect.Call(source.GetAllSettings()).Return(settings);

            // Meta-data (global)
            Expect.Call(source.GetMetaDataItem(MetaDataItem.AccountActivationMessage, null)).Return("AAM");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null)).Return("PRM");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.LoginNotice, null)).Return("");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageChangeMessage, null)).Return("PCM");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null)).Return("DCM");

            // Meta-data (root)
            Expect.Call(source.GetMetaDataItem(MetaDataItem.EditNotice, null)).Return("");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Footer, null)).Return("FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Header, null)).Return("HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.HtmlHead, null)).Return("HTML");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageFooter, null)).Return("P_FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageHeader, null)).Return("P_HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Sidebar, null)).Return("SIDEBAR");

            // Meta-data ("NS" namespace)
            Expect.Call(source.GetMetaDataItem(MetaDataItem.EditNotice, "NS")).Return("NS_EDIT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Footer, "NS")).Return("NS_FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Header, "NS")).Return("NS_HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.HtmlHead, "NS")).Return("NS_HTML");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageFooter, "NS")).Return("NS_P_FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageHeader, "NS")).Return("NS_P_HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Sidebar, "NS")).Return("NS_SIDEBAR");

            // Plugin assemblies
            byte[] asm1 = new byte[] { 1, 2, 3, 4, 5 };
            byte[] asm2 = new byte[] { 6, 7, 8, 9, 10, 11, 12 };
            Expect.Call(source.ListPluginAssemblies()).Return(new string[] { "Plugins1.dll", "Plugins2.dll" });
            Expect.Call(source.RetrievePluginAssembly("Plugins1.dll")).Return(asm1);
            Expect.Call(source.RetrievePluginAssembly("Plugins2.dll")).Return(asm2);

            // Plugin status
            Expect.Call(source.GetPluginStatus("Test1.Plugin1")).Return(true);
            Expect.Call(source.GetPluginStatus("Test2.Plugin2")).Return(false);

            // Plugin config
            Expect.Call(source.GetPluginConfiguration("Test1.Plugin1")).Return("Config1");
            Expect.Call(source.GetPluginConfiguration("Test2.Plugin2")).Return("");

            // Outgoing links
            Dictionary <string, string[]> outgoingLinks = new Dictionary <string, string[]>()
            {
                { "Page1", new string[] { "Page2", "Page3" } },
                { "Page2", new string[] { "Page3" } },
                { "Page3", new string[] { "Page4", "Page3" } }
            };

            Expect.Call(source.GetAllOutgoingLinks()).Return(outgoingLinks);

            // ACLs
            Expect.Call(source.AclManager).Return(sourceAclManager);
            AclEntry[] entries = new AclEntry[] {
                new AclEntry("Res1", "Act1", "Subj1", Value.Grant),
                new AclEntry("Res2", "Act2", "Subj2", Value.Deny)
            };
            Expect.Call(sourceAclManager.RetrieveAllEntries()).Return(entries);

            // Setup DESTINATION -----------------

            // Settings
            destination.BeginBulkUpdate();
            LastCall.On(destination).Repeat.Once();
            foreach (KeyValuePair <string, string> pair in settings)
            {
                Expect.Call(destination.SetSetting(pair.Key, pair.Value)).Return(true);
            }
            destination.EndBulkUpdate();
            LastCall.On(destination).Repeat.Once();

            // Meta-data (global)
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.AccountActivationMessage, null, "AAM")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null, "PRM")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.LoginNotice, null, "")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageChangeMessage, null, "PCM")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null, "DCM")).Return(true);

            // Meta-data (root)
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.EditNotice, null, "")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Footer, null, "FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Header, null, "HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.HtmlHead, null, "HTML")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageFooter, null, "P_FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageHeader, null, "P_HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Sidebar, null, "SIDEBAR")).Return(true);

            // Meta-data ("NS" namespace)
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.EditNotice, "NS", "NS_EDIT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Footer, "NS", "NS_FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Header, "NS", "NS_HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.HtmlHead, "NS", "NS_HTML")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageFooter, "NS", "NS_P_FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageHeader, "NS", "NS_P_HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Sidebar, "NS", "NS_SIDEBAR")).Return(true);

            // Plugin assemblies
            Expect.Call(destination.StorePluginAssembly("Plugins1.dll", asm1)).Return(true);
            Expect.Call(destination.StorePluginAssembly("Plugins2.dll", asm2)).Return(true);

            // Plugin status
            Expect.Call(destination.SetPluginStatus("Test1.Plugin1", true)).Return(true);
            Expect.Call(destination.SetPluginStatus("Test2.Plugin2", false)).Return(true);

            // Plugin config
            Expect.Call(destination.SetPluginConfiguration("Test1.Plugin1", "Config1")).Return(true);
            Expect.Call(destination.SetPluginConfiguration("Test2.Plugin2", "")).Return(true);

            // Outgoing links
            foreach (KeyValuePair <string, string[]> pair in outgoingLinks)
            {
                Expect.Call(destination.StoreOutgoingLinks(pair.Key, pair.Value)).Return(true);
            }

            // ACLs
            Expect.Call(destination.AclManager).Return(destinationAclManager).Repeat.Any();
            foreach (AclEntry e in entries)
            {
                Expect.Call(destinationAclManager.StoreEntry(e.Resource, e.Action, e.Subject, e.Value)).Return(true);
            }

            mocks.ReplayAll();

            DataMigrator.CopySettingsStorageProviderData(source, destination,
                                                         new string[] { "NS" }, new string[] { "Test1.Plugin1", "Test2.Plugin2" });

            mocks.VerifyAll();
        }
Example #21
0
        public void MigrateFilesStorageProviderData()
        {
            MockRepository mocks = new MockRepository();

            IFilesStorageProviderV30    source           = mocks.StrictMock <IFilesStorageProviderV30>();
            IFilesStorageProviderV30    destination      = mocks.StrictMock <IFilesStorageProviderV30>();
            ISettingsStorageProviderV30 settingsProvider = mocks.StrictMock <ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.StrictMock <IAclManager>();

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

            // Setup SOURCE -----------------

            // Directories
            Expect.Call(source.ListDirectories("/")).Return(new string[] { "/Dir1/", "/Dir2/" });
            Expect.Call(source.ListDirectories("/Dir1/")).Return(new string[] { "/Dir1/Sub/" });
            Expect.Call(source.ListDirectories("/Dir2/")).Return(new string[0]);
            Expect.Call(source.ListDirectories("/Dir1/Sub/")).Return(new string[0]);

            // Settings (permissions)
            Expect.Call(aclManager.RenameResource(
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(source, "/"),
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(destination, "/"))).Return(true);
            Expect.Call(aclManager.RenameResource(
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(source, "/Dir1/"),
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(destination, "/Dir1/"))).Return(true);
            Expect.Call(aclManager.RenameResource(
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(source, "/Dir2/"),
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(destination, "/Dir2/"))).Return(true);
            Expect.Call(aclManager.RenameResource(
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(source, "/Dir1/Sub/"),
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(destination, "/Dir1/Sub/"))).Return(true);

            // Filenames
            Expect.Call(source.ListFiles("/")).Return(new string[] { "/File1.txt", "/File2.txt" });
            Expect.Call(source.ListFiles("/Dir1/")).Return(new string[] { "/Dir1/File.txt" });
            Expect.Call(source.ListFiles("/Dir2/")).Return(new string[0]);
            Expect.Call(source.ListFiles("/Dir1/Sub/")).Return(new string[] { "/Dir1/Sub/File.txt" });

            // File content
            Expect.Call(source.RetrieveFile("/File1.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/File1.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveFile(
                    delegate(string file, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content1");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            Expect.Call(source.RetrieveFile("/File2.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/File2.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveFile(
                    delegate(string file, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content2");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            Expect.Call(source.RetrieveFile("/Dir1/File.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/Dir1/File.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveFile(
                    delegate(string file, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content3");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            Expect.Call(source.RetrieveFile("/Dir1/Sub/File.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/Dir1/Sub/File.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveFile(
                    delegate(string file, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content4");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            // File details
            Expect.Call(source.GetFileDetails("/File1.txt")).Return(new FileDetails(8, DateTime.Now, 52));
            Expect.Call(source.GetFileDetails("/File2.txt")).Return(new FileDetails(8, DateTime.Now, 0));
            Expect.Call(source.GetFileDetails("/Dir1/File.txt")).Return(new FileDetails(8, DateTime.Now, 21));
            Expect.Call(source.GetFileDetails("/Dir1/Sub/File.txt")).Return(new FileDetails(8, DateTime.Now, 123));

            // Page attachments
            Expect.Call(source.GetPagesWithAttachments()).Return(new string[] { "MainPage", "Sub.Page", "Sub.Another" });
            Expect.Call(source.ListPageAttachments(null)).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); })).Return(new string[] { "Attachment.txt" });
            Expect.Call(source.ListPageAttachments(null)).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); })).Return(new string[] { "Attachment2.txt" });
            Expect.Call(source.ListPageAttachments(null)).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Another"); })).Return(new string[0]);

            // Page attachment content
            Expect.Call(source.RetrievePageAttachment(null, "Attachment.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveAttachment(
                    delegate(PageInfo page, string name, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content5");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            Expect.Call(source.RetrievePageAttachment(null, "Attachment2.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment2.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveAttachment(
                    delegate(PageInfo page, string name, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content6");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            // Attachment details
            Expect.Call(source.GetPageAttachmentDetails(null, "Attachment.txt")).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment.txt")).Return(new FileDetails(8, DateTime.Now, 8));
            Expect.Call(source.GetPageAttachmentDetails(null, "Attachment2.txt")).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment2.txt")).Return(new FileDetails(8, DateTime.Now, 29));

            // Setup DESTINATION ------------------------

            // Directories
            Expect.Call(destination.CreateDirectory("/", "Dir1")).Return(true);
            Expect.Call(destination.CreateDirectory("/", "Dir2")).Return(true);
            Expect.Call(destination.CreateDirectory("/Dir1/", "Sub")).Return(true);

            // Files
            Expect.Call(destination.StoreFile("/File1.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/File1.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreFile(
                                                                                                                                                              delegate(string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content1", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            Expect.Call(destination.StoreFile("/File2.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/File2.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreFile(
                                                                                                                                                              delegate(string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content2", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            Expect.Call(destination.StoreFile("/Dir1/File.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/Dir1/File.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreFile(
                                                                                                                                                                  delegate(string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content3", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            Expect.Call(destination.StoreFile("/Dir1/Sub/File.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/Dir1/Sub/File.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreFile(
                                                                                                                                                                      delegate(string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content4", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            // File retrieval count
            destination.SetFileRetrievalCount("/File1.txt", 52);
            LastCall.On(destination).Repeat.Once();
            destination.SetFileRetrievalCount("/File2.txt", 0);
            LastCall.On(destination).Repeat.Once();
            destination.SetFileRetrievalCount("/Dir1/File.txt", 21);
            LastCall.On(destination).Repeat.Once();
            destination.SetFileRetrievalCount("/Dir1/Sub/File.txt", 123);
            LastCall.On(destination).Repeat.Once();

            // Page attachments
            Expect.Call(destination.StorePageAttachment(null, "Attachment.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreAttachment(
                                                                                                                                                                                                                                                                   delegate(PageInfo page, string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content5", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            Expect.Call(destination.StorePageAttachment(null, "Attachment2.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment2.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreAttachment(
                                                                                                                                                                                                                                                                    delegate(PageInfo page, string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content6", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            // Attachment retrieval count
            destination.SetPageAttachmentRetrievalCount(null, "Attachment.txt", 8);
            LastCall.On(destination).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment.txt"), Rhino.Mocks.Constraints.Is.Equal(8)).Repeat.Once();
            destination.SetPageAttachmentRetrievalCount(null, "Attachment2.txt", 29);
            LastCall.On(destination).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment2.txt"), Rhino.Mocks.Constraints.Is.Equal(29)).Repeat.Once();

            // Delete source content
            Expect.Call(source.DeleteFile("/File1.txt")).Return(true);
            Expect.Call(source.DeleteFile("/File2.txt")).Return(true);
            Expect.Call(source.DeleteDirectory("/Dir1/")).Return(true);
            Expect.Call(source.DeleteDirectory("/Dir2/")).Return(true);

            Expect.Call(source.DeletePageAttachment(null, "Attachment.aspx")).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment.txt")).Return(true);
            Expect.Call(source.DeletePageAttachment(null, "Attachment2.aspx")).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment2.txt")).Return(true);

            mocks.Replay(source);
            mocks.Replay(destination);
            mocks.Replay(settingsProvider);
            mocks.Replay(aclManager);

            DataMigrator.MigrateFilesStorageProviderData(source, destination, settingsProvider);

            mocks.Verify(source);
            mocks.Verify(destination);
            mocks.Verify(settingsProvider);
            mocks.Verify(aclManager);
        }