상속: Resource, IDisposable
예제 #1
0
 public void GivenIHaveAWebservice()
 {
     var webSourceXML = XmlResource.Fetch("Google_Address_Lookup");
     var webSource = new WebSource(webSourceXML);
     var service = new ServiceModel.Data.WebService { Source = webSource };
     ScenarioContext.Current.Add("WebService", service);
 }
예제 #2
0
        public void WebSourcesTestWithInvalidAddressExpectedInvalidValidationResult()
        {
            var source = new WebSource { Address = "www.foo.bar", AuthenticationType = AuthenticationType.Anonymous }.ToString();

            var handler = new WebSources();
            var result = handler.Test(source, Guid.Empty, Guid.Empty);
            Assert.IsFalse(result.IsValid, result.ErrorMessage);
        }
예제 #3
0
 public WebService()
 {
     ResourceID = Guid.Empty;
     ResourceType = Common.Interfaces.Data.ResourceType.WebService;
     Source = new WebSource();
     Recordsets = new RecordsetList();
     Method = new ServiceMethod();
 }
예제 #4
0
 public void WebSourceContructorWithInvalidXmlExpectedDoesNotThrowExceptionAndInitializesProperties()
 {
     var xml = new XElement("root");
     var source = new WebSource(xml);
     Assert.AreNotEqual(Guid.Empty, source.ResourceID);
     Assert.IsTrue(source.IsUpgraded);
     Assert.AreEqual(ResourceType.WebSource, source.ResourceType);
 }
예제 #5
0
 public WebService()
 {
     ResourceID = Guid.Empty;
     ResourceType = ResourceType.WebService;
     Source = new WebSource();
     Recordsets = new RecordsetList();
     Method = new ServiceMethod();
 }
예제 #6
0
        public void WebSourcesAssertUserAgentHeaderSet()
        {
            var source = new WebSource { Address = "www.foo.bar", AuthenticationType = AuthenticationType.Anonymous };

            WebSources.EnsureWebClient(source, new List<string>());

            var client = source.Client;
            var agent = client.Headers["user-agent"];
            Assert.IsNotNull(agent);
            Assert.AreEqual(agent,GlobalConstants.UserAgentString);
        }
예제 #7
0
 // POST: Service/WebSources/Get
 public WebSource Get(string resourceId, Guid workspaceId, Guid dataListId)
 {
     var result = new WebSource();
     try
     {
         var xmlStr = ResourceCatalog.Instance.GetResourceContents(workspaceId, Guid.Parse(resourceId)).ToString();
         if(!string.IsNullOrEmpty(xmlStr))
         {
             var xml = XElement.Parse(xmlStr);
             result = new WebSource(xml);
         }
     }
     catch(Exception ex)
     {
         RaiseError(ex);
     }
     return result;
 }
예제 #8
0
        public void WebSourceDisposeExpectedDisposesAndNullsClient()
        {
            var source = new WebSource { Client = new WebClient() };

            Assert.IsNotNull(source.Client);
            source.Dispose();
            Assert.IsNull(source.Client);
        }
예제 #9
0
        static void VerifySource(WebSource actual, WebSource expected)
        {
            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.ResourceID, actual.ResourceID);
            Assert.AreEqual(expected.ResourceName, actual.ResourceName);
            Assert.AreEqual(expected.ResourcePath, actual.ResourcePath);
            Assert.AreEqual(expected.ResourceType, actual.ResourceType);
            Assert.AreEqual(expected.ResourceType, actual.ResourceType);

            Assert.AreEqual(expected.Address, actual.Address);
            Assert.AreEqual(expected.DefaultQuery, actual.DefaultQuery);
            Assert.AreEqual(expected.AuthenticationType, actual.AuthenticationType);
            Assert.AreEqual(expected.UserName, actual.UserName);
            Assert.AreEqual(expected.Password, actual.Password);
            Assert.IsNull(actual.Response);
        }
예제 #10
0
        public void WebSourcesAssertUserAgentHeaderSet_SetsUserNameAndPassword()

        {
            var source = new WebSource { Address = "www.foo.bar", AuthenticationType = AuthenticationType.User,UserName = "******",Password = "******"};

            WebSources.EnsureWebClient(source, new List<string> { "a:x", "b:e" });

            var client = source.Client;
            // ReSharper disable PossibleNullReferenceException
            Assert.IsTrue((client.Credentials as NetworkCredential).UserName == "User");
          
            Assert.IsTrue((client.Credentials as NetworkCredential).Password == "pwd");
            // ReSharper restore PossibleNullReferenceException
        }
        string DummyWebExecute(WebSource source, WebRequestMethod method, string relativeUri, string data, bool throwError, out ErrorResultTO errors, string[] headers)
        {
            _requestUrlEvaluated = relativeUri;
            _requestBodyEvaluated = data;
            _requestHeadersEvaluated = headers;

            errors = new ErrorResultTO();
            return _requestResponse;
        }
예제 #12
0
        public void WebSourceContructorWithValidXmlExpectedInitializesProperties()
        {
            var xml = XmlResource.Fetch("WebSource");

            var source = new WebSource(xml);
            Assert.AreEqual(Guid.Parse("f62e08d9-0359-4baa-8af3-08e0d812d6c6"), source.ResourceID);
            Assert.AreEqual(ResourceType.WebSource, source.ResourceType);
            Assert.AreEqual("http://www.webservicex.net/globalweather.asmx", source.Address);
            Assert.AreEqual("/GetCitiesByCountry?CountryName=South%20Africa", source.DefaultQuery);
            Assert.AreEqual("user1234", source.UserName);
            Assert.AreEqual("Password1234", source.Password);
        }
예제 #13
0
 public void WebSourceContructorWithNullXmlExpectedThrowsArgumentNullException()
 {
     var source = new WebSource(null);
 }
예제 #14
0
        ValidationResult CanConnectServer(WebSource source)
        {
            try
            {
                ErrorResultTO errors;
                return new ValidationResult
                {
                    Result = Execute(source, WebRequestMethod.Get, source.DefaultQuery, (string)null, true, out errors)
                };
            }
            catch(WebException wex)
            {
                RaiseError(wex);

                var errors = new StringBuilder();
                Exception ex = wex;
                while(ex != null)
                {
                    errors.AppendFormat("{0} ", ex.Message);
                    ex = ex.InnerException;
                }
                return new ValidationResult
                {
                    IsValid = false,
                    ErrorMessage = errors.ToString()
                };
            }
            finally
            {
                source.DisposeClient();
            }
        }
예제 #15
0
        public void WebSourceToXmlExpectedSerializesProperties()
        {
            var expected = new WebSource
            {
                Address = "http://www.webservicex.net/globalweather.asmx",
                DefaultQuery = "/GetCitiesByCountry?CountryName=US",
                AuthenticationType = AuthenticationType.User,
                UserName = "******",
                Password = "******",
            };

            var xml = expected.ToXml();

            var actual = new WebSource(xml);

            Assert.AreEqual(expected.ResourceType, actual.ResourceType);
            Assert.AreEqual(expected.Address, actual.Address);
            Assert.AreEqual(expected.DefaultQuery, actual.DefaultQuery);
            Assert.AreEqual(expected.UserName, actual.UserName);
            Assert.AreEqual(expected.Password, actual.Password);
            Assert.IsNull(actual.Response);
        }
예제 #16
0
 public void GivenIHaveAWebserviceCallingHttpMaps_Googleapis_ComMapsApiGeocodeJsonSensorTrueAmpAddressAddress()
 {
     var webSourceXML = XmlResource.Fetch("Google_Address_Lookup");
     var webSource = new WebSource(webSourceXML);
     var service = new ServiceModel.Data.WebService { Source = webSource, RequestUrl = webSource.DefaultQuery };
     ErrorResultTO errors;
     WebServices.ExecuteRequest(service, false, out errors);
     ScenarioContext.Current.Add("WebService", service);
 }
예제 #17
0
 public static byte[] Execute(WebSource source, WebRequestMethod method, string relativeUri, byte[] data, bool throwError, out ErrorResultTO errors, string[] headers = null)
 {
     EnsureWebClient(source, headers);
     return Execute(source.Client, string.Format("{0}{1}", source.Address, relativeUri), method, data, throwError, out errors);
 }
예제 #18
0
        public static void EnsureWebClient(WebSource source, IEnumerable<string> headers)
        {
            if(source != null && source.Client != null)
            {
                return;
            }

            if(source != null)
            {
                source.Client = new WebClient();

                if(source.AuthenticationType == AuthenticationType.User)
                {
                    source.Client.Credentials = new NetworkCredential(source.UserName, source.Password);
                }
                source.Client.Headers.Add("user-agent", GlobalConstants.UserAgentString );

                if(headers != null)
                {
                    foreach(var header in headers)
                    {
                        source.Client.Headers.Add(header.Trim());
                    }
                }
            }
        }
예제 #19
0
        public void WebSourcesAssertUserAgentHeaderSet_SetsOtherHeaders()
        {
            var source = new WebSource { Address = "www.foo.bar", AuthenticationType = AuthenticationType.Anonymous };

            WebSources.EnsureWebClient(source, new List<string> { "a:x", "b:e" });

            var client = source.Client;
            var agent = client.Headers["user-agent"];
            Assert.IsNotNull(agent);
            Assert.AreEqual(agent, GlobalConstants.UserAgentString);
            Assert.IsTrue(client.Headers.AllKeys.Contains("a"));
            Assert.IsTrue(client.Headers.AllKeys.Contains("b"));
        }
예제 #20
0
 public void WebSourceContructorWithDefaultExpectedInitializesProperties()
 {
     var source = new WebSource();
     Assert.AreEqual(Guid.Empty, source.ResourceID);
     Assert.AreEqual(ResourceType.WebSource, source.ResourceType);
 }