static void Main () { TestWebService svc = new TestWebService (); Assert.AreEqual ("Hello World", svc.HelloWorld (), "#1"); string url = "http://127.0.0.1:8081/TestWebService.asmx?WSDL"; DiscoveryClientProtocol dcp = new DiscoveryClientProtocol (); using (Stream s = dcp.Download (ref url)) { ServiceDescription sd = ServiceDescription.Read (s); #if NET_2_0 Assert.AreEqual (2, sd.Bindings.Count, "#A1"); Assert.AreEqual ("TestWebServiceSoap", sd.Bindings [0].Name, "#A2"); Assert.AreEqual ("http://tempuri.org/:TestWebServiceSoap", sd.Bindings [0].Type.ToString (), "#A3"); Assert.AreEqual ("TestWebServiceSoap12", sd.Bindings [1].Name, "#A4"); Assert.AreEqual ("http://tempuri.org/:TestWebServiceSoap", sd.Bindings [1].Type.ToString (), "#A5"); #else Assert.AreEqual (1, sd.Bindings.Count, "#A1"); Assert.AreEqual ("TestWebServiceSoap", sd.Bindings [0].Name, "#A2"); Assert.AreEqual ("http://tempuri.org/:TestWebServiceSoap", sd.Bindings [0].Type.ToString (), "#A3"); #endif Assert.AreEqual (1, sd.PortTypes.Count, "#B1"); Assert.AreEqual ("TestWebServiceSoap", sd.PortTypes [0].Name, "#B2"); } }
public void TestGetAlbumXml() { var service = new TestWebService(); var res = service.GetAlbumByIdXml(5); Assert.IsInstanceOfType(res, typeof(Album)); }
public void TestGetAlbumJson() { var service = new TestWebService(); var res = service.GetAlbumByIdJson(5); Assert.IsInstanceOfType(res, typeof(string)); }
public void TestGetUserXml() { var service = new TestWebService(); var res = service.GetUserByIdXml(2); Assert.IsInstanceOfType(res, typeof(User)); }
public void TestRepoException() { var repo = new Mock <IRepository>(); repo.Setup(r => r.GetUsers()).Throws(new Exception("Error")); var service = new TestWebService(repo.Object, new CryptographerMP5()); var res = service.GetUsersXml(); }
public void Add_WebService_Receives() { var custWebService = new TestWebService(); var c = new StringCalculator(null, custWebService); try { c.Add("1,-2"); } catch { } Assert.IsTrue(custWebService.message.Contains("Negatives")); }
public void TestWebService_Execute_WebService_NotFound_ExpectHasError() { var serializer = new Dev2JsonSerializer(); var sut = new TestWebService(); var result = sut.Execute(new Dictionary <string, StringBuilder>(), new Workspace(Guid.Empty)); var executeMessage = serializer.Deserialize <ExecuteMessage>(result); Assert.IsNotNull(result); Assert.IsTrue(executeMessage.HasError); Assert.IsTrue(executeMessage.Message.Contains("Parameter name: WebService")); }
protected void Button1_Click(object sender, EventArgs e) { TestWebService web = new TestWebService(); BankService bs = new BankService(); bs.checkcard( bool check=web.CardDetails(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text), TextBox3.Text, TextBox4.Text, TextBox5.Text); if (check) { TextBox6.Text = "payment Accepted"; } else { TextBox6.Text = "Payment not accepted"; } }
public void TestWebService_Execute_FormDataParameters_Null_ExpectSuccess() { var serializer = new Dev2JsonSerializer(); var mockWebServices = new Mock <IWebServices>(); var sut = new TestWebService { WebServices = mockWebServices.Object, ResourceCatalogue = new Mock <IResourceCatalog>().Object }; var mockWebClientWrapper = new Mock <IWebClientWrapper>(); var mockWebSource = new Mock <IWebSource>(); mockWebSource.Setup(o => o.Address) .Returns("http://address.co.za/examples"); mockWebSource.Setup(o => o.Client) .Returns(mockWebClientWrapper.Object); //Ensure this is not instantiated here mockWebSource.Setup(o => o.AuthenticationType) .Returns(AuthenticationType.Anonymous); var webService = new Warewolf.Core.WebServiceDefinition() { Source = new WebServiceSourceDefinition(mockWebSource.Object), Headers = new List <INameValue> { new NameValue("Content-Type", "multipart/form-data") }, FormDataParameters = null }; var values = new Dictionary <string, StringBuilder> { { "WebService", webService.SerializeToJsonStringBuilder() } }; var result = sut.Execute(values, null); var executeMessage = serializer.Deserialize <ExecuteMessage>(result); Assert.IsNotNull(result); Assert.IsFalse(executeMessage.HasError, "FormDataParameters can be null"); Assert.IsFalse(executeMessage.Message.ToString().Contains("Value cannot be null.\r\nParameter name: source")); mockWebServices.Verify(o => o.TestWebService(It.IsAny <WebService>()), Times.Once, "Some request do not set FormDataParameters and hence it is not required field"); mockWebSource.Verify(o => o.Client, Times.Never); }
public void TestCryptoException() { var repo = new Mock <IRepository>(); repo.Setup(r => r.GetUsers()).Returns(new User[] { new User() { id = 1, name = "test" } }); var crypto = new Mock <ICryptographer>(); crypto.Setup(c => c.Encrypt(It.IsAny <string>())).Throws(new Exception("Error")); var service = new TestWebService(repo.Object, crypto.Object); var res = service.GetUsersXml(); }
public FtpServiceTests() { _mockLog = Substitute.For <ICakeLog>(); _testSettings = new FtpDeploySettings() { FtpUri = "ftp://www.test.com", FtpUserName = "******", FtpPassword = "******", ArtifactsPath = "./TestArtifacts" }; _testWebService = Substitute.For <IWebService>(); var testWebService = new TestWebService(); _testWebService.ListDirectoryDetails("ftp://www.test.com", Arg.Any <string>(), Arg.Any <string>()) .Returns(testWebService.ListDirectoryDetails("ftp://www.test.com", null, null)); _testWebService.ListDirectoryDetails("ftp://www.test.com/testDirectory", Arg.Any <string>(), Arg.Any <string>()) .Returns(testWebService.ListDirectoryDetails("ftp://www.test.com/testDirectory", null, null)); }
public void TestWebService_Execute_Source_NotFound_ExpectHasError() { var serializer = new Dev2JsonSerializer(); var sut = new TestWebService(); var webService = new WebServiceDefinition(); var values = new Dictionary <string, StringBuilder> { { "WebService", webService.SerializeToJsonStringBuilder() } }; var result = sut.Execute(values, null); var executeMessage = serializer.Deserialize <ExecuteMessage>(result); Assert.IsNotNull(result); Assert.IsTrue(executeMessage.HasError); Assert.IsTrue(executeMessage.Message.Contains("Parameter name: source")); }
static int Main () { Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US"); TestWebService svc = new TestWebService (); Assert.AreEqual ("Hello World", svc.HelloWorld (), "#A"); HttpWebRequest request = (HttpWebRequest) WebRequest.Create ("http://localhost:8081/Default.aspx"); request.Method = "GET"; try { HttpWebResponse response = (HttpWebResponse) request.GetResponse (); using (StreamReader sr = new StreamReader (response.GetResponseStream (), Encoding.UTF8, true)) { string result = sr.ReadToEnd (); Assert.IsTrue (result.IndexOf ("Master Web Page") != -1, "#B1:" + result); Assert.IsTrue (result.IndexOf ("<h1 class=\"header\">Welcome to Mono XSP!</h1>") != -1, "#B2:" + result); Assert.IsTrue (result.IndexOf ("<span id=\"ctl00_ContentPlaceHolder1_Label1\">Page Loaded</span>") != -1, "#B3:" + result); } response.Close (); } catch (WebException ex) { HttpWebResponse response = (HttpWebResponse) ex.Response; if (response != null) { using (StreamReader sr = new StreamReader (response.GetResponseStream ())) { Console.WriteLine (sr.ReadToEnd ()); } } return 1; } request = (HttpWebRequest) WebRequest.Create ("http://localhost:8081/Index.aspx"); request.Method = "GET"; try { HttpWebResponse response = (HttpWebResponse) request.GetResponse (); using (StreamReader sr = new StreamReader (response.GetResponseStream (), Encoding.UTF8, true)) { string result = sr.ReadToEnd (); Assert.IsTrue (result.IndexOf ("<title>OK</title>") != -1, "#C1:" + result); Assert.IsTrue (result.IndexOf ("<p>fine</p>") != -1, "#C2:" + result); } response.Close (); } catch (WebException ex) { HttpWebResponse response = (HttpWebResponse) ex.Response; if (response != null) { using (StreamReader sr = new StreamReader (response.GetResponseStream ())) { Console.WriteLine (sr.ReadToEnd ()); } } return 2; } request = (HttpWebRequest) WebRequest.Create ("http://localhost:8081/index.htm"); request.Method = "GET"; try { HttpWebResponse response = (HttpWebResponse) request.GetResponse (); using (StreamReader sr = new StreamReader (response.GetResponseStream (), Encoding.UTF8, true)) { string result = sr.ReadToEnd (); Assert.IsTrue (result.IndexOf ("<title>Index</title>") != -1, "#D1" + result); } response.Close (); } catch (WebException ex) { HttpWebResponse response = (HttpWebResponse) ex.Response; if (response != null) { using (StreamReader sr = new StreamReader (response.GetResponseStream ())) { Console.WriteLine (sr.ReadToEnd ()); } } return 3; } request = (HttpWebRequest) WebRequest.Create ("http://localhost:8081/Start.aspx"); request.Method = "GET"; try { HttpWebResponse response = (HttpWebResponse) request.GetResponse (); using (StreamReader sr = new StreamReader (response.GetResponseStream (), Encoding.UTF8, true)) { string result = sr.ReadToEnd (); Assert.IsTrue (result.IndexOf ("<p>Start</p>") != -1, "#E1" + result); } response.Close (); } catch (WebException ex) { HttpWebResponse response = (HttpWebResponse) ex.Response; if (response != null) { using (StreamReader sr = new StreamReader (response.GetResponseStream ())) { Console.WriteLine (sr.ReadToEnd ()); } } return 4; } request = (HttpWebRequest) WebRequest.Create ("http://localhost:8081/DoesNotExist.aspx"); request.Method = "GET"; try { request.GetResponse (); Assert.Fail ("#F1"); } catch (WebException ex) { Assert.AreEqual (typeof (WebException), ex.GetType (), "#F2"); Assert.IsNull (ex.InnerException, "#F3"); Assert.IsNotNull (ex.Message, "#F4"); Assert.AreEqual (WebExceptionStatus.ProtocolError, ex.Status, "#F5"); HttpWebResponse response = (HttpWebResponse) ex.Response; Assert.IsNotNull (response, "#F6"); Assert.AreEqual (HttpStatusCode.NotFound, response.StatusCode, "#F7"); using (StreamReader sr = new StreamReader (response.GetResponseStream ())) { string result = sr.ReadToEnd (); Assert.IsTrue (result.IndexOf ("The resource cannot be found.") != -1, "#F8:" + result); Assert.IsTrue (result.IndexOf ("/DoesNotExist.aspx") != -1, "#F9:" + result); } } return 0; }
public void TestWebService_Execute_FormDataParameters_NotNull_ExpectSuccess() { var testFileKey = "testFileKey"; var testFileName = "testFileName"; var testFileContent = "this can be any file type parsed into base64 string"; var testFileContentBytes = testFileContent.ToBytesArray(); var testFileContentBase64 = testFileContentBytes.ToBase64String(); var serializer = new Dev2.Communication.Dev2JsonSerializer(); var mockWebServices = new Mock <IWebServices>(); var sut = new TestWebService { WebServices = mockWebServices.Object, ResourceCatalogue = new Mock <IResourceCatalog>().Object }; var mockWebClientWrapper = new Mock <IWebClientWrapper>(); var mockWebSource = new Mock <IWebSource>(); mockWebSource.Setup(o => o.Address) .Returns("http://address.co.za/examples"); mockWebSource.Setup(o => o.Client) .Returns(mockWebClientWrapper.Object); //Ensure this is not instanciated here mockWebSource.Setup(o => o.AuthenticationType) .Returns(AuthenticationType.Anonymous); var webService = new Warewolf.Core.WebServiceDefinition() { Source = new WebServiceSourceDefinition(mockWebSource.Object), Headers = new List <INameValue> { new NameValue("Content-Type", "multipart/form-data") }, IsManualChecked = false, IsFormDataChecked = true, FormDataParameters = new List <IFormDataParameters> { new FormDataConditionExpression { Key = testFileKey, Cond = new FormDataConditionFile { FileBase64 = testFileContentBase64, FileName = testFileName } }.ToFormDataParameter() } }; var values = new Dictionary <string, StringBuilder> { { "WebService", serializer.SerializeToBuilder(webService) } }; var result = sut.Execute(values, null); var executeMessage = serializer.Deserialize <ExecuteMessage>(result); Assert.IsNotNull(result); Assert.IsFalse(executeMessage.HasError); var message = executeMessage.Message.ToString(); Assert.IsTrue(message.Contains("\"Headers\":[{\"$id\":\"2\",\"$type\":\"Dev2.Common.Interfaces.NameValue, Dev2.Common.Interfaces\",\"Name\":\"Content-Type\",\"Value\":\"multipart/form-data\"}]")); Assert.IsTrue(message.Contains("\"FileName\":\"testFileName\",\"ContentType\":null,\"FileBase64\":\"dGhpcyBjYW4gYmUgYW55IGZpbGUgdHlwZSBwYXJzZWQgaW50byBiYXNlNjQgc3RyaW5n\",\"Key\":\"testFileKey\"")); Assert.IsTrue(message.Contains("\"IsFormDataChecked\":true,\"IsUrlEncodedChecked\":false,\"IsManualChecked\":false,")); mockWebServices.Verify(o => o.TestWebService(It.IsAny <WebService>()), Times.Once); mockWebSource.Verify(o => o.Client, Times.Never); }