public void Submit_valid_voting()
        {
            var rh = new MockRequestHandler();

            using (new RESTServer("http://localhost:8080", rh))
            {
                var voting = new VotingDto {
                    VoterId    = "Frodo",
                    Weightings = new[] {
                        new WeightedComparisonPairDto {
                            Id = "1", Selection = Selection.A
                        },
                        new WeightedComparisonPairDto {
                            Id = "2", Selection = Selection.B
                        }
                    }
                };
                var json       = new JavaScriptSerializer();
                var jsonVoting = json.Serialize(voting);

                var wc = new WebClient();
                wc.Headers.Add("Content-Type", "application/json");
                var result = wc.UploadString("http://localhost:8080/api/sprints/42/votings", "Post", jsonVoting);

                Assert.AreEqual("42", rh.sprintId);
                Assert.AreEqual("Frodo", rh.voting.VoterId);
                Assert.AreEqual("2", rh.voting.Weightings.Last().Id);
            }
        }
        public void Submit_inconsistent_voting()
        {
            var rh = new MockRequestHandler();

            using (new RESTServer("http://localhost:8080", rh))
            {
                try {
                    var voting = new VotingDto {
                        VoterId    = "Sauron",
                        Weightings = null
                    };
                    var json       = new JavaScriptSerializer();
                    var jsonVoting = json.Serialize(voting);

                    var wc = new WebClient();
                    wc.Headers.Add("Content-Type", "application/json");
                    var result = wc.UploadString("http://localhost:8080/api/sprints/42/votings", "Post", jsonVoting);
                }
                catch (WebException e) {
                    var response = (System.Net.HttpWebResponse)e.Response;
                    Assert.AreEqual(422, (int)response.StatusCode);

                    var sr     = new StreamReader(response.GetResponseStream());
                    var jsonIv = sr.ReadToEnd();
                    Console.WriteLine("Inconsistent voting: {0}", jsonIv);

                    var json = new JavaScriptSerializer();
                    var iv   = json.Deserialize <InconsistentVotingDto>(jsonIv);
                    Assert.AreEqual("42", iv.SprintId);
                    Assert.AreEqual("1", iv.ComparisonPairId);
                }
            }
        }
        public void Delete_sprint()
        {
            var rh = new MockRequestHandler();

            using (new RESTServer("http://localhost:8080", rh))
            {
                var wc = new WebClient();
                wc.Headers.Add("Content-Type", "application/json");
                var result = wc.UploadString("http://localhost:8080/api/sprints/42", "Delete", "");

                Assert.AreEqual("42", rh.sprintId);
                Assert.AreEqual("42", result);
            }
        }
        public void Create_sprint()
        {
            var rh = new MockRequestHandler();

            rh.sprintId = "42";

            using (new RESTServer("http://localhost:8080", rh)) {
                var stories     = new[] { "X", "Y", "Z" };
                var json        = new JavaScriptSerializer();
                var jsonStories = json.Serialize(stories);

                var wc = new WebClient();
                wc.Headers.Add("Content-Type", "application/json");
                var result = wc.UploadString("http://localhost:8080/api/sprints", "Post", jsonStories);

                Assert.AreEqual("42", result);
            }
        }
        public void Get_total_weighting()
        {
            var rh = new MockRequestHandler();

            using (new RESTServer("http://localhost:8080", rh))
            {
                var wc         = new WebClient();
                var resultJson = wc.DownloadString("http://localhost:8080/api/sprints/42/totalweighting");
                Console.WriteLine(resultJson);

                var json   = new JavaScriptSerializer();
                var result = json.Deserialize <TotalWeightingDto>(resultJson);

                Assert.AreEqual("42", result.SprintId);
                Assert.AreEqual(new[] { "Z", "Y", "X" }, result.Stories);
                Assert.AreEqual(4, result.NumberOfVotings);
            }
        }
        public void Get_comparison_pairs()
        {
            var rh = new MockRequestHandler();

            rh.sprintId = "some id";

            using (new RESTServer("http://localhost:8080", rh))
            {
                var wc         = new WebClient();
                var resultJson = wc.DownloadString("http://localhost:8080/api/sprints/42/comparisonpairs");
                Console.WriteLine(resultJson);

                var json   = new JavaScriptSerializer();
                var result = json.Deserialize <ComparisonPairsDto>(resultJson);

                Assert.AreEqual("42", result.SprintId);

                var pairs = result.Pairs.ToArray();
                Assert.AreEqual(2, result.Pairs.Length);
                Assert.AreEqual("1", result.Pairs[0].Id);
                Assert.AreEqual("Z", result.Pairs[1].B);
            }
        }