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"); }
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_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" ); }