Exemplo n.º 1
0
        public async Task RequestIsSerializedCorrectly()
        {
            const string username = "******";
            const string token    = "token";

            var handler = new DynamicHttpMessageHandler(async(req, ct) =>
            {
                Assert.Equal(HttpMethod.Post, req.Method);

                Assert.Null(req.Headers.Authorization);

                Assert.NotNull(req.Headers.UserAgent);
                var ua = Assert.Single(req.Headers.UserAgent);
                Assert.StartsWith("thingsmobile-dotnet/", ua.ToString());

                Assert.Equal("/services/business-api/simList", req.RequestUri.AbsolutePath);
                Assert.Empty(req.RequestUri.Query);

                Assert.NotNull(req.Content);
                Assert.IsAssignableFrom <FormUrlEncodedContent>(req.Content);

                var expectedBody = $"username={username}&token={token}";
                var actualBody   = await req.Content.ReadAsStringAsync();
                Assert.Equal(expectedBody, actualBody);

                return(new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.OK,
                    Content = new StringContent(await TestSamples.GetSimListResponseAsync(), Encoding.UTF8, "text/xml")
                });
            });
            var httpClient = new HttpClient(handler);

            var options = new ThingsMobileClientOptions
            {
                Username = username,
                Token    = token,
            };
            var client   = new ThingsMobileClient(options, httpClient);
            var response = await client.ListSimCardsAsync();

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.True(response.IsSuccessful);
            Assert.Null(response.Error);
            Assert.NotNull(response.Resource);
            Assert.True(response.Resource.IsSuccess);
            var sim = Assert.Single(response.Resource.Sims);

            Assert.Equal("447937557899", sim.Msisdn);
        }
Exemplo n.º 2
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var options = new ThingsMobileClientOptions
            {
                Username = "******",
                Token    = "your-token-here"
            };
            var client = new ThingsMobileClient(options);

            var response = await client.ListSimCardsAsync();

            var simcards = response.Resource;

            foreach (var sim in simcards.Sims)
            {
                Console.WriteLine($"MSISDN: {sim.Msisdn}, Name: {sim.Name}, Tag: {sim.Tag}, Status: {sim.Status}");
            }
        }