internal DiscoveryClientProtocol(HttpWebClientProtocol protocol) : base(protocol) { this.references = new DiscoveryClientReferenceCollection(); this.documents = new DiscoveryClientDocumentCollection(); this.inlinedSchemas = new Hashtable(); this.additionalInformation = new ArrayList(); this.errors = new DiscoveryExceptionDictionary(); }
void GetServices(DiscoveryClientReferenceCollection references) { foreach (DictionaryEntry entry in references) { var contractRef = entry.Value as ContractReference; if (contractRef != null) { services.Add(contractRef.Contract); } } }
public void GetServiceDescription_Returns_TheServiceDescription() { // Arrange. const string Url = "http://www.example.com/TestService.svc"; const string Username = "******"; const string Password = "******"; Mock.Arrange(() => Arg.IsAny<DiscoveryClientProtocol>().DiscoverAny(Url)).DoNothing(); Mock.Arrange(() => Arg.IsAny<DiscoveryClientProtocol>().ResolveAll()).DoNothing(); var contract1 = new ServiceDescription(); var contractReference1 = Mock.Create<ContractReference>(Behavior.Loose); Mock.Arrange(() => contractReference1.Contract).Returns(contract1); Mock.Arrange(() => contractReference1.Url).Returns("contract1"); var contract2 = new ServiceDescription(); var contractReference2 = Mock.Create<ContractReference>(Behavior.Loose); Mock.Arrange(() => contractReference2.Contract).Returns(contract2); Mock.Arrange(() => contractReference2.Url).Returns("contract2"); var schema1 = new XmlSchema(); var schemaReference1 = Mock.Create<SchemaReference>(Behavior.Loose); Mock.Arrange(() => schemaReference1.Schema).Returns(schema1); Mock.Arrange(() => schemaReference1.Url).Returns("schema1"); var schema2 = new XmlSchema(); var schemaReference2 = Mock.Create<SchemaReference>(Behavior.Loose); Mock.Arrange(() => schemaReference2.Schema).Returns(schema2); Mock.Arrange(() => schemaReference2.Url).Returns("schema2"); var references = new DiscoveryClientReferenceCollection { contractReference1, contractReference2, schemaReference1, schemaReference2 }; Mock.Arrange(() => Arg.IsAny<DiscoveryClientProtocol>().References).Returns(references); var retriever = new WebServiceDescriptionRetriever(); // Act. var serviceDescription = retriever.GetServiceDescription(Url, Username, Password); // Assert. Mock.Assert(() => Arg.IsAny<DiscoveryClientProtocol>().DiscoverAny(Url), Occurs.Once()); Mock.Assert(() => Arg.IsAny<DiscoveryClientProtocol>().ResolveAll(), Occurs.Once()); Assert.IsNotNull(serviceDescription); Assert.AreEqual(2, serviceDescription.ServiceDescriptions.Count); Assert.IsTrue(serviceDescription.ServiceDescriptions.Contains(contract1)); Assert.IsTrue(serviceDescription.ServiceDescriptions.Contains(contract2)); Assert.AreEqual(2, serviceDescription.XmlSchemas.Count); Assert.IsTrue(serviceDescription.XmlSchemas.Contains(schema1)); Assert.IsTrue(serviceDescription.XmlSchemas.Contains(schema2)); }
public ServiceReferenceDiscoveryEventArgs(DiscoveryClientReferenceCollection references) { GetServices(references); }
public void WhenDiscoveryFails_GetServiceDescription_AppendsQueryString() { // Arrange. const string Url = "http://www.example.com/TestService.svc"; const string UrlWithQueryString = Url + "?WSDL"; const string Username = "******"; const string Password = "******"; Mock.Arrange(() => Arg.IsAny<DiscoveryClientProtocol>().DiscoverAny(Url)).Throws<InvalidOperationException>(); Mock.Arrange(() => Arg.IsAny<DiscoveryClientProtocol>().DiscoverAny(UrlWithQueryString)).DoNothing(); var contract = new ServiceDescription(); var contractReference = Mock.Create<ContractReference>(Behavior.Loose); Mock.Arrange(() => contractReference.Contract).Returns(contract); Mock.Arrange(() => contractReference.Url).Returns("contract"); var references = new DiscoveryClientReferenceCollection { contractReference }; Mock.Arrange(() => Arg.IsAny<DiscoveryClientProtocol>().References).Returns(references); var retriever = new WebServiceDescriptionRetriever(); // Act. var serviceDescription = retriever.GetServiceDescription(Url, Username, Password); // Assert. Assert.IsNotNull(serviceDescription); Assert.AreEqual(1, serviceDescription.ServiceDescriptions.Count); Assert.IsTrue(serviceDescription.ServiceDescriptions.Contains(contract)); Assert.AreEqual(0, serviceDescription.XmlSchemas.Count); // Arrange. var expectedException = new InvalidOperationException(); Mock.Arrange(() => Arg.IsAny<DiscoveryClientProtocol>().DiscoverAny(UrlWithQueryString)).Throws(expectedException); try { // Act. retriever.GetServiceDescription(UrlWithQueryString, Username, Password); // Assert. Assert.Fail("Expected exception not thrown."); } catch (InvalidOperationException ex) { Assert.AreSame(expectedException, ex); } Mock.Assert(() => Arg.IsAny<DiscoveryClientProtocol>().DiscoverAny(Url), Occurs.Once()); Mock.Assert(() => Arg.IsAny<DiscoveryClientProtocol>().DiscoverAny(UrlWithQueryString), Occurs.Exactly(2)); }