コード例 #1
0
        public void ItHandlesInvalidDateParam()
        {
            // Arange
            string personMessagebody = "{\"firstName\":\"Alireza\",\"lastName\":\"Oroumand\",\"id\":\"3fa85f64-5717-4562-b3fc-2c963f66afa6\"}";

            _mockProviderService.Given("There is data")
            .UponReceiving("Valid person Data")
            .With(new ProviderServiceRequest
            {
                Method = HttpVerb.Get,
                Path   = "/api/person/",
                Query  = "id=3fa85f64-5717-4562-b3fc-2c963f66afa6"
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, object>
                {
                    {
                        "Content-Type", "application/json; charset=utf-8"
                    }
                },
                Body = personMessagebody
            });

            // Act
            var result         = APICaller.Call(_mockProviderServiceBaseUri, "3fa85f64-5717-4562-b3fc-2c963f66afa6").GetAwaiter().GetResult();
            var resultBodyText = result.Content.ReadAsStringAsync().GetAwaiter().GetResult();

            // Assert
            Assert.Equal(resultBodyText, personMessagebody);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string url = "http://localhost:52512";

            Console.WriteLine("please send a person id: ");
            string            id     = Console.ReadLine();
            var               result = APICaller.Call(url, id).Result.Content.ReadAsStringAsync().Result;
            PersonResponseDto dto    = JsonConvert.DeserializeObject <PersonResponseDto>(result);

            Console.WriteLine($"First Name: {dto.FirstName}, Last Name: {dto.LastName}");
            Console.ReadKey();
        }
コード例 #3
0
        public LandingPageModel()
        {
            MovieModel obj      = new MovieModel();
            string     response = APICaller.Call("https://api.themoviedb.org/3/tv/1399?api_key=1a9755b22a226ad22bb40fc91e9ed04a", "");

            //should move this to viewmodel?

            try
            {
                obj        = JsonConvert.DeserializeObject <MovieModel>(response);
                Background = new BitmapImage(new Uri("https://image.tmdb.org/t/p/original/" + obj.backdrop_path));
            }
            catch (JsonReaderException e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
コード例 #4
0
        /// <summary>
        /// Create a new Twiddla User, returning the UserID if successful
        /// </summary>
        /// <param name="newusername"></param>
        /// <param name="newpassword"></param>
        /// <param name="displayname"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public static int CreateUser(string newusername, string newpassword, string displayname, string email)
        {
            string endpoint = String.Format(@"http://{0}/API/CreateUser.aspx", GetTwiddlaHost(HttpContext.Current.Request));

            APICaller caller = new APICaller(endpoint);
            caller.Add("username", TwiddlaUsername);
            caller.Add("password", TwiddlaPassword);
            caller.Add("newusername", newusername);
            caller.Add("newpassword", newpassword);
            caller.Add("displayname", displayname);
            caller.Add("email", email);

            if (caller.Call())
            {
                return caller.IntValue;
            }

            throw caller.LastException;
        }
コード例 #5
0
        /// <summary>
        /// Create a new Twiddla Meeting, returning the SessionID if successful
        /// </summary>
        /// <param name="meetingpassword"></param>
        /// <param name="meetingtitle"></param>
        /// <param name="url">For custom URLs.  Leave blank or null for a standard, numbered, meetingID</param>
        /// <returns></returns>
        /// 
        public static int CreateMeeting(string meetingtitle, string meetingpassword, string url)
        {
            string endpoint = String.Format(@"http://{0}/new.aspx", GetTwiddlaHost(HttpContext.Current.Request));

            APICaller caller = new APICaller(endpoint);
            caller.Add("username", TwiddlaUsername);
            caller.Add("password", TwiddlaPassword);
            caller.Add("meetingtitle", meetingtitle);
            caller.Add("meetingpassword", meetingpassword);
            if (!String.IsNullOrEmpty(url))
            {
                caller.Add("url", url);
            }

            if (caller.Call())
            {
                return caller.IntValue;
            }

            throw caller.LastException;
        }
コード例 #6
0
        /*
         * make async
         */
        private void CallToApi(string query)
        {
            try
            {
                string response = APICaller.Call("https://api.themoviedb.org/3/search/movie?api_key=1a9755b22a226ad22bb40fc91e9ed04a", "&query=" + query);
                _resultsModel = JsonConvert.DeserializeObject <ResultsModel>(response);
                Console.WriteLine("response here: " + response);
                Console.WriteLine("results model: " + _resultsModel.results.Count);

                ImageBackground = new BitmapImage(new Uri("https://image.tmdb.org/t/p/original/" + _resultsModel.results[0].backdrop_path));

                _resultsModel.results.ForEach(delegate(Result s)
                {
                    ListResults.Add(s);
                });
                RaisePropertyChanged("ListResults");
            }
            catch (JsonReaderException e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
コード例 #7
0
        public static async Task <bool> DoLogin(string username, string password)
        {
            try
            {
                var methodParam = new ApiParams();
                methodParam.Add("idUsuario", username);
                methodParam.Add("clave", password);

                var userJson = await APICaller.Call("ValidarAccesoMovil", methodParam);

                var user = Models.User.FromJsonToken(userJson);
                if (user == null)
                {
                    return(false);
                }
                Models.Shared.User = user;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #8
0
        /// <summary>
        /// List all snapshots for the supplied sessionID
        /// </summary>
        /// <param name="format"></param>
        /// <param name="sessionID"></param>
        /// <returns></returns>
        public static string ListSnapshots(ResponseFormat format, int sessionID)
        {
            string endpoint = String.Format(@"http://{0}/API/ListSnapshots.aspx", GetTwiddlaHost(HttpContext.Current.Request));

            APICaller caller = new APICaller(endpoint);
            caller.Add("username", TwiddlaUsername);
            caller.Add("password", TwiddlaPassword);
            caller.Add("format", format.ToString().ToLower());
            if (sessionID > 0)
            {
                caller.Add("sessionid", sessionID);
            }

            if (caller.Call())
            {
                return caller.Html;
            }

            throw caller.LastException;
        }