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