Esempio n. 1
0
        public void should_throw_exception_when_deserialize_into_wrong_type()
        {
            var deserializer = new ResponseDeserializer();
            var response     = new Response(HttpStatusCode.OK, XmlContentType(), TestObjectXmlResponse);

            Assert.Throws <UnexpectedXmlContentException>(() => deserializer.DeserializeResponse <Status>(response, true));
        }
		public void Should_not_parse_wrong_xml()
		{
			var response = new Response(HttpStatusCode.OK, XmlContentType(), XmlWrongDtoResponseText);

			var deserializer = new ResponseDeserializer();
			Assert.Throws<UnexpectedXmlContentException>(() => deserializer.DeserializeResponse<Status>(response, false));
		}
        public void ThenItShouldThrowExceptionIfResponseIsNotXml(string faultCode, string faultString)
        {
            var deserializer = new ResponseDeserializer();
            var response     = "no-xml-in-here";

            Assert.Throws <ArgumentException>(() => deserializer.DeserializeResponse(response));
        }
Esempio n. 4
0
        public void should_throw_exception_when_deserialize_into_wrong_type_such_as_one_that_is_not_wrapped_in_a_response_tag()
        {
            var deserializer = new ResponseDeserializer();
            var wrongTag     = TestObjectXmlResponse.Replace("response", "rexponse");
            var response     = new Response(HttpStatusCode.OK, XmlContentType(), wrongTag);

            Assert.Throws <UnexpectedXmlContentException>(() => deserializer.DeserializeResponse <Status>(response, true));
        }
Esempio n. 5
0
        public void Should_not_parse_wrong_xml()
        {
            var response = new Response(HttpStatusCode.OK, XmlContentType(), XmlWrongDtoResponseText);

            var deserializer = new ResponseDeserializer();

            Assert.Throws <UnexpectedXmlContentException>(() => deserializer.DeserializeResponse <Status>(response, false));
        }
		public void Should_not_parse_json_identified_as_xml()
		{
			var response = new Response(HttpStatusCode.OK, XmlContentType(), JsonResponseText);

			var deserializer = new ResponseDeserializer();

			Assert.Throws<NonXmlContentException>(() => deserializer.DeserializeResponse<Status>(response, false));
		}
Esempio n. 7
0
        public void Should_not_parse_json_identified_as_xml()
        {
            var response = new Response(HttpStatusCode.OK, XmlContentType(), JsonResponseText);

            var deserializer = new ResponseDeserializer();

            Assert.Throws <NonXmlContentException>(() => deserializer.DeserializeResponse <Status>(response, false));
        }
		public void Should_not_parse_xml_identified_as_json()
		{
			var response = new Response(HttpStatusCode.OK, JsonContentType(), XmlResponseText);

			var deserializer = new ResponseDeserializer();

			Assert.Throws<JsonParseFailedException>(() => deserializer.DeserializeResponse<Status>(response, false));
		}
        public void ProviderDeserializationTestWithMissingPropertiesJson()
        {
            var response = "{\"type\": \"video\",\"html\": \"TestHtml\"}";

            var actual = ResponseDeserializer.DeserializeResponse(response);

            Assert.True(MissingPropertiesObject.Equals(actual));
        }
Esempio n. 10
0
        public void Should_not_parse_xml_identified_as_json()
        {
            var response = new Response(HttpStatusCode.OK, JsonContentType(), XmlResponseText);

            var deserializer = new ResponseDeserializer();

            Assert.Throws <JsonParseFailedException>(() => deserializer.DeserializeResponse <Status>(response, false));
        }
		public void Should_parse_json()
		{
			var response = new Response(HttpStatusCode.OK, JsonContentType(), JsonResponseText);

			var deserializer = new ResponseDeserializer();
			var status = deserializer.DeserializeResponse<Status>(response, false);

			Assert.That(status, Is.Not.Null);
		}
        public void ProviderDeserializationTestWithAdditionalPropertiesJson()
        {
            var response = "{\"type\": \"video\", \"title\": \"TestTitle\", \"thumbnail_url\": \"TestThumbnailUrl\", \"additional\": \"Test\"," +
                           "\"thumbnail_width\": 640, \"thumbnail_height\": 480, \"html\": \"TestHtml\", \"width\": 800, \"height\": 600}";

            var actual = ResponseDeserializer.DeserializeResponse(response);

            Assert.True(FullObject.Equals(actual));
        }
        public void ThenItShouldThrowExceptionIfResponseIsNotSoapResponse(string faultCode, string faultString)
        {
            var deserializer = new ResponseDeserializer();
            var response     = "<nosoap>just xml</nosoap>";

            var actual = Assert.Throws <SoapException>(() => deserializer.DeserializeResponse(response));

            Assert.AreEqual("Response XML does not appear to be a valid SOAP response", actual.Message);
        }
Esempio n. 14
0
        public void should_deserialize_Empty_xml_to_empty_object()
        {
            var deserializer = new ResponseDeserializer();
            var response     = new Response(HttpStatusCode.OK, XmlContentType(), EmptyXmlResponse);

            var testObject = deserializer.DeserializeResponse <TestEmptyObject>(response, true);

            Assert.That(testObject, Is.Not.Null);
        }
Esempio n. 15
0
        public void Should_parse_json()
        {
            var response = new Response(HttpStatusCode.OK, JsonContentType(), JsonResponseText);

            var deserializer = new ResponseDeserializer();
            var status       = deserializer.DeserializeResponse <Status>(response, false);

            Assert.That(status, Is.Not.Null);
        }
        public void ThenItShouldThrowSoapExceptionIfResponseIsFault(string faultCode, string faultString)
        {
            var deserializer = new ResponseDeserializer();
            var response     = GetFaultResponse(faultCode, faultString);

            var actual = Assert.Throws <SoapException>(() => deserializer.DeserializeResponse(response));

            Assert.AreEqual(faultCode, actual.FaultCode);
            Assert.AreEqual(faultString, actual.FaultString);
        }
        public void ThenItShouldParseProvidersFromResponse(Provider provider1, Provider provider2)
        {
            var deserializer = new ResponseDeserializer();
            var response     = GetQueryResponse(provider1, provider2);

            var actual = deserializer.DeserializeResponse(response);

            Assert.IsNotNull(actual);
            Assert.AreEqual(2, actual.Length);
            ObjectAssert.AreEqual(provider1, actual[0]);
            ObjectAssert.AreEqual(provider2, actual[1]);
        }
        public async Task <TR> ResponseAs <TR>() where TR : class, new()
        {
            var request = _requestBuilder.BuildRequest(_requestData);

            try
            {
                var response = await _httpClient.Send(request);

                var responseDeserializer = new ResponseDeserializer();
                return(responseDeserializer.DeserializeResponse <TR>(response, false));
            }
            catch (WebException webException)
            {
                throw new ApiWebException(webException.Message, webException, request);
            }
        }
		public void should_deserialize_well_formed_xml()
		{
			var deserializer = new ResponseDeserializer();
			var response = new Response(HttpStatusCode.OK, XmlContentType(), TestObjectXmlResponse);

			var testObject = deserializer.DeserializeResponse<TestObject>(response, true);

			Assert.That(testObject, Is.Not.Null);
			Assert.That(testObject.Id, Is.EqualTo(1));
			Assert.That(testObject.Name, Is.EqualTo("A big test object"));

			Assert.That(testObject.StringList, Is.Not.Null);
			Assert.That(testObject.StringList.Count, Is.GreaterThan(0));

			Assert.That(testObject.ObjectList, Is.Not.Null);
			Assert.That(testObject.ObjectList.Count, Is.GreaterThan(0));
		}
Esempio n. 20
0
        public void should_deserialize_well_formed_xml()
        {
            var deserializer = new ResponseDeserializer();
            var response     = new Response(HttpStatusCode.OK, XmlContentType(), TestObjectXmlResponse);

            var testObject = deserializer.DeserializeResponse <TestObject>(response, true);

            Assert.That(testObject, Is.Not.Null);
            Assert.That(testObject.Id, Is.EqualTo(1));
            Assert.That(testObject.Name, Is.EqualTo("A big test object"));

            Assert.That(testObject.StringList, Is.Not.Null);
            Assert.That(testObject.StringList.Count, Is.GreaterThan(0));

            Assert.That(testObject.ObjectList, Is.Not.Null);
            Assert.That(testObject.ObjectList.Count, Is.GreaterThan(0));
        }
		public void should_throw_exception_when_deserialize_into_wrong_type_such_as_one_that_is_not_wrapped_in_a_response_tag()
		{
			var deserializer = new ResponseDeserializer();
			var wrongTag = TestObjectXmlResponse.Replace("response", "rexponse");
			var response = new Response(HttpStatusCode.OK, XmlContentType(), wrongTag);

			Assert.Throws<UnexpectedXmlContentException>(() => deserializer.DeserializeResponse<Status>(response, true));
		}
		public void should_throw_exception_when_deserialize_into_wrong_type()
		{
			var deserializer = new ResponseDeserializer();
			var response = new Response(HttpStatusCode.OK, XmlContentType(), TestObjectXmlResponse);

			Assert.Throws<UnexpectedXmlContentException>(() => deserializer.DeserializeResponse<Status>(response, true));
		}
		public void should_deserialize_Empty_xml_to_empty_object()
		{
			var deserializer = new ResponseDeserializer();
			var response = new Response(HttpStatusCode.OK, XmlContentType(), EmptyXmlResponse);

			var testObject = deserializer.DeserializeResponse<TestEmptyObject>(response, true);

			Assert.That(testObject, Is.Not.Null);
		}
        public void NullResponseTest()
        {
            var obj = ResponseDeserializer.DeserializeResponse(null);

            Assert.IsNull(obj);
        }