Пример #1
0
    public string Translate(string sentence, string srcLang, string dstLang)
    {
        String transText = String.Empty;

        try
        {     // Call Web Service Operation
            var service = new SoapService();
            // TODO initialize WS operation arguments here
            string appId         = "F4E6E0444F32B660BED9908E9744594B53D2E864";
            string text          = sentence;
            string from          = srcLang;
            string to            = dstLang;
            string contentType   = "text/html";
            string category      = "general";
            string reservedFlags = "";

            // TODO process  result here
            transText = service.Translate(appId, text, from, to, contentType, category, reservedFlags);
        }
        catch (Exception ex)
        {
            return(ex.Message);
        }

        return(transText);
    }
Пример #2
0
 private void FibonacciButton_Click(object sender, EventArgs e)
 {
     if (fibonacciValid)
     {
         Form waitForm = new WaitForm(this);
         waitForm.Show(this);
         string      body           = @"<Fibonacci xmlns=""http://chanhduong.org/""><n>" + n + "</n></Fibonacci>";
         SoapService soapService    = new SoapService(ChanhDuongURL);
         string      textMessage    = "";
         string      captionMessage = "";
         try
         {
             soapService.SendRequest(body).Wait();
             FibonacciResponse result = (FibonacciResponse)SerializerSoapXml.Deserialize(typeof(FibonacciResponse), soapService.response);
             textMessage    = result.FibonacciResult;
             captionMessage = "Fibonacci of " + n;
         }
         catch (Exception ex)
         {
             textMessage    = ex.Message;
             captionMessage = "Error";
         }
         finally
         {
             waitForm.Close();
             MessageBox.Show(textMessage, captionMessage, MessageBoxButtons.OK);
         }
     }
     else
     {
         MessageBox.Show("N is blank!", "Info", MessageBoxButtons.OK);
     }
 }
Пример #3
0
        public void GetSoapById_ExpectingSoap_ResultShouldReturnSoapViewModel()
        {
            // arrange
            var mockSoapRepository = new Mock <ISoapRepository>();

            var mockSoap = new Soap()
            {
                Id           = Guid.NewGuid(),
                Brand        = "Soap Brand 1",
                Edition      = "Soap Edition 1",
                Description  = "Soap Description 1",
                UnitPrice    = 20,
                UnitQuantity = 100,
                URL          = "img/soap1.jpeg"
            };

            mockSoapRepository.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(mockSoap);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Soap, SoapViewModel>();
            });

            var mapper = config.CreateMapper();

            // act
            var soapService = new SoapService(mockSoapRepository.Object, mapper);
            var result      = soapService.GetSoapById(Guid.NewGuid());

            // assert
            result.Should().BeOfType <SoapViewModel>();
        }
Пример #4
0
        private string Translate(string sourceText, string sourceLang, string targetLang)
        {
            try
            {
                string translatedText;

                using (var translatorClient = new SoapService())
                {
                    string fromLang = sourceLang == Lang.Unknown ? "" : sourceLang;
                    string toLang   = targetLang == Lang.Unknown ? Lang.English : targetLang;

                    try
                    {
                        translatedText = translatorClient.Translate(
                            appId: AppId,
                            text: sourceText,
                            from: $"{fromLang}",
                            to: $"{toLang}");
                    }
                    catch (Exception)
                    {
                        translatedText =
                            "[ Cognitive Services Reply: you have reached your translations limit for today ]";
                    }
                }

                return(translatedText);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                throw;
            }
        }
Пример #5
0
 private void XmlToJsonButton_Click(object sender, EventArgs e)
 {
     if (xmlValid)
     {
         Form waitForm = new WaitForm(this);
         waitForm.Show(this);
         string      xmlToSend      = xml?.Replace("<", "&lt;");
         string      body           = @"<XmlToJson xmlns=""http://chanhduong.org/""><xml>" + xmlToSend + "</xml></XmlToJson>";
         SoapService soapService    = new SoapService(ChanhDuongURL);
         string      textMessage    = "";
         string      captionMessage = "";
         try
         {
             soapService.SendRequest(body).Wait();
             XmlToJsonResponse result = (XmlToJsonResponse)SerializerSoapXml.Deserialize(typeof(XmlToJsonResponse), soapService.response);
             textMessage    = result.XmlToJsonResult;
             captionMessage = "Json";
         }
         catch (Exception ex)
         {
             textMessage    = ex.Message;
             captionMessage = "Error";
         }
         finally
         {
             waitForm.Close();
             MessageBox.Show(textMessage, captionMessage, MessageBoxButtons.OK);
         }
     }
     else
     {
         MessageBox.Show("Xml is blank!", "Info", MessageBoxButtons.OK);
     }
 }
Пример #6
0
        public void SoapServiceTest()
        {
            SoapService webServicesCall = new SoapService();

            People people = new People()
            {
                Gender = "Male",
                Name   = "Radamel Falcao",
                Image  = "https://informe360.com/deportes/wp-content/uploads/2017/02/falcao-500x500_c.jpg"
            };

            var    responseAddPeople = webServicesCall.AddPeople(people);
            string key = responseAddPeople.FirebaseID;

            var responseGetPeople     = webServicesCall.GetPeople();
            var responseGetByIDPeople = webServicesCall.GetByIDPeople(key);
            var responseUpdatePeople  = webServicesCall.UpdatePeople(key, people);
            var responseRemovePeople  = webServicesCall.RemovePeople(key);

            Assert.IsNotNull(responseAddPeople);
            Assert.AreEqual("OK", responseAddPeople.Status);
            Assert.IsNotNull(responseGetPeople);
            Assert.IsNotNull(responseGetByIDPeople);
            Assert.IsNotNull(responseUpdatePeople);

            // TODO: Pending to check.
            Assert.AreEqual(null, responseRemovePeople);
        }
Пример #7
0
 // Constructor
 protected Translator()
 {
     if (client == null)
     {
         client = new SoapService();
         client.TranslateCompleted += client_TranslateCompleted;
     }
 }
Пример #8
0
        public MainPage()
        {
            InitializeComponent();

            SoapService ss = new SoapService();
            var         v  = ss.FindApplicants(new FindApplicantsSoapRequest()
            {
                Forenames = "a", Surname = "a"
            });
        }
Пример #9
0
        public void GetSoaps_NotExistingSoaps_ResultShouldBeEmpty()
        {
            // arrange
            var mockSoapRepository = new Mock <ISoapRepository>();
            var mockMapper         = new Mock <IMapper>();

            // act
            var soapService = new SoapService(mockSoapRepository.Object, mockMapper.Object);
            var result      = soapService.GetSoaps();

            // assert
            result.Soaps.Should().BeEmpty();
        }
Пример #10
0
        public ActionResult Index(SearchViewModel postModel)
        {
            var result       = SoapService.ExecuteGetPath(postModel.StartStation, postModel.DestinationStation, postModel.Time.ToString());
            var stringResult = this.PrepareOutput(result.Stations.ToDictionary(x => x.Station, y => y.Time), result.TotalJourneyTime);
            var viewModel    = new SearchViewModel()
            {
                Stations   = this.StationsForView,
                Result     = stringResult,
                TrainLines = this.TrainLines
            };

            return(View(viewModel));
        }
Пример #11
0
        public void GetSoapById_NotExpectingSoap_ResultShouldBeNull()
        {
            // arrange
            var mockSoapRepository = new Mock <ISoapRepository>();
            var mockMapper         = new Mock <IMapper>();

            // act
            var soapService = new SoapService(mockSoapRepository.Object, mockMapper.Object);
            var result      = soapService.GetSoapById(Guid.NewGuid());

            // assert
            result.Should().BeNull();
        }
Пример #12
0
        public void GetSoaps_NotExistingSoaps_ResultShouldBeOfTypeSoapListViewModel()
        {
            // arrange
            var mockSoapRepository = new Mock <ISoapRepository>();
            var mockMapper         = new Mock <IMapper>();

            // act
            var soapService = new SoapService(mockSoapRepository.Object, mockMapper.Object);
            var result      = soapService.GetSoaps();

            // arrange
            result.Should().BeOfType(typeof(SoapListViewModel));
        }
Пример #13
0
        static void FuzzService(SoapService service)
        {
            Console.WriteLine("Fuzzing service: " + service.Name);

            foreach (SoapPort port in service.Ports)
            {
                Console.WriteLine("Fuzzing " + port.ElementType.Split(':')[0] + "port: " + port.Name);
                SoapBinding binding = _wsdl.Bindings.Single(b => b.Name == port.Binding.Split(':')[1]);
                if (binding.IsHTTP)
                {
                    FuzzHttpPort(binding);
                }
                else
                {
                    FuzzSoapPort(binding);
                }
            }
        }
Пример #14
0
        public void GetSoaps_ExistingSoaps_ResultShouldBeTwoSoaps()
        {
            // arrance
            var mockSoapRepository = new Mock <ISoapRepository>();
            var mockedSoaps        = new List <Soap>
            {
                new Soap
                {
                    Id           = Guid.NewGuid(),
                    Brand        = "Soap Brand 1",
                    Edition      = "Soap Edition 1",
                    Description  = "Soap Description 1",
                    UnitPrice    = 20,
                    UnitQuantity = 100,
                    URL          = "img/soap1.jpeg"
                },
                new Soap
                {
                    Id           = Guid.NewGuid(),
                    Brand        = "Soap Brand 2",
                    Edition      = "Soap Edition 2",
                    Description  = "Soap Description 2",
                    UnitPrice    = 21,
                    UnitQuantity = 100,
                    URL          = "img/soap2.jpeg"
                }
            };

            mockSoapRepository.Setup(x => x.GetAll()).Returns(mockedSoaps);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Soap, SoapViewModel>();
            });
            var mapper = config.CreateMapper();

            // act
            var soapService = new SoapService(mockSoapRepository.Object, mapper);
            var result      = soapService.GetSoaps();

            // assert
            result.Soaps.Should().HaveCount(2);
        }
Пример #15
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public PeopleController()
 {
     webServicesCall = new SoapService();
 }
Пример #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SoapOperation"/> class.
 /// </summary>
 /// <param name="service">The service of the operation.</param>
 /// <param name="action">The action of the operation.</param>
 public SoapOperation(SoapService service, SoapAction action)
 {
     this.Service = service;
     this.Action  = action;
 }
Пример #17
0
 internal OperationBase(ConnectionCredentials connectionCredentials)
 {
     _soapService = new SoapService(connectionCredentials);
 }
Пример #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Body"/> class.
 /// </summary>
 /// <param name="service">The service for this request.</param>
 /// <param name="action">The action for this request.</param>
 public Body(SoapService service, SoapAction action)
 {
     this.Action  = action;
     this.Service = service;
 }