예제 #1
0
 public void SerializeReply_MessageVersion_Not_None_Throws()
 {
     IDispatchMessageFormatter formatter = new MockHttpMessageFormatter();
     ExceptionAssert.Throws(
         typeof(NotSupportedException),
         "Illegal message version should throw",
         () =>
         {
             formatter.SerializeReply(MessageVersion.Soap11, parameters: new object[0], result: "result");
         });
 }
예제 #2
0
 public void SerializeReply_Null_Parameters_Throws()
 {
     IDispatchMessageFormatter formatter = new MockHttpMessageFormatter();
     ExceptionAssert.ThrowsArgumentNull(
         "Null parameters should throw",
         "parameters",
         () =>
         {
             formatter.SerializeReply(MessageVersion.None, /*parameters*/ null, /*result*/ "hello");
         });
 }
예제 #3
0
 public void SerializeReply_Null_Result_Allowed()
 {
     bool receivedNullResult = false;
     IDispatchMessageFormatter formatter = new MockHttpMessageFormatter()
     {
         OnSerializeReply = (parameters, result, response) =>
         {
             receivedNullResult = (result == null);
         }
     };
     formatter.SerializeReply(MessageVersion.None, parameters: new object[0], result: null);
     Assert.IsTrue(receivedNullResult, "Null result did not make it through SerializeReply");
 }
예제 #4
0
 public void SerializeReply_Receives_Parameters_And_Result()
 {
     object[] messageParameters = new object[] { "hello", 5.0 };
     string messageResult = "hello";
     IDispatchMessageFormatter formatter = new MockHttpMessageFormatter()
     {
         OnSerializeReply = (parameters, result, response) =>
         {
             Assert.AreSame(messageParameters, parameters, "SerializeReply did not receive the input parameters");
             Assert.AreSame(messageResult, result, "SerializeReply did not receive the input result");
             Assert.IsNotNull(response, "Response should not be null");
         }
     };
     Message responseMessage = formatter.SerializeReply(MessageVersion.None, messageParameters, messageResult);
     Assert.IsTrue(((MockHttpMessageFormatter) formatter).WasSerializeReplyCalled, "SerializeReply on derived class was not called");
 }
예제 #5
0
 public void SerializeReply_Null_HttpResponseMessage_Throws()
 {
     HttpRequestMessage httpRequestMessage = new HttpRequestMessage();
     IDispatchMessageFormatter formatter = new MockHttpMessageFormatter()
     {
         OnGetDefaultResponse = () =>
         {
             return null;
         }
     };
     ExceptionAssert.ThrowsInvalidOperation(
         "Null returned from GetDefaultResponse should throw",
         () =>
         {
             formatter.SerializeReply(MessageVersion.None, parameters: new object[0], result: "result");
         });
 }
예제 #6
0
 public void SerializeReply_Returns_HttpResponseMessage()
 {
     HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
     IDispatchMessageFormatter formatter = new MockHttpMessageFormatter()
     {
         OnGetDefaultResponse = () =>
         {
             return httpResponseMessage;
         },
         OnSerializeReply = (parameters, result, response) =>
         {
             Assert.IsNotNull(response, "Response should not be null when SerializeReply is called");
         }
     };
     Message wcfMessage = formatter.SerializeReply(MessageVersion.None, parameters: new object[0], result: "result");
     Assert.IsNotNull(wcfMessage, "Returned WCF message cannot be null");
     HttpResponseMessage returnedHttpResponseMessage = wcfMessage.ToHttpResponseMessage();
     Assert.AreSame(httpResponseMessage, returnedHttpResponseMessage, "SerializeReply response message was not the one we returned.");
     Assert.IsTrue(((MockHttpMessageFormatter)formatter).WasSerializeReplyCalled, "SerializeReply on derived class was not called");
 }