コード例 #1
0
        public void RetrievingCustomerAddressesByZipCode(JArray addresses)
        {
            const int CustomerId = 346760;
            const string ZipCode = "802";

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Zip.Contains(ZipCode)))).Returns((int customerId, AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where n.Value<string>("ZipCode").Contains(addressFilter.Zip) &&
                                                       n.Value<int>("OwnerId") == CustomerId
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses for a customer by zip code' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(string.Format(_customerAddressesFormat, CustomerId) + "/?Zip=" + ZipCode)).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Zip.Contains(ZipCode)))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then addresses are returned".
                f(() => addresses.Count().ShouldEqual(2));
            "Then the address references the queried customer".
                f(() => addresses.First().Value<int>("OwnerId").ShouldEqual(CustomerId));
            "Then each address references the queried zip code".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("ZipCode").ShouldContain(ZipCode)));
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: rmaclean/nSwagger
        private static SecurityRequirement[] ParseSecurityRequirements(JArray securitySchemes)
        {
            if (securitySchemes == null)
            {
                return null;
            }

            var result = new List<SecurityRequirement>();
            foreach (JObject securityObject in securitySchemes)
            {
                var security = ((securitySchemes.First() as JObject).First as JProperty);
                var item = new SecurityRequirement
                {
                    Name = security.Name,
                    Values = (security.Value as JArray).Values<string>().ToArray()
                };

                result.Add(item);
            }

            return result.ToArray();
        }
コード例 #3
0
ファイル: ModelXml.cs プロジェクト: dkushner/SlimDX
        static void CalculateIndices(JObject item, JArray interfaces, Dictionary<string, int> indices)
        {
            var key = (string)item["key"];
            if (indices.ContainsKey((string)item["key"]))
                return;

            var parent = (string)item["type"];
            if (!indices.ContainsKey(parent))
                CalculateIndices(interfaces.First(i => (string)i["key"] == parent) as JObject, interfaces, indices);

            int offset = indices[parent];
            int count = 0;

            foreach (var method in item["methods"])
            {
                int index = (int)method["index"];
                method["index"] = index + offset;
                count++;
            }

            indices.Add(key, count + offset);
        }
コード例 #4
-1
ファイル: JsonUtil.cs プロジェクト: dpoeschl/jenkins
        internal static bool TryParsePullRequestInfo(JArray actions, out PullRequestInfo info)
        {
            var container = actions.First(x => x["parameters"] != null);

            string sha1 = null;
            string pullLink = null;
            int? pullId = null;
            string pullAuthorEmail = null;
            string commitAuthorEmail = null;
            var parameters = (JArray)container["parameters"];
            foreach (var pair in parameters)
            {
                switch (pair.Value<string>("name"))
                {
                    case "ghprbActualCommit":
                        sha1 = pair.Value<string>("value");
                        break;
                    case "ghprbPullId":
                        pullId = pair.Value<int>("value");
                        break;
                    case "ghprbPullAuthorEmail":
                        pullAuthorEmail = pair.Value<string>("value");
                        break;
                    case "ghprbActualCommitAuthorEmail":
                        commitAuthorEmail = pair.Value<string>("value");
                        break;
                    case "ghprbPullLink":
                        pullLink = pair.Value<string>("value");
                        break;
                    default:
                        break;
                }
            }

            // It's possible for the pull email to be blank if the Github settings for the user
            // account hides their public email address.  In that case fall back to the commit
            // author.  It's generally the same value and serves as a nice backup identifier.
            if (string.IsNullOrEmpty(pullAuthorEmail))
            {
                pullAuthorEmail = commitAuthorEmail;
            }

            if (sha1 == null || pullLink == null || pullId == null || pullAuthorEmail == null)
            {
                info = null;
                return false;
            }

            info = new PullRequestInfo(
                authorEmail: pullAuthorEmail,
                id: pullId.Value,
                pullUrl: pullLink,
                sha1: sha1);
            return true;
        }