예제 #1
0
        public void HttpOperationDescription_Insert_OutputParameters_From_HttpOperationDescription()
        {
            OperationDescription             od      = GetOperationDescription(typeof(MockService2), "OneInOneOutReturnsString");
            MessagePartDescriptionCollection mpdColl = od.Messages[1].Body.Parts;

            Assert.AreEqual(1, mpdColl.Count, "Test assumes we start with 1 output param");

            // Get a synchronized HOD and HODCollection
            HttpOperationDescription           hod     = od.ToHttpOperationDescription();
            HttpParameterDescriptionCollection hpdColl = hod.OutputParameters;

            // Get an HPD for the newly created MPD
            MessagePartDescription mpdNew = new MessagePartDescription("NewMPD", "NewMPDNS")
            {
                Type = typeof(byte)
            };
            HttpParameterDescription hpd = mpdNew.ToHttpParameterDescription();

            // Add it to the output parameters
            hpdColl.Add(hpd);

            // Verify it appears in the MPD coll
            Assert.AreEqual(2, mpdColl.Count, "Adding new MPD to HPD collection should have updated MPD collection");
            Assert.AreEqual(2, od.Messages[1].Body.Parts.Count, "Adding new MPD should have updated Parts");
            Assert.AreEqual(typeof(byte), od.Messages[1].Body.Parts[1].Type, "Adding new MPD failed due to type");
        }
예제 #2
0
        public void HttpOperationDescription_Update_ReturnValue_From_Incomplete_HttpOperationDescription()
        {
            OperationDescription     od  = GetOperationDescription(typeof(MockService2), "GetAStringFromInt");
            MessagePartDescription   mpd = od.Messages[1].Body.ReturnValue;
            HttpOperationDescription hod = od.ToHttpOperationDescription();
            HttpParameterDescription hpd = hod.ReturnValue;

            // Clear out all of Messages[]
            od.Messages.Clear();

            Assert.IsNull(hod.ReturnValue, "ReturnValue should be null with no backing Messages[1]");

            // Attempting to set a mock HPD should throw
            ExceptionAssert.ThrowsInvalidOperation(
                "Setting unsynchronized HPD to ReturnValue should throw",
                () => hod.ReturnValue = new HttpParameterDescription()
            {
                ParameterType = typeof(string)
            }
                );

            // Setting a valid ReturnValue should auto-create Messages[1]
            hod.ReturnValue = hpd;

            Assert.IsNotNull(hod.ReturnValue, "ReturnValue was not set");
            Assert.AreSame(hpd.MessagePartDescription, hod.ReturnValue.MessagePartDescription, "ReturnValue not as expected");

            Assert.AreEqual(2, od.Messages.Count, "Setting ReturnValue should have created Messages[1]");
        }
예제 #3
0
        public void HttpOperationDescription_Update_ReturnValue_From_OperationDescription()
        {
            OperationDescription     od  = GetOperationDescription(typeof(MockService2), "GetAStringFromInt");
            HttpOperationDescription hod = od.ToHttpOperationDescription();

            Assert.IsNotNull(hod, "Failed to create HttpOperationDescription");
            HttpParameterDescription returnParameter = hod.ReturnValue;

            Assert.IsNotNull(returnParameter, "Return parameter was null");
            Assert.AreEqual(typeof(string), returnParameter.ParameterType, "Return parameter type should have been string");

            // Update return MPD in-place
            MessagePartDescription mpd = od.Messages[1].Body.ReturnValue;

            mpd.Type = typeof(float);
            Assert.AreEqual(typeof(float), hod.ReturnValue.ParameterType, "Updating OD ReturnValue in place should reflect in HOD");

            // Insert a new MPD
            mpd      = new MessagePartDescription("NewName", "NewNamespace");
            mpd.Type = typeof(double);
            od.Messages[1].Body.ReturnValue = mpd;
            Assert.AreEqual(typeof(double), hod.ReturnValue.ParameterType, "Inserting new OD ReturnValue  should reflect in HOD");

            // Remove the MPD
            od.Messages.RemoveAt(1);
            Assert.IsNull(hod.ReturnValue, "Removing return value message part should yield null ReturnValue");
        }
        public void HttpParameterDescription_Type_Property_Updated_From_MessagePartDescription()
        {
            OperationDescription     od  = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            MessagePartDescription   mpd = od.Messages[0].Body.Parts[0];
            HttpParameterDescription hpd = new HttpParameterDescription(mpd);

            mpd.Type = typeof(float);
            Assert.AreEqual(typeof(float), hpd.ParameterType, "Setting type on messagePartDescription should update http parameter description");
        }
        public void HttpParameterDescription_Default_Ctor()
        {
            HttpParameterDescription hpd = new HttpParameterDescription();

            Assert.IsNull(hpd.ParameterType, "ProcessorType should have been null");
            Assert.IsNull(hpd.Name, "Name should have been null");
            Assert.IsNull(hpd.Namespace, "Namespace should have been null");
            Assert.AreEqual(0, hpd.Index, "Index should have been zero");
            Assert.IsNull(hpd.MessagePartDescription, "Internal messagePartDescription should be null");
        }
        public void HttpParameterDescription_Index_Property_Updates_MessagePartDescription()
        {
            OperationDescription     od  = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            MessagePartDescription   mpd = od.Messages[0].Body.Parts[0];
            HttpParameterDescription hpd = new HttpParameterDescription(mpd);

            hpd.Index = 5;
            Assert.AreEqual(5, mpd.Index, "Setting index on http parameter description should update messagePartDescription");
            Assert.AreEqual(5, hpd.Index, "Setting index did not retain value");
        }
        public void HttpParameterDescription_ExtensionMethod_Creates_From_MessagePartDescription()
        {
            OperationDescription     od  = GetOperationDescription(typeof(MockService3), "SampleMethod");
            MessagePartDescription   mpd = od.Messages[1].Body.ReturnValue;
            HttpParameterDescription hpd = mpd.ToHttpParameterDescription();

            Assert.AreEqual("SampleMethodResult", hpd.Name, "Name was not set correctly");
            Assert.AreEqual(typeof(string), hpd.ParameterType, "ProcessorType was not set correctly");
            Assert.AreEqual(0, hpd.Index, "Index was not set correctly");
            Assert.AreSame(mpd, hpd.MessagePartDescription, "Internal messagePartDescription should be what we passed to ctor");
        }
        public void HttpParameterDescription_Namespace_Immutable_From_MessagePartDescription()
        {
            OperationDescription     od  = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            HttpParameterDescription hpd = new HttpParameterDescription(od.Messages[0].Body.Parts[0]);

            ExceptionAssert.Throws(
                typeof(NotSupportedException),
                "Setting namespace property should throw",
                () => { hpd.Namespace = "newName"; }
                );
        }
예제 #9
0
        public void HttpOperationDescription_Return_Parameter_Matches_Void_Method()
        {
            OperationDescription     od  = GetOperationDescription(typeof(MockService2), "NoParametersReturnsVoid");
            HttpOperationDescription hod = od.ToHttpOperationDescription();

            Assert.IsNotNull(hod, "Failed to create HttpOperationDescription");
            HttpParameterDescription returnParameter = hod.ReturnValue;

            Assert.IsNotNull(returnParameter, "Return parameter was null");
            Assert.AreEqual(typeof(void), returnParameter.ParameterType, "Return parameter type should have been void");
        }
예제 #10
0
        public void HttpOperationDescription_Can_Be_Created_From_Simple_Types()
        {
            HttpOperationDescription hod = new HttpOperationDescription();

            hod.ReturnValue = new HttpParameterDescription()
            {
                Name          = "Return",
                Namespace     = "ReturnNS",
                ParameterType = typeof(string),
                Index         = 0
            };

            hod.InputParameters.Add(new HttpParameterDescription()
            {
                Name          = "InParameter",
                Namespace     = "InParameterNS",
                ParameterType = typeof(int),
                Index         = 0
            });

            hod.OutputParameters.Add(new HttpParameterDescription()
            {
                Name          = "OutParameter",
                Namespace     = "OutParameterNS",
                ParameterType = typeof(string),
                Index         = 1
            });

            HttpParameterDescription parmDesc = hod.ReturnValue;

            Assert.AreEqual("Return", parmDesc.Name, "ReturnValue.Name incorrect");
            Assert.AreEqual("ReturnNS", parmDesc.Namespace, "ReturnValue.Namespace incorrect");
            Assert.AreEqual(typeof(string), parmDesc.ParameterType, "ReturnValue.ParameterType incorrect");
            Assert.AreEqual(0, parmDesc.Index, "ReturnValue.Index incorrect");

            HttpParameterDescriptionCollection coll = hod.InputParameters;

            Assert.AreEqual(1, coll.Count, "Input parameter collection should have 1 element");
            parmDesc = coll[0];
            Assert.AreEqual("InParameter", parmDesc.Name, "InputParameter.Name incorrect");
            Assert.AreEqual("InParameterNS", parmDesc.Namespace, "InputParameter.Namespace incorrect");
            Assert.AreEqual(typeof(int), parmDesc.ParameterType, "InputParameter.ParameterType incorrect");
            Assert.AreEqual(0, parmDesc.Index, "InputParameter.Index incorrect");

            coll = hod.OutputParameters;
            Assert.AreEqual(1, coll.Count, "Output parameter collection should have 1 element");
            parmDesc = coll[0];
            Assert.AreEqual("OutParameter", parmDesc.Name, "OutParameter.Name incorrect");
            Assert.AreEqual("OutParameterNS", parmDesc.Namespace, "OutParameter.Namespace incorrect");
            Assert.AreEqual(typeof(string), parmDesc.ParameterType, "OutParameter.ParameterType incorrect");
            Assert.AreEqual(1, parmDesc.Index, "OutParameter.Index incorrect");
        }
예제 #11
0
 public JsonValueProcessor(HttpParameterDescription parameter, MediaTypeProcessorMode mode)
     : base(parameter, mode)
 {
     if (parameter != null)
     {
         parameterType        = parameter.ParameterType;
         isJsonValueParameter = typeof(JsonValue).IsAssignableFrom(parameterType);
         if (!isJsonValueParameter)
         {
             serializer = new DataContractJsonSerializer(parameterType);
         }
     }
 }
예제 #12
0
        // Verifies that a HttpOperationDescription built from an OperationDescription
        // matches the given MethodInfo for return type, parameters, and attributes
        private void AssertHttpOperationDescriptionMatchesMethod(HttpOperationDescription hod, MethodInfo method)
        {
            Assert.IsNotNull(hod, "HttpOperationDescription was null");
            Assert.AreEqual(hod.Name, method.Name, "Name mismatch");

            HttpParameterDescription returnParameter = hod.ReturnValue;

            Assert.AreEqual(returnParameter.ParameterType, method.ReturnType, "Return type mismatch");

            IList <HttpParameterDescription> inputParameters = hod.InputParameters;

            ParameterInfo[] parameters = method.GetParameters().Where(p => !p.IsOut).ToArray();
            Assert.AreEqual(parameters.Length, inputParameters.Count, "Input parameter count mismatch");

            for (int i = 0; i < parameters.Length; ++i)
            {
                Assert.AreEqual(parameters[i].Name, inputParameters[i].Name, "Input parameter name mismatch");
                Assert.AreEqual(parameters[i].ParameterType, inputParameters[i].ParameterType, "Input parameter type mismatch");
            }

            IList <HttpParameterDescription> outputParameters = hod.OutputParameters;

            parameters = method.GetParameters().Where(p => p.IsOut).ToArray();
            Assert.AreEqual(parameters.Length, outputParameters.Count, "Output parameter count mismatch");

            for (int i = 0; i < parameters.Length; ++i)
            {
                Assert.AreEqual(parameters[i].Name, outputParameters[i].Name, "Output parameter name mismatch");

                // ServiceModel removes the ByRef part
                Type t = parameters[i].ParameterType;
                if (t.HasElementType && t.IsByRef)
                {
                    t = t.GetElementType();
                }
                Assert.AreEqual(t, outputParameters[i].ParameterType, "Output parameter type mismatch");
            }

            IEnumerable <Attribute> hodAttributes    = hod.Attributes;
            IEnumerable <Attribute> methodAttributes = method.GetCustomAttributes(false).Cast <Attribute>().ToArray();

            foreach (Attribute a in methodAttributes)
            {
                if (!hodAttributes.Contains(a))
                {
                    Assert.Fail("Did not find attribute " + a.GetType().Name + " on method " + method.Name);
                }
            }
        }
        public void HttpParameterDescription_Construct_From_Simple_Properties()
        {
            HttpParameterDescription hpd = new HttpParameterDescription()
            {
                Name          = "Sample",
                Namespace     = "SampleNS",
                ParameterType = typeof(string),
                Index         = 1
            };

            Assert.AreEqual("Sample", hpd.Name, "Name was not set correctly");
            Assert.AreEqual("SampleNS", hpd.Namespace, "Namespace was not set correctly");
            Assert.AreEqual(typeof(string), hpd.ParameterType, "ProcessorType was not set correctly");
            Assert.AreEqual(1, hpd.Index, "Index was not set correctly");
        }
예제 #14
0
        public void HttpOperationDescription_Return_Parameter_Matches_Method()
        {
            OperationDescription     od  = GetOperationDescription(typeof(MockService2), "GetAStringFromInt");
            HttpOperationDescription hod = od.ToHttpOperationDescription();

            Assert.IsNotNull(hod, "Failed to create HttpOperationDescription");
            HttpParameterDescription returnParameter = hod.ReturnValue;

            Assert.IsNotNull(returnParameter, "Return parameter was null");
            Assert.AreEqual(typeof(string), returnParameter.ParameterType, "Return parameter type should have been string");

            Assert.AreEqual("GetAStringFromIntResult", returnParameter.Name, "Return parameter name match operation + Result");
            Assert.AreEqual(TestNamespace, returnParameter.Namespace, "Return parameter namespace should match namespace");
            Assert.AreEqual(0, returnParameter.Index, "Return parameter index should be zero");
        }
예제 #15
0
        public void HttpOperationDescription_Unsynchronized_ReturnValue_Setter()
        {
            HttpOperationDescription hod = new HttpOperationDescription();

            HttpParameterDescription returnValue = new HttpParameterDescription()
            {
                Name          = "TheReturn",
                ParameterType = typeof(string)
            };

            hod.ReturnValue = returnValue;

            Assert.AreSame(returnValue, hod.ReturnValue, "Failed to set return value");

            hod.ReturnValue = null;
            Assert.IsNull(hod.ReturnValue, "Failed to reset return value");
        }
예제 #16
0
        public void HttpOperationDescription_Update_OutputParameters_From_HttpOperationDescription()
        {
            OperationDescription   od  = GetOperationDescription(typeof(MockService2), "OneInOneOutReturnsString");
            MessagePartDescription mpd = od.Messages[1].Body.Parts[0];  // output parameter 1 in the MPD

            Assert.AreEqual(typeof(double), mpd.Type, "MPD out parameter 1 has wrong type");

            // Get a synchronized HOD.
            HttpOperationDescription hod = od.ToHttpOperationDescription();

            Assert.IsNotNull(hod, "Failed to create HttpOperationDescription");

            // Get a synchronized HPDCollection and from it a synchronized HPD
            HttpParameterDescriptionCollection hpdColl = hod.OutputParameters;
            HttpParameterDescription           hpd     = hpdColl[0];

            Assert.IsNotNull(hpd, "Input parameter was null");
            Assert.AreEqual(typeof(double), hpd.ParameterType, "HPD out parameter 1 has wrong type");

            // Negative test -- Name and Namespace are immutable when synchronized
            ExceptionAssert.Throws(
                typeof(NotSupportedException),
                "Setting Name should throw when synchronized",
                () => hpd.Name = "Rename"
                );

            ExceptionAssert.Throws(
                typeof(NotSupportedException),
                "Setting Name should throw when synchronized",
                () => hpd.Name = "Rename"
                );

            // Update return value directly in HOD's parameter description
            hpd.ParameterType = typeof(int);
            hpd.Index         = 5;

            // This should have directly updated it in the MPD as well
            Assert.AreEqual(typeof(int), mpd.Type, "HPD failed to update ParameterType in MPD");
            Assert.AreEqual(5, mpd.Index, "HPD failed to update Index in MPD");

            // Final test -- and that should have updated it in the OD.
            // This is technically the same test as above, but this proves it.
            Assert.AreEqual(typeof(int), od.Messages[1].Body.Parts[0].Type, "HPD failed to update ParameterType in MPD");
            Assert.AreEqual(5, od.Messages[1].Body.Parts[0].Index, "HPD failed to update Index in MPD");
        }
예제 #17
0
        public void HttpOperationDescription_Update_ReturnValue_From_HttpOperationDescription()
        {
            OperationDescription   od  = GetOperationDescription(typeof(MockService2), "GetAStringFromInt");
            MessagePartDescription mpd = od.Messages[1].Body.ReturnValue;

            // Get a synchronized HOD.
            HttpOperationDescription hod = od.ToHttpOperationDescription();

            Assert.IsNotNull(hod, "Failed to create HttpOperationDescription");

            // Get a synchronized HPD
            HttpParameterDescription hpd = hod.ReturnValue;

            Assert.IsNotNull(hpd, "Return parameter was null");
            Assert.AreEqual(typeof(string), hpd.ParameterType, "Return parameter type should have been string");

            // Negative test -- Name and Namespace are immutable when synchronized
            ExceptionAssert.Throws(
                typeof(NotSupportedException),
                "Setting Name should throw when synchronized",
                () => hpd.Name = "Rename"
                );

            ExceptionAssert.Throws(
                typeof(NotSupportedException),
                "Setting Name should throw when synchronized",
                () => hpd.Name = "Rename"
                );

            // Update return value directly in HOD's parameter description
            hpd.ParameterType = typeof(double);
            hpd.Index         = 5;

            // This should have directly updated it in the MPD as well
            Assert.AreEqual(typeof(double), mpd.Type, "HPD failed to update ParameterType in MPD");
            Assert.AreEqual(5, mpd.Index, "HPD failed to update Index in MPD");

            // Final test -- and that should have updated it in the OD.
            // This is technically the same test as above, but this proves it.
            Assert.AreEqual(typeof(double), od.Messages[1].Body.ReturnValue.Type, "HPD failed to update ParameterType in MPD");
            Assert.AreEqual(5, od.Messages[1].Body.ReturnValue.Index, "HPD failed to update Index in MPD");
        }
예제 #18
0
        public void HttpOperationDescription_Update_OutputParameters_From_Incomplete_HttpOperationDescription()
        {
            OperationDescription               od      = GetOperationDescription(typeof(MockService2), "OneInOneOutReturnsString");
            MessagePartDescription             mpd     = od.Messages[1].Body.Parts[0]; // output parameter 1 in the MPD
            HttpOperationDescription           hod     = od.ToHttpOperationDescription();
            HttpParameterDescriptionCollection hpdColl = hod.OutputParameters;
            HttpParameterDescription           hpd     = hpdColl[0];

            // Zap the Messages[]
            od.Messages.Clear();

            // Zapping the backing Messages should have rendered the input collection empty
            Assert.AreEqual(0, hpdColl.Count, "Resetting Messages did not reset count");
            Assert.AreEqual(0, hod.InputParameters.Count, "Resetting Messages did not reset count in HOD");

            // Mutating the OutputParameter collection should auto-create the both in and out Messages
            hpdColl.Add(hpd);

            Assert.AreEqual(2, od.Messages.Count, "Messages[1] was not autocreated");
            Assert.AreEqual(1, hpdColl.Count, "Creating Messages did not set count");
            Assert.AreEqual(1, hod.OutputParameters.Count, "Creating Messages did not set count in HOD");
        }
예제 #19
0
        public void HttpOperationDescription_Update_ReturnValue_Throws_From_Unsynchronized()
        {
            OperationDescription   od  = GetOperationDescription(typeof(MockService2), "GetAStringFromInt");
            MessagePartDescription mpd = od.Messages[1].Body.ReturnValue;

            // Get a synchronized HOD.
            HttpOperationDescription hod = od.ToHttpOperationDescription();

            Assert.IsNotNull(hod, "Failed to create HttpOperationDescription");

            // Get an unsynchronized HPD
            HttpParameterDescription unsynchedHpd = new HttpParameterDescription()
            {
                Name          = "TheReturn",
                ParameterType = typeof(int)
            };

            ExceptionAssert.ThrowsInvalidOperation(
                "Expect InvalidOperation to throw when trying to set unsynchronized return",
                () => hod.ReturnValue = unsynchedHpd
                );

            // Get a synchronized HPD
            HttpParameterDescription hpd = hod.ReturnValue;

            Assert.IsNotNull(hpd, "Return parameter was null");
            Assert.AreEqual(typeof(string), hpd.ParameterType, "Return parameter type should have been string");

            // Null set should succeed
            hod.ReturnValue = null;
            Assert.IsNull(hod.ReturnValue, "Could not set to null");

            // Null should propagate
            Assert.IsNull(od.Messages[1].Body.ReturnValue, "Null did not propagate");

            // Set back to valid value and see if propagates
            hod.ReturnValue = hpd;
            Assert.AreEqual(mpd, od.Messages[1].Body.ReturnValue, "Did not reset to synced value");
        }
예제 #20
0
        public void HttpOperationDescription_Default_Ctor()
        {
            HttpOperationDescription hod = new HttpOperationDescription();

            HttpParameterDescription returnValue = hod.ReturnValue;

            Assert.IsNull(returnValue, "ReturnValue should initialize to null");

            Collection <Attribute> attributes = hod.Attributes;

            Assert.IsNotNull(attributes, "Attributes should initialize to non-null");
            Assert.AreEqual(0, attributes.Count, "Attributes should initialize to empty collection");

            HttpParameterDescriptionCollection inputs = hod.InputParameters;

            Assert.IsNotNull(inputs, "InputParameters should initialize to non-null");
            Assert.AreEqual(0, inputs.Count, "InputParameters should initialize to empty collection");

            HttpParameterDescriptionCollection outputs = hod.OutputParameters;

            Assert.IsNotNull(outputs, "OutputParameters should initialize to non-null");
            Assert.AreEqual(0, outputs.Count, "OutputParameters should initialize to empty collection");

            KeyedByTypeCollection <IOperationBehavior> behaviors = hod.Behaviors;

            Assert.IsNotNull(behaviors, "Behaviors should initialize to non-null");
            Assert.AreEqual(0, behaviors.Count, "Behaviors should initialize to empty");

            Collection <Type> knownTypes = hod.KnownTypes;

            Assert.IsNotNull(knownTypes, "knownTypes should initialize to non-null");
            Assert.AreEqual(0, knownTypes.Count, "knownTypes should initialize to empty");

            Assert.IsNull(hod.BeginMethod, "BeginMethod should initialize to null");
            Assert.IsNull(hod.EndMethod, "EndMethod should initialize to null");
            Assert.IsNull(hod.SyncMethod, "SyncMethod should initialize to null");
            Assert.IsNull(hod.DeclaringContract, "DeclaringContract should initialize to null");
        }
예제 #21
0
 public PngFormatter(HttpParameterDescription parameter, MediaTypeProcessorMode mode)
     : base(parameter, mode)
 {
 }