示例#1
0
        public void SafelyTry_ReturnsRawValue_WhenHttpResponseMessage()
        {
            // valuetypes are serialized as one element value array
            var target     = new LaunchPad();
            var mockLogger = new MockLogger();
            var output     = new HttpResponseMessage(HttpStatusCode.PartialContent)
            {
                Content = new StringContent("Gubmy")
            };

            var result = target.SafelyTry(mockLogger, () => output);

            AssertEx.AreEqual(HttpStatusCode.PartialContent, result.StatusCode);

            AssertEx.AreEqual("Gubmy", result.Content.ReadAsStringAsync().Result);
        }
示例#2
0
        public void SafelyTry_ReturnsError_OnException()
        {
            // valuetypes are serialized as one element value array
            var target     = new LaunchPad();
            var mockLogger = new MockLogger();


            var result = target.SafelyTry(mockLogger, () => throw new Exception("bob wins"));

            AssertEx.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);

            var stuff = JsonConvert.DeserializeObject <TestResponse>(
                result.Content.ReadAsStringAsync().Result);

            AssertEx.StartsWith("There was a fatal service error.", stuff.ErrorMessage);
        }
示例#3
0
        public void SafelyTry_ReturnsStandardResponseObject_OnSuccess()
        {
            // valuetypes are serialized as one element value array
            var target     = new LaunchPad();
            var mockLogger = new MockLogger();
            var result     = target.SafelyTry(mockLogger, () => "Hi");

            AssertEx.AreEqual(HttpStatusCode.OK, result.StatusCode);

            var stuff = JsonConvert.DeserializeObject <TestResponse>(
                result.Content.ReadAsStringAsync().Result);

            AssertEx.AreEqual(null, stuff.ErrorMessage);
            AssertEx.AreEqual(1, stuff.Count);
            AssertEx.AreEqual(new string[] { "Hi" }, stuff.Values);
        }