Inheritance: Resource, IDisposable
コード例 #1
0
ファイル: WebServiceSteps.cs プロジェクト: ndubul/Chillas
 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
ファイル: WebSourcesTests.cs プロジェクト: Robin--/Warewolf
        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
ファイル: WebSourceTests.cs プロジェクト: Robin--/Warewolf
 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
ファイル: WebSourcesTests.cs プロジェクト: Robin--/Warewolf
        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
ファイル: WebSourceTests.cs プロジェクト: Robin--/Warewolf
        public void WebSourceDisposeExpectedDisposesAndNullsClient()
        {
            var source = new WebSource { Client = new WebClient() };

            Assert.IsNotNull(source.Client);
            source.Dispose();
            Assert.IsNull(source.Client);
        }
コード例 #9
0
ファイル: WebSourcesTests.cs プロジェクト: Robin--/Warewolf
        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
ファイル: WebSourcesTests.cs プロジェクト: Robin--/Warewolf
        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
        }
コード例 #11
0
        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
ファイル: WebSourceTests.cs プロジェクト: Robin--/Warewolf
        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
ファイル: WebSourceTests.cs プロジェクト: Robin--/Warewolf
 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
ファイル: WebSourceTests.cs プロジェクト: Robin--/Warewolf
        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
ファイル: WebServiceSteps.cs プロジェクト: ndubul/Chillas
 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
ファイル: WebSourcesTests.cs プロジェクト: Robin--/Warewolf
        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
ファイル: WebSourceTests.cs プロジェクト: Robin--/Warewolf
 public void WebSourceContructorWithDefaultExpectedInitializesProperties()
 {
     var source = new WebSource();
     Assert.AreEqual(Guid.Empty, source.ResourceID);
     Assert.AreEqual(ResourceType.WebSource, source.ResourceType);
 }