public void DeleteByGuid() { var redirectMappingProvider = new RedirectMappingProvider(this._container); var redirectMapping = new RedirectMapping { Guid = Guid.NewGuid(), Uri = new Uri("http://www.silkveil.net"), RedirectType = RedirectType.Permanent }; int count = 0; redirectMappingProvider.MappingsAvailable += r => { Assert.That(r.Count(), Is.EqualTo(0)); count++; }; redirectMappingProvider.Create(redirectMapping); redirectMappingProvider.Delete(redirectMapping.Guid); redirectMappingProvider.ReadAll(); Assert.That(count, Is.EqualTo(1)); }
public void Update() { var redirectMappingProvider = new RedirectMappingProvider(this._container); var redirectMapping = new RedirectMapping { Guid = Guid.NewGuid(), Uri = new Uri("http://www.google.de"), RedirectType = RedirectType.Temporary }; int count = 0; redirectMappingProvider.MappingAvailable += r => { Assert.That(r.Uri, Is.EqualTo(redirectMapping.Uri)); Assert.That(r.RedirectType, Is.EqualTo(redirectMapping.RedirectType)); count++; }; redirectMappingProvider.Create(redirectMapping); redirectMapping.Uri = new Uri("http://www.silkveil.net"); redirectMapping.RedirectType = RedirectType.Permanent; redirectMappingProvider.Update(redirectMapping); redirectMappingProvider.ReadById(redirectMapping.Guid); Assert.That(count, Is.EqualTo(1)); }
public void RequestStatusCode() { var httpStreamFactory = new HttpStreamFactory(); httpStreamFactory.StreamAvailable += httpStreamFactory.RequestStatusCode; int count = 0; httpStreamFactory.StatusCodeAvailable += sc => { Assert.That(sc, Is.EqualTo(301)); count++; }; var redirectMapping = new RedirectMapping { Guid = Guid.NewGuid(), Uri = new Uri("http://www.silkveil.net"), RedirectType = RedirectType.Permanent }; httpStreamFactory.CreateRedirect(redirectMapping); Assert.That(count, Is.EqualTo(1)); }
public void ValidGuid() { var guid = Guid.NewGuid(); var redirectMappingResolver = new RedirectMappingResolver(); int count = 0; redirectMappingResolver.MappingResolved += r => { Assert.That(r.Guid, Is.EqualTo(guid)); Assert.That(r.Uri, Is.EqualTo(new Uri("http://www.silkveil.net"))); count++; }; redirectMappingResolver.RequestMapping += g => { var redirectMapping = new RedirectMapping { Guid = guid, Uri = new Uri("http://www.silkveil.net") }; redirectMappingResolver.RequestedMappingAvailable(redirectMapping); }; redirectMappingResolver.ResolveGuid(guid); Assert.That(count, Is.EqualTo(1)); }
public void RedirectTemporarily() { var httpStreamFactory = new HttpStreamFactory(); int count = 0; httpStreamFactory.StreamAvailable += s => { using (var streamReader = new StreamReader(s)) { Assert.That(streamReader.ReadLine(), Is.EqualTo("HTTP/1.1 302 Found")); Assert.That(streamReader.ReadLine(), Is.EqualTo("Location: http://www.silkveil.net/")); } count++; }; var redirectMapping = new RedirectMapping { Guid = Guid.NewGuid(), Uri = new Uri("http://www.silkveil.net"), RedirectType = RedirectType.Temporary }; httpStreamFactory.CreateRedirect(redirectMapping); Assert.That(count, Is.EqualTo(1)); }
public void RequestHeaders() { var httpStreamFactory = new HttpStreamFactory(); httpStreamFactory.StreamAvailable += httpStreamFactory.RequestHeaders; int count = 0; httpStreamFactory.HeadersAvailable += h => { Assert.That(h.Count, Is.EqualTo(1)); Assert.That(h["Location"], Is.EqualTo("http://www.silkveil.net/")); count++; }; var redirectMapping = new RedirectMapping { Guid = Guid.NewGuid(), Uri = new Uri("http://www.silkveil.net"), RedirectType = RedirectType.Permanent }; httpStreamFactory.CreateRedirect(redirectMapping); Assert.That(count, Is.EqualTo(1)); }
public void ReadAllReturnsNonEmptyCollectionAfterCreate() { var redirectMappingProvider = new RedirectMappingProvider(this._container); var redirectMapping = new RedirectMapping { Guid = Guid.NewGuid(), Uri = new Uri("http://www.silkveil.net"), RedirectType = RedirectType.Permanent }; int count = 0; redirectMappingProvider.MappingsAvailable += r => { Assert.That(r, Is.InstanceOf(typeof(IEnumerable <IRedirectMapping>))); Assert.That(r.Count(), Is.EqualTo(1)); Assert.That(r.First().Guid, Is.EqualTo(redirectMapping.Guid)); Assert.That(r.First().Uri, Is.EqualTo(redirectMapping.Uri)); Assert.That(r.First().RedirectType, Is.EqualTo(redirectMapping.RedirectType)); count++; }; redirectMappingProvider.Create(redirectMapping); redirectMappingProvider.ReadAll(); Assert.That(count, Is.EqualTo(1)); }
public void GetAndSetUri() { var uri = new Uri("http://www.silkveil.net"); var redirect = new RedirectMapping { Uri = uri }; Assert.That(redirect.Uri, Is.EqualTo(uri)); }
public void GetAndSetGuid() { var guid = Guid.NewGuid(); var redirect = new RedirectMapping { Guid = guid }; Assert.That(redirect.Guid, Is.EqualTo(guid)); }
private static void GetMappingOrCreate(Type type, out RedirectMapping mapping) { if (m_Mappings.ContainsKey(type)) { mapping = m_Mappings[type]; } else { mapping = new RedirectMapping(); m_Mappings.Add(type, mapping); } }
public void UpdateNonExistentMapping() { var redirectMappingProvider = new RedirectMappingProvider(this._container); var redirectMapping = new RedirectMapping { Guid = Guid.NewGuid(), Uri = new Uri("http://www.silkveil.net"), RedirectType = RedirectType.Permanent }; Assert.That(() => redirectMappingProvider.Update(redirectMapping), Throws.Exception.TypeOf(typeof(MappingNotFoundException))); }
public void CreateAlreadyExistingItemResultsInException() { var redirectMappingProvider = new RedirectMappingProvider(this._container); var redirectMapping = new RedirectMapping { Guid = Guid.NewGuid(), Uri = new Uri("http://www.silkveil.net"), RedirectType = RedirectType.Permanent }; redirectMappingProvider.Create(redirectMapping); Assert.That(() => redirectMappingProvider.Create(redirectMapping), Throws.Exception.TypeOf(typeof(DuplicateMappingException))); }
static RedirectUIKit() { mapping = new RedirectMapping(); // ------ UIName / Behaviour / Args mapping.Register("OpenUIAsync", 0, 3, new string[] { "System.String", "TinaX.XComponent.XBehaviour", "System.Object[]" }, OpenUIAsync_Task_Name_Behaviour_Args); mapping.Register("OpenUI", 0, 3, new string[] { "System.String", "TinaX.XComponent.XBehaviour", "System.Object[]" }, OpenUI_Name_Behavior_Args); mapping.Register("OpenUIAsync", 0, 4, new string[] { "System.String", "TinaX.XComponent.XBehaviour", "System.Action`2[TinaX.UIKit.IUIEntity,TinaX.XException]", "System.Object[]" }, OpenUIAsync_Callback_Name_Behaviour_Args); // ------ UIName / Behaviour / Params /Args mapping.Register("OpenUI", 0, 4, new string[] { "System.String", "TinaX.XComponent.XBehaviour", "TinaX.UIKit.OpenUIParam", "System.Object[]" }, OpenUI_Name_Behaviour_Param_Args); mapping.Register("OpenUIAsync", 0, 4, new string[] { "System.String", "TinaX.XComponent.XBehaviour", "TinaX.UIKit.OpenUIParam", "System.Object[]" }, OpenUIAsync_Task_Name_Behaviour_Param_Args); mapping.Register("OpenUIAsync", 0, 5, new string[] { "System.String", "TinaX.XComponent.XBehaviour", "TinaX.UIKit.OpenUIParam", "System.Action`2[TinaX.UIKit.IUIEntity,TinaX.XException]", "System.Object[]" }, OpenUIAsync_Callback_Name_Behavior_Param_Args); }
public override void ProcessRequest(HttpRequestArgs args) { //there are no specific conditions to skip this processor, as we are redirecting custom paths to new destinations //ensure request contains a trailing in order to give request a common foundation for cache/comparison logic string requestedPath = this.EnsureSlashes(Context.Request.FilePath.ToLower()); //check cache for previously resolved redirect RedirectMapping resolvedMapping = this.GetResolvedMapping(requestedPath); //if it wasn't found via cache, generate the mapping now if (resolvedMapping == null) { resolvedMapping = FindRedirectMatch(requestedPath, this.MappingsMap); //if the map was found, cache it if (resolvedMapping != null) { var item = GetCache <Dictionary <string, RedirectMapping> >(ResolvedMappingsPrefix) ?? new Dictionary <string, RedirectMapping>(); item[requestedPath] = resolvedMapping; SetCache(ResolvedMappingsPrefix, item); } } if (resolvedMapping != null && HttpContext.Current != null) { string targetUrl = this.GetTargetUrl(resolvedMapping, requestedPath); if (resolvedMapping.RedirectType == RedirectType.Redirect301) { this.Redirect301(HttpContext.Current.Response, targetUrl); } else if (resolvedMapping.RedirectType == RedirectType.Redirect302) { HttpContext.Current.Response.Redirect(targetUrl, true); } else if (resolvedMapping.RedirectType == RedirectType.ServerTransfer) { HttpContext.Current.Server.TransferRequest(targetUrl); } else { HttpContext.Current.Response.Redirect(targetUrl, true); } } }
protected virtual string GetTargetUrl(RedirectMapping mapping, string input) { string target = mapping.Target; if (IsValidRegex(mapping.Source)) { target = mapping.Source.Replace(input.TrimEnd(new char[] { '/' }), target); } //if its fully qualified url target, use that if (Uri.IsWellFormedUriString(HttpUtility.UrlDecode(target), UriKind.Absolute)) { var targetUri = new UriBuilder(HttpUtility.UrlDecode(target)); if (mapping.PreserveQueryString) { MergeUriQueryStringWithIncomingQueryString(targetUri); } target = targetUri.Uri.AbsoluteUri; } //if its not a fully qualified url, prepend with the virtual folder path of the current site if available to produce the final relative target url else if (!string.IsNullOrEmpty(Context.Site.VirtualFolder)) { //fake uri with the current url just so we can access useful uribuilder functions (which are not available to relative uris) var targetUri = new UriBuilder(new Uri(HttpContext.Current.Request.Url, string.Concat(StringUtil.EnsurePostfix('/', Context.Site.VirtualFolder), HttpUtility.UrlDecode(target).TrimStart(new char[] { '/' })))); if (mapping.PreserveQueryString) { MergeUriQueryStringWithIncomingQueryString(targetUri); } target = targetUri.Uri.PathAndQuery; } return(target); }
public void RedirectTemporarilyReturnsARewindedStream() { var httpStreamFactory = new HttpStreamFactory(); int count = 0; httpStreamFactory.StreamAvailable += s => { Assert.That(s.Position, Is.EqualTo(0)); count++; }; var redirectMapping = new RedirectMapping { Guid = Guid.NewGuid(), Uri = new Uri("http://www.silkveil.net"), RedirectType = RedirectType.Temporary }; httpStreamFactory.CreateRedirect(redirectMapping); Assert.That(count, Is.EqualTo(1)); }