public void ProxyAliasesShouldBeEqual() { ProxyAlias alias1 = new ProxyAlias("Alias", typeof(ProxyAlias)); ProxyAlias alias2 = new ProxyAlias("Alias", typeof(ProxyAlias)); Expect.IsTrue(alias1.Equals(alias2)); Expect.IsTrue(alias2.Equals(alias1)); }
public void ProxyAliasListShouldContain() { ProxyAlias alias1 = new ProxyAlias("Alias", typeof(ProxyAlias)); ProxyAlias alias2 = new ProxyAlias("Alias", typeof(ProxyAlias)); List <ProxyAlias> list = new List <ProxyAlias>(); list.Add(alias1); Expect.IsTrue(list.Contains(alias2)); }
public void ExecutionRequestShouldNotBeInitialized() { string url = "http://blah.com/Monkey/GetPages.json"; RequestWrapper req = new RequestWrapper(new { Headers = new NameValueCollection(), Url = new Uri(url), HttpMethod = "GET" }); ResponseWrapper res = new ResponseWrapper(new object()); ProxyAlias alias = new ProxyAlias("Monkey", typeof(TestBam)); ExecutionRequest execRequest = new ExecutionRequest(req, res, new ProxyAlias[] { alias }); Expect.IsFalse(execRequest.IsInitialized); }
public void ExecutionRequestShouldResolveClassAlias() { string url = "http://blah.com/Monkey/GetPages.json"; RequestWrapper req = new RequestWrapper(new { Headers = new NameValueCollection(), Url = new Uri(url), HttpMethod = "GET" }); ResponseWrapper res = new ResponseWrapper(new object()); ProxyAlias alias = new ProxyAlias("Monkey", typeof(TestBam)); ExecutionRequest execRequest = new ExecutionRequest(req, res, new ProxyAlias[] { alias }); Expect.AreEqual("TestBam", execRequest.ClassName); }
public void ProxyAliasesShouldNotBeNull() { string url = "http://blah.com/Monkey/GetPages.json"; RequestWrapper req = new RequestWrapper(new { Url = new Uri(url), HttpMethod = "GET" }); ResponseWrapper res = new ResponseWrapper(new object()); ProxyAlias alias = new ProxyAlias("Monkey", typeof(TestBam)); ExecutionRequest execRequest = new ExecutionRequest(req, res, new ProxyAlias[] { alias }); Expect.IsNotNull(execRequest.ProxyAliases); }
protected internal virtual void ParseRequestUrl() { // parse the request url to set the className, methodName and ext string path = RequestUrl.AbsolutePath; if (path.ToLowerInvariant().StartsWith("/get")) { path = path.TruncateFront(4); } else if (path.ToLowerInvariant().StartsWith("/post")) { path = path.TruncateFront(5); } Queue <string> split = new Queue <string>(path.DelimitSplit("/", ".")); while (split.Count > 0) { string currentChunk = split.Dequeue(); string upperred = currentChunk.ToUpperInvariant(); if (string.IsNullOrEmpty(_className)) { if (!ServiceProvider.HasClass(currentChunk) && ProxyAliases != null) { ProxyAlias alias = ProxyAliases.Where(pa => pa.Alias.Equals(currentChunk)).FirstOrDefault(); if (alias != null) { _className = alias.ClassName; } else { _className = currentChunk; } } else { _className = currentChunk; } } else if (string.IsNullOrEmpty(_methodName)) { _methodName = currentChunk; } else if (string.IsNullOrEmpty(_ext)) { _ext = currentChunk; } } }
private bool SendMethodForm(IHttpContext context, string appName) { bool result = false; IRequest request = context.Request; string path = request.Url.AbsolutePath; string prefix = MethodFormPrefixFormat._Format(ResponderSignificantName.ToLowerInvariant()); string partsICareAbout = path.TruncateFront(prefix.Length); string[] segments = partsICareAbout.DelimitSplit("/", "\\"); if (segments.Length == 2) { Incubator providers; List <ProxyAlias> aliases; GetServiceProxies(appName, out providers, out aliases); string className = segments[0]; string methodName = segments[1]; Type type = providers[className]; if (type == null) { ProxyAlias alias = aliases.FirstOrDefault(a => a.Alias.Equals(className)); if (alias != null) { type = providers[alias.ClassName]; } } if (type != null) { InputFormBuilder builder = new InputFormBuilder(type); QueryStringParameter[] parameters = request.Url.Query.DelimitSplit("?", "&").ToQueryStringParameters(); Dictionary <string, object> defaults = new Dictionary <string, object>(); foreach (QueryStringParameter param in parameters) { defaults.Add(param.Name, param.Value); } TagBuilder form = builder.MethodForm(methodName, defaults); LayoutModel layoutModel = GetLayoutModel(appName); layoutModel.PageContent = form.ToMvcHtml().ToString(); ContentResponder.CommonTemplateRenderer.RenderLayout(layoutModel, context.Response.OutputStream); result = true; } } return(result); }
public static ExecutionTargetInfo ResolveExecutionTarget(string path, Incubator serviceProvider, ProxyAlias[] proxyAliases) { ExecutionTargetInfo result = new ExecutionTargetInfo(); Queue <string> split = new Queue <string>(path.DelimitSplit("/", ".")); while (split.Count > 0) { string currentChunk = split.Dequeue(); string upperred = currentChunk.ToUpperInvariant(); if (string.IsNullOrEmpty(result.ClassName)) { if (!serviceProvider.HasClass(currentChunk) && proxyAliases != null) { ProxyAlias alias = proxyAliases.Where(pa => pa.Alias.Equals(currentChunk)).FirstOrDefault(); if (alias != null) { result.ClassName = alias.ClassName; } else { result.ClassName = currentChunk; } } else { result.ClassName = currentChunk; } } else if (string.IsNullOrEmpty(result.MethodName)) { result.MethodName = currentChunk; } else if (string.IsNullOrEmpty(result.Ext)) { result.Ext = currentChunk; } } return(result); }