コード例 #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");
        }
        public void HttpParameterDescriptionCollection_Ctor_From_Output_MessagePartDescriptionCollection()
        {
            OperationDescription od = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection(od, isOutputCollection: true);
            Assert.IsNotNull(coll, "Failed to create HttpParameterDescriptionCollection");
            Assert.AreEqual(1, coll.Count, "HttpParameterDescriptionCollection should have found 1 parameter");
            HttpParameterDescription hpd = coll[0];

            Assert.AreEqual("outParameter", hpd.Name, "Name was not set correctly");
            Assert.AreEqual(typeof(double), hpd.ParameterType, "ParameterType was not set correctly");
            Assert.AreEqual(0, hpd.Index, "Index was not set correctly");
        }
コード例 #3
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");
        }
コード例 #4
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");
        }
        public void HttpParameterDescriptionCollection_Ctor_From_Mock_HttpParameterDescriptions()
        {
            HttpParameterDescription[] paramDescs = new[] {
                new HttpParameterDescription() { Name="First", Namespace="FirstNS", ParameterType=typeof(string), Index=0 },
                new HttpParameterDescription() { Name="Second", Namespace="SecondNS", ParameterType=typeof(int), Index=1 },
            };

            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection(paramDescs.ToList());
            Assert.AreEqual(2, coll.Count, "HttpParameterDescriptionCollection should have found 2 parameters");

            Assert.AreEqual("First", coll[0].Name, "Name1 was not set correctly");
            Assert.AreEqual("FirstNS", coll[0].Namespace, "Namespace1 was not set correctly");
            Assert.AreEqual(typeof(string), coll[0].ParameterType, "Type1 was not set correctly");
            Assert.AreEqual(0, coll[0].Index, "Index1 was not set correctly");

            Assert.AreEqual("Second", coll[1].Name, "Name2 was not set correctly");
            Assert.AreEqual("SecondNS", coll[1].Namespace, "Namespace2 was not set correctly");
            Assert.AreEqual(typeof(int), coll[1].ParameterType, "Type2 was not set correctly");
            Assert.AreEqual(1, coll[1].Index, "Index2 was not set correctly");
        }
コード例 #6
0
        public void HttpOperationDescription_Delete_OutputParameters_From_HttpOperationDescription()
        {
            OperationDescription   od  = GetOperationDescription(typeof(MockService2), "OneInOneOutReturnsString");
            MessagePartDescription mpd = od.Messages[1].Body.Parts[0];  // input parameter 1 in the MPD

            // 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;

            Assert.AreEqual(1, hpdColl.Count, "Expected HPD collection to have one output param");

            // Delete it from our collection
            hpdColl.RemoveAt(0);

            // Verify the backing OD has seen that change
            Assert.AreEqual(0, od.Messages[1].Body.Parts.Count, "Expected delete of HPD input parameter to delete it from OD");
        }
コード例 #7
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");
        }
コード例 #8
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");
        }
コード例 #9
0
        public void HttpOperationDescription_Update_InputParameters_From_OperationDescription()
        {
            OperationDescription od  = GetOperationDescription(typeof(MockService2), "GetAStringFromInt");
            OperationDescription od2 = GetOperationDescription(typeof(MockService2), "OneInOneOutReturnsString");

            HttpOperationDescription hod = od.ToHttpOperationDescription();

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

            // Just confirm initial creation was correct
            HttpParameterDescriptionCollection inputParameters = hod.InputParameters;

            Assert.AreEqual(1, inputParameters.Count, "Expected one input parameter");
            Assert.AreEqual(typeof(int), inputParameters[0].ParameterType, "Expected int type");

            // Replace the messages from 2nd OD
            od.Messages[0] = od2.Messages[0];

            inputParameters = hod.InputParameters;
            Assert.IsNotNull(inputParameters, "InputParameters should not be null after update");
            Assert.AreEqual(1, inputParameters.Count, "Expected one input parameter after update");
            Assert.AreEqual(typeof(char), inputParameters[0].ParameterType, "Expected char type after update");
        }
        public void HttpParameterDescriptionCollection_Synchronized_Implements_Clear()
        {
            OperationDescription od1 = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            MessagePartDescriptionCollection mpdColl = od1.Messages[0].Body.Parts;
            Assert.AreEqual(2, mpdColl.Count, "MessagePartDescriptionCollection should show 2 existing input parameters");

            // This ctor creates the synchronized form of the collection.   It should immediately reflect
            // the state of the MPD collection
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od1, isOutputCollection: false);

            hpdColl.Clear();
            Assert.AreEqual(0, hpdColl.Count, "Clear failed");
        }
        public void HttpParameterDescriptionCollection_Synchronized_GetEnumerator()
        {
            OperationDescription od1 = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            OperationDescription od2 = GetOperationDescription(typeof(MockService3), "SampleMethod");
            MessagePartDescriptionCollection mpdColl = od1.Messages[0].Body.Parts;
            Assert.AreEqual(2, mpdColl.Count, "MessagePartDescriptionCollection should show 2 existing input parameters");

            MessagePartDescriptionCollection mpdColl2 = od2.Messages[0].Body.Parts;
            Assert.AreEqual(1, mpdColl2.Count, "MessagePartDescriptionCollection 2 should show 1 existing input parameters");

            // Pull out individual parts to test synching at item level
            MessagePartDescription mpd1 = mpdColl[0];
            MessagePartDescription mpd2 = mpdColl[1];

            // Use a MPD from a 2nd collection so we can add and remove it
            MessagePartDescription mpd3 = mpdColl2[0];

            // This ctor creates the synchronized form of the collection.   It should immediately reflect
            // the state of the MPD collection
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od1, isOutputCollection: false);
            Assert.IsNotNull(hpdColl, "Failed to create HttpParameterDescriptionCollection");
            Assert.AreEqual(2, hpdColl.Count, "HttpParameterDescriptionCollection should show 2 existing input parameters");

            // Extension method creates synched version of HPD from MPD's
            HttpParameterDescription hpd1 = mpd1.ToHttpParameterDescription();
            HttpParameterDescription hpd2 = mpd2.ToHttpParameterDescription();

            // Ensure the extension method created HPD's that point to the idential MPD
            Assert.AreEqual(mpd1, hpd1.MessagePartDescription, "HttParameterDescription 1 linked to wrong MessagePartDescription");
            Assert.AreEqual(mpd2, hpd2.MessagePartDescription, "HttParameterDescription 2 linked to wrong MessagePartDescription");

            // Keep one from 2nd collection
            HttpParameterDescription hpd3 = mpd3.ToHttpParameterDescription();

            // GetEnumerator
            IEnumerator<HttpParameterDescription> ie = hpdColl.GetEnumerator();
            object[] items = EnumeratorToArray(ie);
            AssertSame(hpdColl, items, "Generic enumerator");

            // Non-generic GetEnumerator
            IEnumerator iec = ((IEnumerable)hpdColl).GetEnumerator();
            Assert.IsNotNull(iec, "GetEnumerator failed");
            items = EnumeratorToArray(iec);
            AssertSame(hpdColl, items, "Nongeneric enumerator");
        }
 private static void AssertSame(HttpParameterDescriptionCollection coll, object[] items, string message)
 {
     Assert.AreEqual(coll.Count, items.Length, message + ": length mismatch");
     for (int i = 0; i < items.Length; ++i)
     {
         HttpParameterDescription hpd1 = coll[i];
         HttpParameterDescription hpd2 = items[i] as HttpParameterDescription;
         Assert.IsNotNull(hpd1, message + ": null in collection");
         Assert.IsNotNull(hpd2, message + ": null in items");
         Assert.AreSame(hpd1.MessagePartDescription, hpd2.MessagePartDescription, message + ": different MessagePartDescriptions");
     }
 }
        public void HttpParameterDescriptionCollection_Synchronized_CopyTo()
        {
            OperationDescription od1 = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            OperationDescription od2 = GetOperationDescription(typeof(MockService3), "SampleMethod");
            MessagePartDescriptionCollection mpdColl = od1.Messages[0].Body.Parts;
            Assert.AreEqual(2, mpdColl.Count, "MessagePartDescriptionCollection should show 2 existing input parameters");

            MessagePartDescriptionCollection mpdColl2 = od2.Messages[0].Body.Parts;
            Assert.AreEqual(1, mpdColl2.Count, "MessagePartDescriptionCollection 2 should show 1 existing input parameters");

            // Pull out individual parts to test synching at item level
            MessagePartDescription mpd1 = mpdColl[0];
            MessagePartDescription mpd2 = mpdColl[1];

            // Use a MPD from a 2nd collection so we can add and remove it
            MessagePartDescription mpd3 = mpdColl2[0];

            // This ctor creates the synchronized form of the collection.   It should immediately reflect
            // the state of the MPD collection
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od1, isOutputCollection: false);
            Assert.IsNotNull(hpdColl, "Failed to create HttpParameterDescriptionCollection");
            Assert.AreEqual(2, hpdColl.Count, "HttpParameterDescriptionCollection should show 2 existing input parameters");

            // Extension method creates synched version of HPD from MPD's
            HttpParameterDescription hpd1 = mpd1.ToHttpParameterDescription();
            HttpParameterDescription hpd2 = mpd2.ToHttpParameterDescription();

            // Ensure the extension method created HPD's that point to the idential MPD
            Assert.AreEqual(mpd1, hpd1.MessagePartDescription, "HttParameterDescription 1 linked to wrong MessagePartDescription");
            Assert.AreEqual(mpd2, hpd2.MessagePartDescription, "HttParameterDescription 2 linked to wrong MessagePartDescription");

            // Keep one from 2nd collection
            HttpParameterDescription hpd3 = mpd3.ToHttpParameterDescription();

            // CopyTo
            HttpParameterDescription[] arr = new HttpParameterDescription[2];
            hpdColl.CopyTo(arr, 0);
            Assert.AreSame(hpd1.MessagePartDescription, arr[0].MessagePartDescription, "CopyTo[0] failed");
            Assert.AreSame(hpd2.MessagePartDescription, arr[1].MessagePartDescription, "CopyTo[1] failed");

            // CopyTo negative tests
            ExceptionAssert.ThrowsArgumentNull(
                "CopyTo throws argument null for null array",
                "array",
                () => hpdColl.CopyTo(null, 0)
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "CopyTo should throw for negative index",
                () => hpdColl.CopyTo(arr, -1),
                "arrayIndex"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "CopyTo should throw for too large an index",
                () => hpdColl.CopyTo(arr, 2),
                "arrayIndex"
                );
        }
        public void HttpParameterDescriptionCollection_Unsynchronized_CopyTo()
        {
            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
            HttpParameterDescription hpd1 = new HttpParameterDescription()
            {
                Name = "First",
                Namespace = "FirstNS",
                Index = 0,
                ParameterType = typeof(string)
            };
            HttpParameterDescription hpd2 = new HttpParameterDescription()
            {
                Name = "Second",
                Namespace = "SecondNS",
                Index = 1,
                ParameterType = typeof(int)
            };
            HttpParameterDescription hpd3 = new HttpParameterDescription()
            {
                Name = "Third",
                Namespace = "ThirdNS",
                Index = 2,
                ParameterType = typeof(double)
            };

            coll.Add(hpd1);
            coll.Add(hpd2);

            // CopyTo
            HttpParameterDescription[] arr = new HttpParameterDescription[2];
            coll.CopyTo(arr, 0);
            Assert.AreSame(hpd1, arr[0], "CopyTo[0] failed");
            Assert.AreSame(hpd2, arr[1], "CopyTo[1] failed");

            // CopyTo negative tests
            ExceptionAssert.ThrowsArgumentNull(
                "CopyTo throws argument null for null array",
                "array",
                () => coll.CopyTo(null, 0)
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "CopyTo should throw for negative index",
                () => coll.CopyTo(arr, -1),
                "arrayIndex"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "CopyTo should throw for too large an index",
                () => coll.CopyTo(arr, 2),
                "arrayIndex"
                );
        }
        public void HttpParameterDescriptionCollection_Synchronized_Incomplete_Indexer()
        {
            OperationDescription od = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            HttpOperationDescription hod = od.ToHttpOperationDescription();
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od, isOutputCollection: false);
            HttpParameterDescription hpd = hod.InputParameters[0];

            // Zap both inputs and outputs
            MessageDescription mdInput = od.Messages[0];
            MessageDescription mdOutput = od.Messages[1];
            od.Messages.Clear();

            // Verify the HOD sees an empty set
            Assert.AreEqual(0, hod.InputParameters.Count, "Expected zero input parameters");

            // Verify our local collection sees an empty set
            Assert.AreEqual(0, hpdColl.Count, "Expected zero elements in local collection");

            // Expect ArgumentOutOfRangeException using get indexer
            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Expected ArgumentOutOfRangeException indexing into missing inputs",
                () => hpd = hod.InputParameters[0]
                );

            // Same exception indexing our local collection
            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Expected ArgumentOutOfRangeException indexing into missing inputs",
                () => hpd = hpdColl[0]
                );

            // Expect ArgumentOutOfRangeException using set indexer on InputParameters
            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Expected ArgumentOutOfRangeException indexing into missing inputs",
                () => hod.InputParameters[0] = hpd
                );

            // Same exception setting on our local collection
            ExceptionAssert.Throws(
                 typeof(ArgumentOutOfRangeException),
                 "Expected ArgumentOutOfRangeException indexing into missing inputs",
                 () => hpdColl[0] = hpd
                 );

            // Add back a real input MessageDescription and verify collections have content again
            od.Messages.Add(mdInput);

            Assert.AreEqual(2, hod.InputParameters.Count, "HOD.InputParameters did not update when added MessageDescription");
            Assert.AreEqual(2, hpdColl.Count, "HODColl.Count did not update when added MessageDescription");

            // The indexer get should work again
            HttpParameterDescription hpd1 = hpdColl[0];
            Assert.IsNotNull(hpd1, "Unexpected null reindexing collection");
            hpd1 = hod.InputParameters[0];
            Assert.IsNotNull(hpd1, "Unexpected null reindexing InputParameters");

            // And so should the setter indexer
            hpdColl[0] = hpd;
            hod.InputParameters[0] = hpd;
        }
 public void HttpParameterDescriptionCollection_Synchronized_Incomplete_Implements_Clear()
 {
     OperationDescription od = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
     od.Messages.Clear();
     HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od, isOutputCollection: false);
     hpdColl.Clear();
     Assert.AreEqual(0, hpdColl.Count, "Clear failed");
 }
        public void HttpParameterDescriptionCollection_Unsynchronized_Contains()
        {
            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
            HttpParameterDescription hpd1 = new HttpParameterDescription()
            {
                Name = "First",
                Namespace = "FirstNS",
                Index = 0,
                ParameterType = typeof(string)
            };
            HttpParameterDescription hpd2 = new HttpParameterDescription()
            {
                Name = "Second",
                Namespace = "SecondNS",
                Index = 1,
                ParameterType = typeof(int)
            };
            HttpParameterDescription hpd3 = new HttpParameterDescription()
            {
                Name = "Third",
                Namespace = "ThirdNS",
                Index = 2,
                ParameterType = typeof(double)
            };

            coll.Add(hpd1);
            coll.Add(hpd2);

            // Contains
            Assert.IsTrue(coll.Contains(hpd1), "Contains[0] incorrect");
            Assert.IsTrue(coll.Contains(hpd2), "Contains[1] incorrect");
            Assert.IsFalse(coll.Contains(hpd3), "Contains[none] incorrect");

            // Contains negative
            ExceptionAssert.ThrowsArgumentNull(
                "IndexOf with null should throw",
                "item",
                () => coll.Contains(null));
        }
        public void HttpParameterDescriptionCollection_Synchronized_Incomplete_IndexOf()
        {
            OperationDescription od = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            HttpOperationDescription hod = od.ToHttpOperationDescription();
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od, isOutputCollection: false);
            HttpParameterDescription hpd = hod.InputParameters[0];

            Assert.AreEqual(0, hpdColl.IndexOf(hpd), "Prove IndexOf works prior to clearing");

            // Zap both inputs and outputs
            MessageDescription mdInput = od.Messages[0];
            MessageDescription mdOutput = od.Messages[1];
            od.Messages.Clear();

            // Verify the HOD sees an empty set
            Assert.AreEqual(0, hod.InputParameters.Count, "Expected zero input parameters");
            Assert.AreEqual(0, hpdColl.Count, "Expected zero elements in local collection");

            // Verify IndexOf cannot find it in either collection
            Assert.AreEqual(-1, hod.InputParameters.IndexOf(hpd), "InputParameters.IndexOf should not have found it");
            Assert.AreEqual(-1, hpdColl.IndexOf(hpd), "HPDColl.IndexOf should not have found it");

            // Add back a real input MessageDescription and verify collections have content again
            od.Messages.Add(mdInput);

            Assert.AreEqual(0, hod.InputParameters.IndexOf(hpd), "InputParameters.IndexOf should have found it");
            Assert.AreEqual(0, hpdColl.IndexOf(hpd), "HPDColl.IndexOf should have found it");
        }
        public void HttpParameterDescriptionCollection_Unsynchronized_Indexer()
        {
            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
            HttpParameterDescription hpd1 = new HttpParameterDescription()
            {
                Name = "First",
                Namespace = "FirstNS",
                Index = 0,
                ParameterType = typeof(string)
            };
            HttpParameterDescription hpd2 = new HttpParameterDescription()
            {
                Name = "Second",
                Namespace = "SecondNS",
                Index = 1,
                ParameterType = typeof(int)
            };
            HttpParameterDescription hpd3 = new HttpParameterDescription()
            {
                Name = "Third",
                Namespace = "ThirdNS",
                Index = 2,
                ParameterType = typeof(double)
            };
            HttpParameterDescription hpdTemp = null;

            coll.Add(hpd1);
            coll.Add(hpd2);

            // Indexer get
            Assert.AreEqual(2, coll.Count, "Count incorrect");
            Assert.AreSame(hpd1, coll[0], "Indexer[0] incorrect");
            Assert.AreSame(hpd2, coll[1], "Indexer[1] incorrect");

            // Indexer get negative
            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Indexer should throw for too large index",
                () => hpdTemp = coll[2],
                "index"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Indexer should throw for negative index",
                () => hpdTemp = coll[-1],
                "index"
                );

            // Indexer set
            coll[1] = hpd3;
            Assert.AreSame(hpd3, coll[1], "Indexer set failed");

            // Indexer set null item
            ExceptionAssert.ThrowsArgumentNull(
                "Indexer set with null should throw",
                "value",
                () => coll[0] = null);

            // Indexer set negative
            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Indexer should throw for too large index",
                () => coll[5] = hpd2,
                "index"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Indexer should throw for negative index",
                () => coll[-1] = hpd2,
                "index"
                );
        }
        public void HttpParameterDescriptionCollection_Unsynchronized_Implements_Clear()
        {
            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
            HttpParameterDescription hpd1 = new HttpParameterDescription()
            {
                Name = "First",
                Namespace = "FirstNS",
                Index = 0,
                ParameterType = typeof(string)
            };
            HttpParameterDescription hpd2 = new HttpParameterDescription()
            {
                Name = "Second",
                Namespace = "SecondNS",
                Index = 1,
                ParameterType = typeof(int)
            };

            coll.Add(hpd1);
            coll.Add(hpd2);

            // Clear
            coll.Clear();
            Assert.AreEqual(0, coll.Count, "Clear failed");
        }
        public void HttpParameterDescriptionCollection_Synchronized_Collection_Throws_New_Mock_HttpParameterDescriptions()
        {
            OperationDescription od = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            MessagePartDescriptionCollection mpdColl = od.Messages[0].Body.Parts;
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od, isOutputCollection: false);
            Assert.IsFalse(hpdColl.IsReadOnly, "Collection should not be readonly");

            // Create a new HPD from simple types
            HttpParameterDescription hpd = new HttpParameterDescription()
            {
                Name = "MockHpd",
                Namespace = "MockHpdNS",
                Index = 2,
                ParameterType = this.GetType()
            };

            ExceptionAssert.ThrowsInvalidOperation(
                "Should throw if attempt to add unsynchronized item to synchronized collection",
                () => hpdColl.Add(hpd));

            ExceptionAssert.ThrowsInvalidOperation(
                "Should throw if attempt to insert unsynchronized item to synchronized collection",
                () => hpdColl.Insert(0, hpd));

            ExceptionAssert.ThrowsInvalidOperation(
                "Should throw if attempt to test contains of unsynchronized item to synchronized collection",
                () => hpdColl.Contains(hpd));

            ExceptionAssert.ThrowsInvalidOperation(
                "Should throw if attempt to test contains of unsynchronized item to synchronized collection",
                () => hpdColl.IndexOf(hpd));
        }
        public void HttpParameterDescriptionCollection_Unsynchronized_GetEnumerator()
        {
            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
            HttpParameterDescription hpd1 = new HttpParameterDescription()
            {
                Name = "First",
                Namespace = "FirstNS",
                Index = 0,
                ParameterType = typeof(string)
            };
            HttpParameterDescription hpd2 = new HttpParameterDescription()
            {
                Name = "Second",
                Namespace = "SecondNS",
                Index = 1,
                ParameterType = typeof(int)
            };
            HttpParameterDescription hpd3 = new HttpParameterDescription()
            {
                Name = "Third",
                Namespace = "ThirdNS",
                Index = 2,
                ParameterType = typeof(double)
            };

            coll.Add(hpd1);
            coll.Add(hpd2);

            // GetEnumerator
            IEnumerator<HttpParameterDescription> ie = coll.GetEnumerator();
            Assert.IsNotNull(ie, "GetEnumerator failed");
            object[] items = EnumeratorToArray(ie);
            AssertSame(coll, items, "Generic enumerator");

            // Non-generic GetEnumerator
            IEnumerator iec = ((IEnumerable)coll).GetEnumerator();
            Assert.IsNotNull(iec, "GetEnumerator failed");
            items = EnumeratorToArray(iec);
            AssertSame(coll, items, "Non-generic enumerator");
        }
 public void HttpParameterDescriptionCollection_Ctor_Empty_List()
 {
     HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection(Enumerable.Empty<HttpParameterDescription>().ToList());
     Assert.AreEqual(0, coll.Count, "Expected empty list to init to empty collection");
 }
        public void HttpParameterDescriptionCollection_Synchronized_Incomplete_CopyTo()
        {
            OperationDescription od = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            HttpOperationDescription hod = od.ToHttpOperationDescription();
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od, isOutputCollection: false);
            HttpParameterDescription hpd = hod.InputParameters[0];

            Assert.IsTrue(hpdColl.Contains(hpd), "Prove Contains works prior to clearing");

            // Zap both inputs and outputs
            MessageDescription mdInput = od.Messages[0];
            MessageDescription mdOutput = od.Messages[1];
            od.Messages.Clear();

            HttpParameterDescription[] arr = new HttpParameterDescription[2];

            // CopyTo should throw ArgumentOutOfRange for any copy request
            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Expected ArgumentOutOfRangeException on empty Messages",
                () => hpdColl.CopyTo(arr, 0),
                "arrayIndex"
            );

            od.Messages.Add(mdInput);

            hpdColl.CopyTo(arr, 0);
            Assert.AreEqual(hpd.MessagePartDescription, arr[0].MessagePartDescription, "Copy did not yield expected instance");
        }
 public void HttpParameterDescriptionCollection_Ctor_Throws_Null_Descriptions()
 {
     ExceptionAssert.ThrowsArgumentNull(
         "Null list of descriptions should throw",
         "descriptions",
         () =>
         {
             HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection(descriptions: null);
         });
 }
        public void HttpParameterDescriptionCollection_Synchronized_Incomplete_Implements_Contains()
        {
            OperationDescription od = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            HttpOperationDescription hod = od.ToHttpOperationDescription();
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od, isOutputCollection: false);
            HttpParameterDescription hpd = hod.InputParameters[0];

            Assert.IsTrue(hpdColl.Contains(hpd), "Prove Contains works prior to clearing");

            // Zap both inputs and outputs
            MessageDescription mdInput = od.Messages[0];
            MessageDescription mdOutput = od.Messages[1];
            od.Messages.Clear();

            // Verify Contains cannot find it in either collection
            Assert.IsFalse(hod.InputParameters.Contains(hpd), "InputParameters.Contains should not have found it");
            Assert.IsFalse(hpdColl.Contains(hpd), "HPDColl.Contains should not have found it");

            // Add back a real input MessageDescription and verify collections have content again
            od.Messages.Add(mdInput);

            Assert.IsTrue(hod.InputParameters.Contains(hpd), "InputParameters.Contains should have found it");
            Assert.IsTrue(hpdColl.Contains(hpd), "HPDColl.Contains should have found it");
        }
        public void HttpParameterDescriptionCollection_Unsynchronized_RemoveAt()
        {
            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
            HttpParameterDescription hpd1 = new HttpParameterDescription()
            {
                Name = "First",
                Namespace = "FirstNS",
                Index = 0,
                ParameterType = typeof(string)
            };
            HttpParameterDescription hpd2 = new HttpParameterDescription()
            {
                Name = "Second",
                Namespace = "SecondNS",
                Index = 1,
                ParameterType = typeof(int)
            };
            HttpParameterDescription hpd3 = new HttpParameterDescription()
            {
                Name = "Third",
                Namespace = "ThirdNS",
                Index = 2,
                ParameterType = typeof(double)
            };

            coll.Add(hpd1);
            coll.Add(hpd2);

            // RemoveAt
            coll.Add(hpd3);
            Assert.AreEqual(3, coll.Count, "Add failed");
            Assert.IsTrue(coll.Contains(hpd3), "Contains after add failed");
            coll.RemoveAt(2);
            Assert.AreEqual(2, coll.Count, "RemoveAt count failed");
            Assert.IsFalse(coll.Contains(hpd3), "RemoveAt+Contains failed");

            // RemoveAt negative
            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "RemoveAt should throw for negative index",
                () => coll.RemoveAt(-1),
                "index"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "RemoveAt should throw for too large index",
                () => coll.RemoveAt(3),
                "index"
                );
        }
        public void HttpParameterDescriptionCollection_Unsynchronized_IndexOf()
        {
            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
            HttpParameterDescription hpd1 = new HttpParameterDescription()
            {
                Name = "First",
                Namespace = "FirstNS",
                Index = 0,
                ParameterType = typeof(string)
            };
            HttpParameterDescription hpd2 = new HttpParameterDescription()
            {
                Name = "Second",
                Namespace = "SecondNS",
                Index = 1,
                ParameterType = typeof(int)
            };
            HttpParameterDescription hpd3 = new HttpParameterDescription()
            {
                Name = "Third",
                Namespace = "ThirdNS",
                Index = 2,
                ParameterType = typeof(double)
            };

            coll.Add(hpd1);
            coll.Add(hpd2);

            // IndexOf
            Assert.AreEqual(0, coll.IndexOf(hpd1), "IndexOf[0] incorrect");
            Assert.AreEqual(1, coll.IndexOf(hpd2), "IndexOf[1] incorrect");
            Assert.AreEqual(-1, coll.IndexOf(hpd3), "IndexOf[none] incorrect");

            // IndexOf negative
            ExceptionAssert.ThrowsArgumentNull(
                "IndexOf with null should throw",
                "item",
                () => coll.IndexOf(null));
        }
 public void HttpParameterDescriptionCollection_Default_Ctor()
 {
     HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
     Assert.AreEqual(0, coll.Count, "Expected default ctor to init to empty collection");
 }
        public void HttpParameterDescriptionCollection_Synchronized_Indexer()
        {
            OperationDescription od1 = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            OperationDescription od2 = GetOperationDescription(typeof(MockService3), "SampleMethod");
            MessagePartDescriptionCollection mpdColl = od1.Messages[0].Body.Parts;
            Assert.AreEqual(2, mpdColl.Count, "MessagePartDescriptionCollection should show 2 existing input parameters");

            MessagePartDescriptionCollection mpdColl2 = od2.Messages[0].Body.Parts;
            Assert.AreEqual(1, mpdColl2.Count, "MessagePartDescriptionCollection 2 should show 1 existing input parameters");

            // Pull out individual parts to test synching at item level
            MessagePartDescription mpd1 = mpdColl[0];
            MessagePartDescription mpd2 = mpdColl[1];

            // Use a MPD from a 2nd collection so we can add and remove it
            MessagePartDescription mpd3 = mpdColl2[0];

            // This ctor creates the synchronized form of the collection.   It should immediately reflect
            // the state of the MPD collection
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od1, isOutputCollection: false);
            Assert.IsNotNull(hpdColl, "Failed to create HttpParameterDescriptionCollection");
            Assert.AreEqual(2, hpdColl.Count, "HttpParameterDescriptionCollection should show 2 existing input parameters");

            // Extension method creates synched version of HPD from MPD's
            HttpParameterDescription hpd1 = mpd1.ToHttpParameterDescription();
            HttpParameterDescription hpd2 = mpd2.ToHttpParameterDescription();

            // Ensure the extension method created HPD's that point to the idential MPD
            Assert.AreEqual(mpd1, hpd1.MessagePartDescription, "HttParameterDescription 1 linked to wrong MessagePartDescription");
            Assert.AreEqual(mpd2, hpd2.MessagePartDescription, "HttParameterDescription 2 linked to wrong MessagePartDescription");

            // Keep one from 2nd collection
            HttpParameterDescription hpd3 = mpd3.ToHttpParameterDescription();

            HttpParameterDescription hpdTemp = null;

            // Indexer get (note this verifies HPD indexer redirects to original MPD coll
            Assert.AreEqual(2, hpdColl.Count, "Count incorrect");
            Assert.AreSame(hpd1.MessagePartDescription, hpdColl[0].MessagePartDescription, "Indexer[0] incorrect");
            Assert.AreSame(hpd2.MessagePartDescription, hpdColl[1].MessagePartDescription, "Indexer[1] incorrect");

            // Indexer get negative
            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Indexer should throw for negative index",
                () => hpdTemp = hpdColl[2],
                "index"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Indexer should throw for negative index",
                () => hpdTemp = hpdColl[-1],
                "index"
                );

            // Indexer set
            hpdColl[1] = hpd3;
            Assert.AreEqual(2, hpdColl.Count, "Index set should have not affected count");
            Assert.AreSame(hpd3.MessagePartDescription, hpdColl[1].MessagePartDescription, "Indexer[1] set incorrect");
        }
        public void HttpParameterDescriptionCollection_Unsynchronized_Insert()
        {
            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
            HttpParameterDescription hpd1 = new HttpParameterDescription()
            {
                Name = "First",
                Namespace = "FirstNS",
                Index = 0,
                ParameterType = typeof(string)
            };
            HttpParameterDescription hpd2 = new HttpParameterDescription()
            {
                Name = "Second",
                Namespace = "SecondNS",
                Index = 1,
                ParameterType = typeof(int)
            };
            HttpParameterDescription hpd3 = new HttpParameterDescription()
            {
                Name = "Third",
                Namespace = "ThirdNS",
                Index = 2,
                ParameterType = typeof(double)
            };

            // Insert semamtics allow index==Count.  Verify.
            coll.Insert(0, hpd1);
            coll.Insert(1, hpd2);

            // Now really insert between
            coll.Insert(1, hpd3);

            Assert.AreEqual(3, coll.Count, "Insert failed");
            Assert.AreSame(hpd3, coll[1], "Insert went to wrong spot");
            Assert.AreSame(hpd2, coll[2], "Insert did not move items");

            // Insert negative
            ExceptionAssert.ThrowsArgumentNull(
                "Insert throws argument null for null item",
                "item",
                () => coll.Insert(0, null)
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Insert should throw for negative index",
                () => coll.Insert(-1, hpd3),
                "index"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "Insert should throw for too large index",
                () => coll.Insert(4, hpd3),
                "index"
                );
        }
        public void HttpParameterDescriptionCollection_Synchronized_IndexOf()
        {
            OperationDescription od1 = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            OperationDescription od2 = GetOperationDescription(typeof(MockService3), "SampleMethod");
            MessagePartDescriptionCollection mpdColl = od1.Messages[0].Body.Parts;
            Assert.AreEqual(2, mpdColl.Count, "MessagePartDescriptionCollection should show 2 existing input parameters");

            MessagePartDescriptionCollection mpdColl2 = od2.Messages[0].Body.Parts;
            Assert.AreEqual(1, mpdColl2.Count, "MessagePartDescriptionCollection 2 should show 1 existing input parameters");

            // Pull out individual parts to test synching at item level
            MessagePartDescription mpd1 = mpdColl[0];
            MessagePartDescription mpd2 = mpdColl[1];

            // Use a MPD from a 2nd collection so we can add and remove it
            MessagePartDescription mpd3 = mpdColl2[0];

            // This ctor creates the synchronized form of the collection.   It should immediately reflect
            // the state of the MPD collection
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od1, isOutputCollection: false);
            Assert.IsNotNull(hpdColl, "Failed to create HttpParameterDescriptionCollection");
            Assert.AreEqual(2, hpdColl.Count, "HttpParameterDescriptionCollection should show 2 existing input parameters");

            // Extension method creates synched version of HPD from MPD's
            HttpParameterDescription hpd1 = mpd1.ToHttpParameterDescription();
            HttpParameterDescription hpd2 = mpd2.ToHttpParameterDescription();

            // Ensure the extension method created HPD's that point to the idential MPD
            Assert.AreEqual(mpd1, hpd1.MessagePartDescription, "HttParameterDescription 1 linked to wrong MessagePartDescription");
            Assert.AreEqual(mpd2, hpd2.MessagePartDescription, "HttParameterDescription 2 linked to wrong MessagePartDescription");

            // Keep one from 2nd collection
            HttpParameterDescription hpd3 = mpd3.ToHttpParameterDescription();

            // IndexOf
            Assert.AreEqual(0, hpdColl.IndexOf(hpd1), "IndexOf[0] incorrect");
            Assert.AreEqual(1, hpdColl.IndexOf(hpd2), "IndexOf[1] incorrect");
            Assert.AreEqual(-1, hpdColl.IndexOf(hpd3), "IndexOf[none] incorrect");

            // IndexOf negative
            ExceptionAssert.ThrowsArgumentNull(
                "IndexOf with null should throw",
                "item",
                () => hpdColl.IndexOf(null));
        }
 public void HttpParameterDescriptionCollection_Unsynchronized_IsReadOnly()
 {
     HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
     Assert.IsFalse(coll.IsReadOnly, "Collection should not be readonly");
 }
        public void HttpParameterDescriptionCollection_Synchronized_RemoveAt()
        {
            OperationDescription od1 = GetOperationDescription(typeof(MockService3), "SampleInOutMethod");
            OperationDescription od2 = GetOperationDescription(typeof(MockService3), "SampleMethod");
            MessagePartDescriptionCollection mpdColl = od1.Messages[0].Body.Parts;
            Assert.AreEqual(2, mpdColl.Count, "MessagePartDescriptionCollection should show 2 existing input parameters");

            MessagePartDescriptionCollection mpdColl2 = od2.Messages[0].Body.Parts;
            Assert.AreEqual(1, mpdColl2.Count, "MessagePartDescriptionCollection 2 should show 1 existing input parameters");

            // Pull out individual parts to test synching at item level
            MessagePartDescription mpd1 = mpdColl[0];
            MessagePartDescription mpd2 = mpdColl[1];

            // Use a MPD from a 2nd collection so we can add and remove it
            MessagePartDescription mpd3 = mpdColl2[0];

            // This ctor creates the synchronized form of the collection.   It should immediately reflect
            // the state of the MPD collection
            HttpParameterDescriptionCollection hpdColl = new HttpParameterDescriptionCollection(od1, isOutputCollection: false);
            Assert.IsNotNull(hpdColl, "Failed to create HttpParameterDescriptionCollection");
            Assert.AreEqual(2, hpdColl.Count, "HttpParameterDescriptionCollection should show 2 existing input parameters");

            // Extension method creates synched version of HPD from MPD's
            HttpParameterDescription hpd1 = mpd1.ToHttpParameterDescription();
            HttpParameterDescription hpd2 = mpd2.ToHttpParameterDescription();

            // Ensure the extension method created HPD's that point to the idential MPD
            Assert.AreEqual(mpd1, hpd1.MessagePartDescription, "HttParameterDescription 1 linked to wrong MessagePartDescription");
            Assert.AreEqual(mpd2, hpd2.MessagePartDescription, "HttParameterDescription 2 linked to wrong MessagePartDescription");

            // Keep one from 2nd collection
            HttpParameterDescription hpd3 = mpd3.ToHttpParameterDescription();

            // RemoveAt
            hpdColl.Add(hpd3);
            Assert.AreEqual(3, hpdColl.Count, "Add failed");
            Assert.IsTrue(hpdColl.Contains(hpd3), "Contains after add failed");
            hpdColl.RemoveAt(2);
            Assert.AreEqual(2, hpdColl.Count, "RemoveAt count failed");
            Assert.IsFalse(hpdColl.Contains(hpd3), "RemoveAt+Contains failed");

            // RemoveAt negative
            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "RemoveAt should throw for negative index",
                () => hpdColl.RemoveAt(-1),
                "index"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "RemoveAt should throw for too large index",
                () => hpdColl.RemoveAt(3),
                "index"
                );
        }
        public void HttpParameterDescriptionCollection_Unsynchronized_Remove()
        {
            HttpParameterDescriptionCollection coll = new HttpParameterDescriptionCollection();
            HttpParameterDescription hpd1 = new HttpParameterDescription()
            {
                Name = "First",
                Namespace = "FirstNS",
                Index = 0,
                ParameterType = typeof(string)
            };
            HttpParameterDescription hpd2 = new HttpParameterDescription()
            {
                Name = "Second",
                Namespace = "SecondNS",
                Index = 1,
                ParameterType = typeof(int)
            };
            HttpParameterDescription hpd3 = new HttpParameterDescription()
            {
                Name = "Third",
                Namespace = "ThirdNS",
                Index = 2,
                ParameterType = typeof(double)
            };

            coll.Add(hpd1);
            coll.Add(hpd2);

            // Remove
            coll.Remove(hpd3);
            Assert.AreEqual(2, coll.Count, "Remove failed");
            Assert.IsFalse(coll.Contains(hpd3), "Remove still shows contains");

            // Remove negative
            Assert.IsFalse(coll.Remove(hpd3), "Redundant remove should have returned false");

            ExceptionAssert.ThrowsArgumentNull(
                "Remove throws argument null for null item",
                "item",
                () => coll.Remove(null)
                );
        }