コード例 #1
0
 public void BeforeEach()
 {
     _endpoint = new Endpoint
     {
         Request = { Url = "/something" },
         Responses = new List<Response> { new Response { Status = 200 }}
     };
 }
コード例 #2
0
        public static Endpoint Verify(Endpoint endpoint)
        {
            endpoint = endpoint ?? new Endpoint();

            return new Endpoint
            {
                Request = VerifyRequest(endpoint.Request),
                Responses = VerifyResponses(endpoint.Responses)
            };
        }
コード例 #3
0
        public void Find_ShouldRetrieveEndpoint_ByUrl()
        {
            var inserted = new Endpoint { Request = new Request {Url = "/phantom"} };
            var incoming = new Endpoint { Request = new Request {Url = "/phantom", Post = "A string!"} };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.NotNull(actual);
        }
コード例 #4
0
        public void Find_ShouldRetreiveEndpoint_WhenPostMatches()
        {
            var inserted = new Endpoint { Request = new Request {Url = "/phantom", Post = "A string!"} };
            var incoming = new Endpoint
            {
                Request = new Request {Url = "/phantom", Method = new List<string> {"GET"}, Post = "A string!"}
            };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.NotNull(actual);
        }
コード例 #5
0
        public void Find_ShouldRetrieveEndpoint_WhenFileIsntFound_ButPostMatchesIncomingPost()
        {
            var inserted = new Endpoint
            {
                Request = new Request { Url = "/phantom", Post = "Some post contents!", File = "../../Files/nowhere.txt" }
            };
            var incoming = new Endpoint
            {
                Request = new Request {Url = "/phantom", Method = new List<string> {"GET"}, Post = "Some post contents!"}
            };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.NotNull(actual);
        }
コード例 #6
0
ファイル: EndpointDb.cs プロジェクト: turbonaitis/stubby4net
        public Response Find(Endpoint incoming)
        {
            KeyValuePair<uint, Endpoint> keyValue;
            try {
                keyValue = (from stored in _dictionary where stored.Value.Matches(incoming) select stored).First();
            } catch {
                return null;
            }

            var id = keyValue.Key;
            var endpoint = keyValue.Value;

            int sightings = _sightings[id];
            _sightings[id] = sightings + 1;

            return keyValue.Value.Responses[sightings % endpoint.Responses.Count];
        }
コード例 #7
0
ファイル: YamlParser.cs プロジェクト: turbonaitis/stubby4net
        private static Endpoint ParseEndpoint(YamlMappingNode yamlEndpoint)
        {
            var endpoint = new Endpoint();

            foreach(var requestResponse in yamlEndpoint.Children) {
                switch(requestResponse.Key.ToString()) {
                    case "request":
                        {
                            endpoint.Request = ParseRequest((YamlMappingNode) requestResponse.Value);
                            break;
                        }
                    case "response":
                        {
                            endpoint.Responses = ParseResponses(requestResponse);
                            break;
                        }
                }
            }

            return endpoint;
        }
コード例 #8
0
        public void Find_ShouldReturnNull_WhenQueryDoesntMatch()
        {
            var inserted = new Endpoint
            {
                Request =
               new Request {Url = "/phantom", Query = new NameValueCollection {{"alpha", "a"}, {"beta", "b"},}}
            };
            var incoming = new Endpoint
            {
                Request =
               new Request {
                  Url = "/phantom",
                  Method = new List<string> {"GET"},
                  Post = "A string!",
                  Query = new NameValueCollection {{"alpha", "c"}, {"beta", "b"}, {"kappa", "k"}}
               }
            };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.IsNull(actual);
        }
コード例 #9
0
ファイル: Endpoint.cs プロジェクト: turbonaitis/stubby4net
 internal bool Matches(Endpoint other)
 {
     return Request.Matches(other.Request);
 }
コード例 #10
0
ファイル: Stubby.cs プロジェクト: mrak/stubby4net
 /// <summary>
 /// Add a new endpoint configuration
 /// </summary>
 /// <param name="endpoint">The new endpoint data</param>
 /// <param name="id">The new generated id, for use with Replace/Delete</param>
 /// <returns>True if the operation succeeded</returns>
 public bool Add(Endpoint endpoint, out uint id)
 {
     return _endpointDb.Insert(endpoint, out id);
 }
コード例 #11
0
        public void Find_ShouldReturnNull_WhenFileDoesntMatchIncomingPost()
        {
            var inserted = new Endpoint
            {
                Request = new Request {Url = "/phantom", File = "../../Files/someFileContents.txt"}
            };
            var incoming = new Endpoint
            {
                Request = new Request {Url = "/phantom", Method = new List<string> {"GET"}, Post = "Some non-existant file contents!"}
            };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.IsNull(actual);
        }
コード例 #12
0
        public void Find_ShouldReturnNull_WhenEndpointNotFound()
        {
            var inserted = new Endpoint { Request = new Request {Url = "/phantom"} };
            var incoming = new Endpoint { Request = new Request {Url = "/of/the/opera", Post = "A string!"} };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.IsNull(actual);
        }
コード例 #13
0
        public void Find_ShouldRetrieveEndpoint_WhenUrlIsARegexMatchOnIncomingRequest()
        {
            var inserted = new Endpoint
            {
                Request = new Request { Url = "/phantom$", Method = new List<string> {"POST"}}
            };
            var incoming = new Endpoint
            {
                Request = new Request { Url = "/ghost/or/phantom", Method = new List<string> { "POST" }}
            };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.NotNull(actual);
        }
コード例 #14
0
ファイル: EndpointDb.cs プロジェクト: turbonaitis/stubby4net
        public bool Insert(Endpoint endpoint, out uint id)
        {
            id = NextId();
            var verified = Defaults.Verify(endpoint);

            if(!_dictionary.TryAdd(id, verified))
                return false;

            var methods = verified.Request.Method.Aggregate("", (current, verb) => current + (verb + ",")).TrimEnd(',');
            _sightings.Add(id, 0);
            if(Notify) Out.Notice(string.Format(Loaded, methods, verified.Request.Url));
            return true;
        }
コード例 #15
0
ファイル: EndpointDb.cs プロジェクト: turbonaitis/stubby4net
 public bool Insert(Endpoint endpoint)
 {
     uint i;
     return Insert(endpoint, out i);
 }
コード例 #16
0
ファイル: EndpointDb.cs プロジェクト: turbonaitis/stubby4net
        public bool Replace(uint id, Endpoint endpoint)
        {
            if(!_dictionary.ContainsKey(id))
                return false;

            _dictionary[id] = Defaults.Verify(endpoint);
            return true;
        }
コード例 #17
0
ファイル: Stubby.cs プロジェクト: mrak/stubby4net
 /// <summary>
 /// Swap out the configuration of one of the endpoints
 /// </summary>
 /// <param name="id">The id of the endpoint to replace</param>
 /// <param name="endpoint">The new endpoint data</param>
 /// <returns>True if the operation succeeded</returns>
 public bool Replace(uint id, Endpoint endpoint)
 {
     return _endpointDb.Replace(id, endpoint);
 }
コード例 #18
0
        public void Find_ShouldReturnNull_WhenHeadersDontMatch()
        {
            var inserted = new Endpoint
            {
                Request =
               new Request {
                  Url = "/phantom",
                  Headers =
                     new NameValueCollection {
                        {"Content-Type", "application/json"},
                        {"Content-Disposition", "attachment"},
                     }
               }
            };
            var incoming = new Endpoint
            {
                Request =
               new Request {
                  Url = "/phantom",
                  Method = new List<string> {"GET"},
                  Post = "A string!",
                  Headers =
                     new NameValueCollection {
                        {"Content-Type", "application/xml"},
                        {"Content-Disposition", "attachment"},
                        {"Server", "somethingSpecial"}
                     }
               }
            };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.IsNull(actual);
        }
コード例 #19
0
ファイル: Stubs.cs プロジェクト: mrak/stubby4net
        private Response FindEndpoint(HttpListenerContext context)
        {
            var incoming = new Endpoint
            {
                Request = {
               Url = context.Request.Url.AbsolutePath,
               Method = new List<string> {context.Request.HttpMethod.ToUpper()},
               Headers = CreateNameValueCollection(context.Request.Headers, caseSensitiveKeys: false),
               Query = CreateNameValueCollection(context.Request.QueryString),
               Post = utils.ReadPost(context.Request)
            }
            };

            var found = _endpointDb.Find(incoming);
            return found;
        }
コード例 #20
0
        public void Find_ShouldReturnNull_WhenMethodNotInList()
        {
            var inserted = new Endpoint
            {
                Request = new Request {Url = "/phantom", Method = new List<string> {"POST", "HEAD"}}
            };
            var incoming = new Endpoint
            {
                Request = new Request {Url = "/phantom", Method = new List<string> {"GET"}, Post = "A string!"}
            };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.IsNull(actual);
        }
コード例 #21
0
ファイル: Endpoint.cs プロジェクト: turbonaitis/stubby4net
 protected bool Equals(Endpoint other)
 {
     return Equals(Request, other.Request) && Equals(Responses, other.Responses);
 }
コード例 #22
0
        public void Find_ShouldReturnNull_WhenPostIsDifferent()
        {
            var inserted = new Endpoint { Request = new Request {Url = "/phantom", Post = "Tsk tsk."} };
            var incoming = new Endpoint
            {
                Request = new Request {Url = "/phantom", Method = new List<string> {"GET"}, Post = "A string!"}
            };

            _endpointDb.Insert(inserted);

            var actual = _endpointDb.Find(incoming);

            Assert.IsNull(actual);
        }