public async Task Local_FileLifeCycle() { var fileName = Guid.NewGuid().ToString() + ".png"; var fm = new LocalNetworkFileManager(); var key = new FileKey() { ID = fileName, FileType = FileType.Thumbnail }; string partialPath = String.Join("/", new string[] { VoatSettings.Instance.DestinationPathThumbs, fileName }.ToPathParts()); Assert.IsFalse(await fm.Exists(key)); using (var httpRehorse = new HttpResource("https://voat.co/Graphics/voat-goat.png")) { await httpRehorse.GiddyUp(); await fm.Upload(key, httpRehorse.Stream); } Assert.IsTrue(await fm.Exists(key)); var url = fm.Uri(key, new PathOptions() { FullyQualified = false, ProvideProtocol = false }); Assert.AreEqual($"/{partialPath}", url, "Condition:1.1"); fm.Delete(key); Assert.IsFalse(await fm.Exists(key)); }
public void Local_ThumbnailPath() { var fileName = "SOMEQUIDHERE.jpg"; var fm = new LocalNetworkFileManager(); var key = new FileKey() { ID = fileName, FileType = FileType.Thumbnail }; string partialPath = String.Join("/", new string[] { VoatSettings.Instance.DestinationPathThumbs, fileName }.ToPathParts()); VerifyPath(fm, key, partialPath); }
public void Local_BadgePath() { var fileName = "Donor.jpg"; var fm = new LocalNetworkFileManager(); var key = new FileKey() { ID = fileName, FileType = FileType.Badge }; string partialPath = String.Join("/", new string[] { "~/images/badges", fileName }.ToPathParts()); VerifyPath(fm, key, partialPath); }
public void Local_AvatarPath() { var fileName = "puttitout.jpg"; var fm = new LocalNetworkFileManager(); var key = new FileKey() { ID = fileName, FileType = FileType.Avatar }; string partialPath = String.Join("/", new string[] { VoatSettings.Instance.DestinationPathAvatars, fileName }.ToPathParts()); VerifyPath(fm, key, partialPath); ////LOCAL //VoatSettings.Instance.UseContentDeliveryNetwork = false; //var localPath = String.Join('/', VoatSettings.Instance.DestinationPathAvatars.ToPathParts()); //result = VoatUrlFormatter.AvatarPath(username, avatarFileName, false, true, true); //Assert.AreEqual($"~/{localPath}/{username}.jpg", result, "Condition:1.2"); //result = VoatUrlFormatter.AvatarPath(username, avatarFileName, true, false, true); //Assert.AreEqual($"//{VoatSettings.Instance.SiteDomain}/{localPath}/{username}.jpg", result, "Condition:2.2"); //result = VoatUrlFormatter.AvatarPath(username, avatarFileName, true, true, true); //Assert.AreEqual($"http{(VoatSettings.Instance.ForceHTTPS ? "s" : "")}://{VoatSettings.Instance.SiteDomain}/{localPath}/{username}.jpg", result, "Condition:3.2"); ////Reset original value //VoatSettings.Instance.UseContentDeliveryNetwork = originalSetting; //string username = "******"; //string avatarFileName = "username.jpg"; //string result = ""; //var originalSetting = VoatSettings.Instance.UseContentDeliveryNetwork; ////CDN //VoatSettings.Instance.UseContentDeliveryNetwork = true; //result = VoatUrlFormatter.AvatarPath(username, avatarFileName, false, true, true); //Assert.AreEqual(String.Format("~/avatars/{0}.jpg", username), result, "Condition:1"); //result = VoatUrlFormatter.AvatarPath(username, avatarFileName, true, false, true); //Assert.AreEqual(String.Format("//cdn.voat.co/avatars/{0}.jpg", username), result, "Condition:2"); //result = VoatUrlFormatter.AvatarPath(username, avatarFileName, true, true, true); //Assert.AreEqual($"http{(VoatSettings.Instance.ForceHTTPS ? "s" : "")}://cdn.voat.co/avatars/{username}.jpg", result, "Condition:3"); }
public void Local_ExceptionPaths() { var fm = new LocalNetworkFileManager(); var key = new FileKey() { ID = null, FileType = FileType.Avatar }; VerifyPath(fm, key, ""); key = new FileKey() { ID = "", FileType = FileType.Avatar }; VerifyPath(fm, key, ""); }