Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var adapter = new RestAdapter("https://jsonplaceholder.typicode.com/");
            var service = adapter.Create <IUserService>();

            var response = service.GetUsers();

            Console.WriteLine($"Request: {response.ResponseStatus}");
            var listOfUser = response.Data;

            listOfUser.ForEach(Console.WriteLine);

            var response2 = service.GetUser(1);
            var user      = response2.Data;

            Console.WriteLine(user.ToString());
            Console.WriteLine($"Request: {response2.ResponseStatus}");

            var response3 = service.AddUser(new User {
                Name = "minh"
            });

            Console.WriteLine($"Request: {response3.ResponseStatus}");

            response3 = service.UpdateUser(1, new User {
                Name = "minh"
            });
            Console.WriteLine($"Request: {response3.ResponseStatus}");

            response3 = service.DeleteUser(1);
            Console.WriteLine($"Request: {response3.ResponseStatus}");

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var restClient = new RestClient("http://api.openweathermap.org/data/2.5/");

            restClient.Authenticator = new HttpBasicAuthenticator("Default", "32e86d2782c009304019c7b0526d0155");
            restClient.AddDefaultHeader("content-type", "application/json; charset=utf-8");
            restClient.AddDefaultHeader("charset", "utf-8");

            var adapter = new RestAdapter(restClient);
            var service = adapter.Create <IService>();

            var response = service.GetWeatherFollowGeoLocation("16", "108");

            Console.WriteLine($"Request: {response.ResponseStatus}");
            Console.WriteLine(response.Content);

            response = service.GetWeatherFollowId("1905468");
            Console.WriteLine($"Request: {response.ResponseStatus}");
            Console.WriteLine(response.Content);

            response = service.GetWeatherFollowZipCode("70055");
            Console.WriteLine($"Request: {response.ResponseStatus}");
            Console.WriteLine(response.Content);

            response = service.GetWeatherFollowCityName("Danang");
            Console.WriteLine($"Request: {response.ResponseStatus}");
            Console.WriteLine(response.Content);
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            var restClient = new RestClient("http://danabus.vn/data/2/");
            var adapter    = new RestAdapter(restClient);
            var service    = adapter.Create <IBusService>();

            var respone = service.GetBusService();

            Console.WriteLine(respone.ResponseStatus);

            var obj       = respone.Data;
            var xmlString = ObjectToXmlString(obj);

            Console.WriteLine(xmlString);

            var folder = "../../../XmlFile/";

            SaveAsXml(xmlString, folder, "");

            var id        = "12";
            var responeId = service.GetBusServiceId(id);

            Console.WriteLine(responeId.ResponseStatus);

            var objId = JsonConvert.DeserializeObject <BusServiceId>(responeId.Content);

            SaveBusServiceIdtoXml(id, objId, folder);

            Console.ReadKey();
        }
Ejemplo n.º 4
0
        public static bool MachineIsRegistered2()
        {
            RestAdapter            adapter         = new RestAdapter("http://localhost:5400/api/v1/machine");
            IMachine               service         = adapter.Create <IMachine>();
            RestResponse <Machine> machineResponse = service.AutenticateMachine(service.GetMachineIdLocal());
            Machine machine = machineResponse.Data;

            return(false);
        }
        static void SendEmail(string emailString, string content)
        {
            var restClient = new RestClient("https://us17.api.mailchimp.com/3.0/");

            restClient.Authenticator = new HttpBasicAuthenticator("username", ApiKey);
            restClient.AddDefaultHeader("content-type", "application/json");

            var adapter = new RestAdapter(restClient);
            var service = adapter.Create <IService>();

            var email = new Email {
                EmailAddress = emailString, Status = "subscribed"
            };

            SimpleJson.CurrentJsonSerializerStrategy = new SerializerStrategy();
            var responseAddEmail = service.AddEmail(IdList, email);

            var campaign = new
            {
                recipients = new { list_id = IdList },
                type       = "regular",
                settings   = new
                {
                    subject_line = "Only Test 1",
                    reply_to     = "*****@*****.**",
                    from_name    = "minh"
                }
            };
            var responseCreateCampaign = service.CreateCampaign(campaign);

            IdCompaign = JsonConvert.DeserializeObject <Campaign>(responseCreateCampaign.Content).id;

            var responseSetContent = service.SetContent(IdCompaign, new { html = content });

            var responseSendContent = service.SendContent(IdCompaign);

            if (responseAddEmail.ResponseStatus.ToString().Contains("Completed") && responseCreateCampaign.ResponseStatus.ToString().Contains("Completed") && responseSetContent.ResponseStatus.ToString().Contains("Completed") && responseSendContent.StatusCode.ToString().Contains("NoContent"))
            {
                Console.WriteLine("Send: complete");
            }
            else
            {
                Console.WriteLine("Send: error");
                Console.WriteLine($"Add email: {responseAddEmail.ResponseStatus}");
                Console.WriteLine($"Create campaign: {responseCreateCampaign.ResponseStatus}");
                Console.WriteLine($"Set content: {responseSetContent.ResponseStatus}");
                Console.WriteLine($"Send content: {responseSendContent.StatusCode}");
            }
        }
Ejemplo n.º 6
0
        public void PostAutomationTriggerTestWithoutToken()
        {
            PostAutomationTrigger request = new PostAutomationTrigger();

            request.RequestingUser      = "";
            request.ProjectName         = "";
            request.ProjectTeamMembers  = new string[] { };
            request.ServiceLine         = "";
            request.ServiceInstanceName = "";
            request.OfferingName        = "";
            request.Location            = "";
            request.EngagementCode      = "";
            request.Sponsor             = "";
            request.Environment         = "";
            request.Parameters          = new Dictionary <string, string>()
            {
            };
            request.ContentType = "application/json";

            RestAdapter   RestClientWithoutToken = new RestAdapter(CTP_URL);
            IRestResponse response = RestClientWithoutToken.Create(request);

            Assert.That((int)response.StatusCode, Is.EqualTo(401), "Automation Trigger endpoint is not working properly");
        }
Ejemplo n.º 7
0
 public static IMonitoringService GetMonitoringService()
 {
     return(restAdapter.Create <IMonitoringService>());
 }
 public void SetUp()
 {
     adapter = new RestAdapter("http://jordanthoms.apiary.io/");
     service = adapter.Create<IPeopleService>();
 }
Ejemplo n.º 9
0
 public void SetUp()
 {
     restClient = Substitute.For <IRestClient>();
     adapter    = new RestAdapter(restClient);
     client     = adapter.Create <IRestInterface>();
 }
Ejemplo n.º 10
0
 public void SetUp()
 {
     restClient = Substitute.For<IRestClient>();
     adapter = new RestAdapter(restClient);
     client = adapter.Create<IRestInterface>();
 }
Ejemplo n.º 11
0
 public void SetUp()
 {
     adapter = new RestAdapter("http://jordanthoms.apiary.io/");
     service = adapter.Create <IPeopleService>();
 }