public void AddsTwoFilesToListWhenAddingDefaultFileName() { var updated = new ManualResetEvent(false); var path = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()); Directory.CreateDirectory(path); var folder = new PublicFolder(path); folder.DirectoryListing.Count.ShouldBe(0); folder.Watcher.Created += (sender, args) => { updated.Set(); }; var filename = folder.IndexFileName; var filepath = Path.Combine(path, filename); File.WriteAllText(filepath, "for testing purposes - delete me"); updated.WaitOne(1000, false); folder.DirectoryListing.Count.ShouldBe(2); folder.DirectoryListing.Count(x => x.Key == $"/{filename}" && x.Value == filepath).ShouldBe(1); folder.CleanUp(); }
internal static string FilePathGetter(this PublicFolder folder, string pathInfo) { var memberInfo = folder.GetType(); var method = memberInfo?.GetMethod("GetFilePath", BindingFlags.Instance | BindingFlags.NonPublic); return((string)method?.Invoke(folder, new object[] { pathInfo })); }
public void UpdatesIndexerWhenChangingFromDefaultFileName() { var updated = new ManualResetEvent(false); var path = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()); Directory.CreateDirectory(path); var filepath = Path.Combine(path, PublicFolder.DefaultIndexFileName); var newfilepath = Path.Combine(path, GenerateUniqueString()); File.WriteAllText(filepath, "for testing purposes - delete me"); var folder = new PublicFolder(path); folder.DirectoryListing.Count.ShouldBe(2); folder.DirectoryListing.Count(x => x.Value == filepath).ShouldBe(2); folder.DirectoryListing.Count(x => x.Key == $"/{PublicFolder.DefaultIndexFileName}").ShouldBe(1); folder.Watcher.Renamed += (sender, args) => { updated.Set(); }; File.Move(filepath, newfilepath); updated.WaitOne(1000, false); folder.DirectoryListing.Count.ShouldBe(1); folder.DirectoryListing.Count(x => x.Value == newfilepath).ShouldBe(1); folder.DirectoryListing.Count(x => x.Key == $"/{PublicFolder.DefaultIndexFileName}").ShouldBe(0); folder.CleanUp(); }
internal static string GetDirectoryListKey(this PublicFolder folder, string item) { var method = folder.GetType().GetMethod("CreateDirectoryListKey", BindingFlags.Instance | BindingFlags.NonPublic); var result = method.Invoke(folder, new object[] { item }); return((string)result); }
public void SendsWhenFileExistsWithPrefix() { const string prefix = "prefix"; const string folder = "sendresponse-b"; var root = new PublicFolder { Prefix = prefix, FolderPath = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()) }; var folderpath = Path.Combine(root.FolderPath, folder); var properties = new Dictionary <string, object> { { "PathInfo", $"/{prefix}/{folder}" } }; var context = Mocks.HttpContext(properties); // Create the directory if (!Directory.Exists(folderpath)) { Directory.CreateDirectory(folderpath); } // Create the required file var filepath = Path.Combine(folderpath, root.DefaultFileName); using (var sw = File.CreateText(filepath)) { sw.WriteLine("Hello"); } root.RespondWithFile(context); context.Response.Received().SendResponse(filepath, true); CleanUp(root.FolderPath); }
protected override void InternalProcessRecord() { try { using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(this.ConfigurationSession, "Disable-MailPublicFolder", Guid.Empty)) { if (!string.IsNullOrWhiteSpace(base.DataObject.EntryId)) { StoreObjectId storeObjectId = StoreObjectId.FromHexEntryId(base.DataObject.EntryId); PublicFolder publicFolder = (PublicFolder)publicFolderDataProvider.Read <PublicFolder>(new PublicFolderId(storeObjectId)); publicFolder.MailEnabled = false; publicFolder.ProxyGuid = Guid.Empty.ToByteArray(); publicFolderDataProvider.Save(publicFolder); } } } catch (AccessDeniedException exception) { base.WriteError(exception, ExchangeErrorCategory.Authorization, this.Identity); } catch (ObjectNotFoundException ex) { this.WriteWarning(Strings.FailedToLocatePublicFolder(this.Identity.ToString(), ex.ToString())); } base.InternalProcessRecord(); }
public void RewritesPath() { var target = new PublicFolder("/js", "/js-1.1.0.0"); var actual = target.RewriteAliasToPath("/js-1.1.0.0/app.js"); Assert.Equal("/js/app.js", actual); }
private Guid GetSourceMailboxGuid() { Guid guid = Guid.Empty; base.WriteVerbose(Strings.DetermineSourceMailbox); using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(this.ConfigurationSession, "New-PublicFolderMoveRequest", Guid.Empty)) { foreach (PublicFolderIdParameter publicFolderIdParameter in this.Folders) { PublicFolder publicFolder = (PublicFolder)base.GetDataObject <PublicFolder>(publicFolderIdParameter, publicFolderDataProvider, null, new LocalizedString?(Strings.ErrorPublicFolderNotFound(publicFolderIdParameter.ToString())), new LocalizedString?(Strings.ErrorPublicFolderNotUnique(publicFolderIdParameter.ToString()))); if (publicFolderDataProvider.PublicFolderSession.IsWellKnownFolder(publicFolder.InternalFolderIdentity.ObjectId)) { base.WriteError(new RecipientTaskException(Strings.ErrorCannotMoveWellKnownPublicFolders), ErrorCategory.InvalidArgument, publicFolderIdParameter); } if (guid == Guid.Empty) { guid = publicFolder.ContentMailboxGuid; } else if (guid != publicFolder.ContentMailboxGuid) { base.WriteError(new RecipientTaskException(Strings.ErrorCannotMovePublicFoldersFromDifferentSourceMailbox), ErrorCategory.InvalidArgument, publicFolderIdParameter); } if (publicFolder.EntryId == null || publicFolder.DumpsterEntryId == null) { base.WriteError(new RecipientTaskException(Strings.ErrorCannotMovePublicFoldersWithNullEntryId), ErrorCategory.InvalidData, publicFolderIdParameter); } this.folderList.Add(new MoveFolderInfo(publicFolder.EntryId, false)); this.folderList.Add(new MoveFolderInfo(publicFolder.DumpsterEntryId, false)); } } return(guid); }
public void DirectoryListingIsUpdatedWhenDefaultFileNameChanges() { var defaultFileName1 = PublicFolder.DefaultIndexFileName; const string defaultFileName2 = "default.html"; var path = Path.Combine(Directory.GetCurrentDirectory(), GenerateUniqueString()); Directory.CreateDirectory(path); File.WriteAllText(Path.Combine(path, defaultFileName1), "for testing purposes - delete me"); File.WriteAllText(Path.Combine(path, defaultFileName2), "for testing purposes - delete me"); var folder = new PublicFolder(path); folder.DirectoryListing.Count.ShouldBe(3); folder.DirectoryListing.Count(x => x.Key.EndsWith(defaultFileName1)).ShouldBe(1); folder.DirectoryListing.Count(x => x.Key.EndsWith(defaultFileName2)).ShouldBe(1); folder.DirectoryListing.Count(x => x.Value == Path.Combine(folder.FolderPath, defaultFileName1)).ShouldBe(2); folder.IndexFileName = defaultFileName2; folder.DirectoryListing.Count.ShouldBe(3); folder.DirectoryListing.Count(x => x.Key.EndsWith(defaultFileName2)).ShouldBe(1); folder.DirectoryListing.Count(x => x.Key.EndsWith(defaultFileName2)).ShouldBe(1); folder.DirectoryListing.Count(x => x.Value == Path.Combine(folder.FolderPath, defaultFileName2)).ShouldBe(2); folder.CleanUp(); }
public static void GetObjectPostAction(DataRow inputRow, DataTable dataTable, DataObjectStore store) { PublicFolder publicFolder = store.GetDataObject("PublicFolder") as PublicFolder; PublicFolderStatistics publicFolderStatistics = store.GetDataObject("PublicFolderStatistics") as PublicFolderStatistics; if (dataTable.Rows.Count == 1) { DataRow dataRow = dataTable.Rows[0]; if (publicFolder != null) { dataRow["IsStorageQuotasSet"] = (publicFolder.IssueWarningQuota == null || (publicFolder.IssueWarningQuota.Value.IsUnlimited && publicFolder.ProhibitPostQuota.Value.IsUnlimited && publicFolder.MaxItemSize.Value.IsUnlimited)); dataRow["IssueWarningQuota"] = MailboxPropertiesHelper.UnlimitedByteQuantifiedSizeToString(publicFolder.IssueWarningQuota); dataRow["ProhibitPostQuota"] = MailboxPropertiesHelper.UnlimitedByteQuantifiedSizeToString(publicFolder.ProhibitPostQuota); dataRow["MaxItemSize"] = MailboxPropertiesHelper.UnlimitedByteQuantifiedSizeToString(publicFolder.MaxItemSize); dataRow["IsRetainDeletedItemsForSet"] = (publicFolder.RetainDeletedItemsFor == null); dataRow["RetainDeletedItemsFor"] = ((publicFolder.RetainDeletedItemsFor != null) ? publicFolder.RetainDeletedItemsFor.Value.Days.ToString() : "5"); dataRow["IsAgeLimitSet"] = (publicFolder.AgeLimit == null); dataRow["AgeLimit"] = ((publicFolder.AgeLimit != null && publicFolder.AgeLimit != null) ? publicFolder.AgeLimit.Value.Days.ToString() : "5"); } if (publicFolderStatistics != null) { dataRow["TotalItemSize"] = publicFolderStatistics.TotalItemSize.ToMB().ToString(); dataRow["TotalAssociatedItemSize"] = ((!publicFolderStatistics.TotalAssociatedItemSize.IsNullValue()) ? publicFolderStatistics.TotalAssociatedItemSize.ToMB() : 0UL); dataRow["TotalDeletedItemSize"] = ((!publicFolderStatistics.TotalDeletedItemSize.IsNullValue()) ? publicFolderStatistics.TotalDeletedItemSize.ToMB() : 0UL); } } }
public void DefaultValues() { var root = new PublicFolder(); root.DefaultFileName.ShouldBe("index.html"); root.FolderPath.EndsWith("public").ShouldBe(true); root.Prefix.Equals(string.Empty).ShouldBeTrue(); }
public void ReturnsFalseWhenPathInfoDoesNotStartWithPrefix() { var root = new PublicFolder { Prefix = "prefix" }; root.ShouldRespondWithFile(Mocks.HttpContext()).ShouldBeFalse(); }
public void default_index_can_be_changed() { var root = new PublicFolder { DefaultFileName = "default.html" }; root.DefaultFileName.ShouldBe("default.html"); }
public void TrimsLeadingAndTrailingWhitespace() { var folder = new PublicFolder { Prefix = " /hello/ " }; folder.Prefix.Equals("/hello").ShouldBeTrue(); }
public void DoesNotPrependForwadSlashWhenExists() { var folder = new PublicFolder { Prefix = "/hello" }; folder.Prefix.Equals("/hello").ShouldBeTrue(); }
public void IsEmptyStringWhenSetToNull() { var folder = new PublicFolder { Prefix = null }; folder.Prefix.Equals(string.Empty).ShouldBeTrue(); }
public void CreatesPublicFolderFromString() { const string expected = "/css"; PublicFolder actual = expected; Assert.Equal(expected, actual.Path); Assert.Equal(expected, actual.Alias); }
private bool IsValidToUpdateEntryId(string entryId, out ADObjectId contentMailbox) { contentMailbox = null; if (string.IsNullOrEmpty(entryId)) { return(false); } if (StringComparer.OrdinalIgnoreCase.Equals(entryId, this.DataObject.EntryId)) { return(false); } StoreObjectId storeObjectId = null; try { storeObjectId = StoreObjectId.FromHexEntryId(entryId); } catch (FormatException innerException) { base.WriteError(new RecipientTaskException(Strings.ErrorSetMailPublicFolderEntryIdWrongFormat(entryId), innerException), ExchangeErrorCategory.Client, this.DataObject.Identity); } using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(this.ConfigurationSession, "Set-MailPublicFolder", Guid.Empty)) { Guid exchangeGuid = Guid.Empty; try { PublicFolder publicFolder = (PublicFolder)publicFolderDataProvider.Read <PublicFolder>(new PublicFolderId(storeObjectId)); exchangeGuid = publicFolder.ContentMailboxGuid; } catch (ObjectNotFoundException innerException2) { base.WriteError(new RecipientTaskException(Strings.ErrorSetMailPublicFolderEntryIdNotExist(entryId), innerException2), ExchangeErrorCategory.Client, this.DataObject.Identity); } ADRecipient adrecipient = base.TenantGlobalCatalogSession.FindByExchangeGuid(exchangeGuid); if (adrecipient != null) { contentMailbox = adrecipient.Id; } if (string.IsNullOrEmpty(this.DataObject.EntryId)) { return(true); } StoreObjectId storeObjectId2 = StoreObjectId.FromHexEntryId(this.DataObject.EntryId); try { PublicFolder publicFolder2 = (PublicFolder)publicFolderDataProvider.Read <PublicFolder>(new PublicFolderId(storeObjectId2)); } catch (ObjectNotFoundException) { return(true); } if (ArrayComparer <byte> .Comparer.Equals(storeObjectId2.LongTermFolderId, storeObjectId.LongTermFolderId)) { return(true); } } return(false); }
public void AppendsPrefix() { var folder = new PublicFolder { Prefix = "unit-test" }; var path = folder.GetDirectoryListKey(Path.Combine(folder.FolderPath, "path1", "path2")); path.Equals("/unit-test/path1/path2").ShouldBeTrue(); }
public void NoParameters() { var folder = new PublicFolder(); folder.IndexFileName.ShouldBe(PublicFolder.DefaultIndexFileName); folder.FolderPath.ShouldBe(Path.Combine(Directory.GetCurrentDirectory(), PublicFolder.DefaultFolderName)); folder.Prefix.Equals(string.Empty).ShouldBeTrue(); folder.DirectoryListing.Any().ShouldBeFalse(); }
public void PrependsMissingForwardSlash() { var folder = new PublicFolder { Prefix = "hello" }; folder.Prefix.Equals("hello").ShouldBeFalse(); folder.Prefix.Equals("/hello").ShouldBeTrue(); }
public void CreatesFolderIfNotExists() { var folder = GenerateUniqueString(); var root = new PublicFolder { FolderPath = folder }; root.FolderPath.Equals(Path.Combine(Directory.GetCurrentDirectory(), folder)).ShouldBe(true); CleanUp(root.FolderPath); }
public void DefaultFileNameDoesNotChangeWhenSetToEmptyString() { var folder = new PublicFolder(); var defaultFileName = folder.IndexFileName; folder.IndexFileName = string.Empty; folder.IndexFileName.ShouldBe(defaultFileName); }
public void DoesNotUpdateToNull() { var folder = new PublicFolder(); var watcher = folder.Watcher; folder.Watcher = null; folder.Watcher.ShouldNotBeNull(); folder.Watcher.Equals(watcher).ShouldBeTrue(); }
public void DefaultFileNameDoesNotChangeWhenSetToNull() { var folder = new PublicFolder(); var defaultFileName = folder.IndexFileName; folder.IndexFileName = null; folder.IndexFileName.ShouldBe(defaultFileName); }
private SearchSource GetSource(SearchSource source, PublicFolder publicFolder) { SearchSource searchSource = source.Clone(); searchSource.OriginalReferenceId = publicFolder.FolderPath.ToString(); searchSource.ReferenceId = publicFolder.ContentMailboxGuid.ToString(); searchSource.FolderSpec = this.GetFolderSpec(publicFolder); searchSource.SourceLocation = SourceLocation.PrimaryOnly; searchSource.SourceType = SourceType.MailboxGuid; return(searchSource); }
public void DisposesOfFileSystemWatcher() { var watcher = Substitute.For <FileSystemWatcher>(); var folder = new PublicFolder { Watcher = watcher }; folder.Dispose(); watcher.Received().Dispose(); }
public void TrimsTrailingSlash() { var folder = new PublicFolder { Prefix = "hello/" }; folder.Prefix.Equals("/hello").ShouldBeTrue(); folder.Prefix = "/hello/"; folder.Prefix.Equals("/hello").ShouldBeTrue(); }
public void DoesNotDisposeWhenSetToSameValue() { var watcher = Substitute.For <FileSystemWatcher>(); var folder = new PublicFolder { Watcher = watcher }; folder.Watcher = watcher; watcher.DidNotReceive().Dispose(); }
public void RemovesFolderPath() { var folder = new PublicFolder(); var path = Path.Combine(folder.FolderPath, "path1", "path2"); path.StartsWith(folder.FolderPath).ShouldBeTrue(); path.ToLower().StartsWith(folder.FolderPath.ToLower()).ShouldBeTrue(); path = folder.GetDirectoryListKey(path); path.Equals("/path1/path2").ShouldBeTrue(); }