Esempio n. 1
0
        public async Task CreateUserWithBadData()
        {
            swaggerClient client = new swaggerClient(baseUrl, httpClient);

            CreateUserCommand command = new CreateUserCommand()
            {
                FirstName    = "Some",
                MiddleName   = "Tandem",
                LastName     = "User",
                PhoneNumber  = "not a phone number",
                EmailAddress = $"{Guid.NewGuid()}@foo.bar"
            };

            ApiException phoneNumberException = await Assert.ThrowsExceptionAsync <ApiException>(
                () => client.UsersAsync(command));

            command.PhoneNumber  = "222-333-4444";
            command.EmailAddress = "not an email";

            ApiException emailException = await Assert.ThrowsExceptionAsync <ApiException>(
                () => client.UsersAsync(command));

            Assert.AreEqual(400, phoneNumberException.StatusCode);
            Assert.AreEqual(400, emailException.StatusCode);
        }
 public IncomingModel(swaggerClient client, GitHubClient github, SlaOptions slaOptions, ILogger <IncomingModel> logger)
 {
     _client    = client;
     _github    = github;
     SlaOptions = slaOptions;
     _logger    = logger;
 }
        public async Task <IEnumerable <Product> > GetRecommendation(string ProductID)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(mlServiceURL);
            httpClient.DefaultRequestHeaders.Authorization
                = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", mlServiceBearerToken);
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var response = await httpClient.PostAsJsonAsync <ProductInfo>(mlServiceURL, new ProductInfo()
            {
                product_id = ProductID
            });

            response.EnsureSuccessStatusCode();

            var jString = await response.Content.ReadAsStringAsync();

            if (jString.Contains("RDD is empty"))
            {
                return new Product[] { }
            }
            ;

            var strippedString = JsonConvert.DeserializeObject(jString).ToString();
            var jsonstring     = JObject.Parse(strippedString);
            var products       = jsonstring.GetValue("related_products");

            swaggerClient svcClient = new swaggerClient(productAPIServiceURL, new System.Net.Http.HttpClient());

            return(await svcClient.GetProductsAsync(products.Select(x => x.ToString())));
        }
    }
Esempio n. 4
0
        static async Task Main(string[] args)
        {
            var http   = new HttpClient();
            var client = new swaggerClient("http://localhost:5001", http);

            var products = await client.ProductsAllAsync(new ProductFilter());

            foreach (var product in products)
            {
                System.Console.WriteLine(product.Name);
            }

            System.Console.WriteLine("------------");

            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                .Build();

            var products_client = new ProductsClient(configuration);

            var pp = products_client.GetProducts();

            foreach (var product in pp.Products)
            {
                System.Console.WriteLine(product.Name);
            }
        }
Esempio n. 5
0
        static async Task Main(string[] args)
        {
            // Hinzufügen / Dienstverweis / swagger.json - URL imported

            const string  endPoint = "https://localhost:44332/";
            swaggerClient client   = new swaggerClient(endPoint, new HttpClient());

            (await client.EventsAsync()).ToList().ForEach(x => Console.WriteLine(x));
        }
Esempio n. 6
0
        public async Task SearchForNonExistingUser()
        {
            swaggerClient client = new swaggerClient(baseUrl, httpClient);

            ApiException <ProblemDetails> exception
                = await Assert.ThrowsExceptionAsync <ApiException <ProblemDetails> >(
                      () => client.Users2Async($"{Guid.NewGuid()}@foo.bar"));

            Assert.AreEqual(404, exception.StatusCode);
        }
Esempio n. 7
0
        static async Task Main(string[] args)
        {
            var client = new swaggerClient("https://localhost:44380", new HttpClient());
            var data   = await client.CourseAllAsync();

            foreach (var item in data)
            {
                Console.WriteLine(item.Title);
            }
        }
        static async Task Run()
        {
            var client    = new swaggerClient("https://localhost:5001/", new System.Net.Http.HttpClient());
            var forecasts = await client.WeatherForecastAsync();

            foreach (var forecast in forecasts)
            {
                Console.WriteLine(forecast.Summary);
            }
        }
Esempio n. 9
0
        public SwaggerClientWrapper(
            IHttpClientFactory httpClientFactory,
            IConfiguration configuration)
        {
            _httpClientFactory = httpClientFactory;
            _configuration     = configuration;

            _client = new swaggerClient(
                _configuration["Api:BaseUrl"],
                _httpClientFactory.CreateClient(name: nameof(SwaggerClientWrapper)));
        }
Esempio n. 10
0
        static async Task Main(string[] args)
        {
            var httpclient = new swaggerClient("https://localhost:44324/", new HttpClient());

            var AllCourse = await httpclient.CourseAllAsync();

            foreach (var Course in AllCourse)
            {
                Console.WriteLine(Course.Title);
            }
        }
Esempio n. 11
0
        static async Task Main(string[] args)
        {
            var http = new HttpClient();

            var client   = new swaggerClient("https://localhost:5001", http);
            var contacts = await client.ContactAllAsync();

            foreach (var c in contacts)
            {
                Console.WriteLine($"{c.FirstName} {c.LastName}");
            }
        }
Esempio n. 12
0
        public IntegrationTests(ApiFixture fixture, ITestOutputHelper output)
        {
            sut    = fixture.PostmanCollection(output);
            api    = fixture.Api;
            client = fixture.ApiClient;

            variables = new ImmutableVariableContext(new
            {
                baseUrl = api.BaseAddress?.ToString().Trim('/') ?? "http://localhost:5042"
            });

            folder = sut.FindFolder("Tests");
        }
Esempio n. 13
0
        private static async Task RemoteApiCall2()
        {
            const string BASE_URL = "https://api4all.azurewebsites.net";

            using (var httpClient = new HttpClient())
            {
                var client = new swaggerClient(BASE_URL, httpClient);
                var items  = await client.StudentsAllAsync();

                foreach (var i in items)
                {
                    Console.WriteLine($"{i.StudentId}\t{i.FirstName}\t{i.LastName}\t{i.School}");
                }
            }
        }
Esempio n. 14
0
        public async Task <IEnumerable <Product> > GetRecommendation(string UserID)
        {
            var _recommendations = await this.ObjectCollection.FindAsync(new GenericSpecification <user_recommendation>(x => x.user_id == int.Parse(UserID)));

            if (_recommendations != null && _recommendations.product_ids.Length > 0)
            {
                using (var httpClient = new HttpClient())
                {
                    swaggerClient swaggerClient = new swaggerClient(productAPIServiceURL, httpClient);
                    return(await swaggerClient.GetProductsAsync(_recommendations.product_ids));
                }
            }
            else
            {
                return(new Product[] { });
            }
        }
Esempio n. 15
0
        public async Task <IEnumerable <Product> > GetRecommendation(string UserID)
        {
            var _recommendations = _cosmosStore.Query().Where(x => x.user_id == UserID).ToArray();

            if (_recommendations.Length > 0)
            {
                using (var httpClient = new HttpClient())
                {
                    swaggerClient swaggerClient = new swaggerClient(productAPIServiceURL, httpClient);
                    return(await swaggerClient.GetProductsAsync(_recommendations[0].product_ids));
                }
            }
            else
            {
                return(new Product[] { });
            }
        }
Esempio n. 16
0
        public async Task <IEnumerable <Product> > GetHistory(string UserID)
        {
            var _history = _cosmosStore.Query().Where(x => x.user_id == UserID).SelectMany(p => p.purchased_items).Distinct().ToArray();

            if (_history.Length > 0)
            {
                using (var httpClient = new HttpClient())
                {
                    swaggerClient swaggerClient = new swaggerClient(productAPIServiceURL, httpClient);
                    return(await swaggerClient.GetProductsAsync(_history));
                }
            }
            else
            {
                return(new Product[] { });
            }
        }
Esempio n. 17
0
        static async Task Main(string[] args)
        {
            var http   = new HttpClient();
            var client = new swaggerClient("http://localhost:5000/", http);
            var result = await client.WeatherForecastAsync(1);

            foreach (var item in result)
            {
                Console.WriteLine($"{item.Date}, {item.TemperatureF}, {item.Summary}");
            }
            Console.WriteLine("Hello World!");

            var result2 = await client.GetLenAsync(3);

            foreach (var item in result2)
            {
                Console.WriteLine($"{item.Date}, {item.TemperatureF}, {item.Summary}");
            }
            Console.WriteLine("Hello World!");
        }
Esempio n. 18
0
        public async Task AddJoiner(int id, int joinerId, string joinerName, string joinerPhone, bool joinerPositiveStart, bool joinerUnmute, bool?joinerAnnounceEnter, bool?joinerAnnounceLeave, bool?joinerAnnounceMute, bool?joinerAnnounceUnmute)
        {
            var client = new swaggerClient(VoiceUrl, new HttpClient());
            var joinerAnnouncements = new List <AnnouncementType>();

            if (joinerAnnounceEnter.HasValue && joinerAnnounceEnter.Value)
            {
                joinerAnnouncements.Add(AnnouncementType.Join);
            }
            if (joinerAnnounceLeave.HasValue && joinerAnnounceLeave.Value)
            {
                joinerAnnouncements.Add(AnnouncementType.Leave);
            }
            if (joinerAnnounceMute.HasValue && joinerAnnounceMute.Value)
            {
                joinerAnnouncements.Add(AnnouncementType.Mute);
            }
            if (joinerAnnounceUnmute.HasValue && joinerAnnounceUnmute.Value)
            {
                joinerAnnouncements.Add(AnnouncementType.Unmute);
            }
            try
            {
                await client.Joiners2Async($"{Prefix}{id}", new NewJoiner
                {
                    Name  = joinerName,
                    Phone = joinerPhone,
                    RequirePositiveStart = joinerPositiveStart,
                    RequireUnmute        = joinerUnmute,
                    SystemId             = joinerId.ToString(),
                    Announcements        = joinerAnnouncements
                });

                _ = Log(id, "info", $"Joiner ({joinerId}/{joinerName}/{joinerPhone}) added to call");
            }
            catch (Exception e)
            {
                _ = Log(id, "error", $"Failed to add joiner {joinerPhone} to call due to error {e.GetType().Name}: {e.Message}");
                throw;
            }
        }
Esempio n. 19
0
        public async Task CreateThenFindUser()
        {
            swaggerClient client = new swaggerClient(baseUrl, httpClient);

            CreateUserCommand command = new CreateUserCommand()
            {
                FirstName    = "Some",
                MiddleName   = "Tandem",
                LastName     = "User",
                PhoneNumber  = "111-222-3333",
                EmailAddress = $"{Guid.NewGuid()}@foo.bar"
            };

            await client.UsersAsync(command);

            UserDetailView savedUser = await client.Users2Async(command.EmailAddress);

            string expectedName = $"{command.FirstName} {command.MiddleName} {command.LastName}";

            Assert.AreEqual(expectedName, savedUser.Name);
            Assert.AreEqual(command.EmailAddress, savedUser.EmailAddress);
            Assert.AreEqual(command.EmailAddress, savedUser.EmailAddress);
        }
        private static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var httpClient    = new HttpClient();
            var swaggerClient = new swaggerClient("http://*****:*****@gmail.com",
                MobileNo = "9111111111"
            });

            Console.WriteLine(flag);
        }
Esempio n. 21
0
        public async Task Start(int id, int accountId, string accountName, string accountPhone, int agentId, string agentFirstName, string agentLastName, string agentPhone, bool?agentEnter, bool?agentLeave, bool?agentUnmute, bool?agentMute, string visitorFirstName, string visitorLastName, string visitorPhone, bool?visitorEnter, bool?visitorLeave, bool?visitorUnmute, bool?visitorMute)
        {
            var client             = new swaggerClient(VoiceUrl, new HttpClient());
            var agentAnnouncements = new List <AnnouncementType>();

            if (agentEnter.HasValue && agentEnter.Value)
            {
                agentAnnouncements.Add(AnnouncementType.Join);
            }
            if (agentLeave.HasValue && agentLeave.Value)
            {
                agentAnnouncements.Add(AnnouncementType.Leave);
            }
            if (agentMute.HasValue && agentMute.Value)
            {
                agentAnnouncements.Add(AnnouncementType.Mute);
            }
            if (agentUnmute.HasValue && agentUnmute.Value)
            {
                agentAnnouncements.Add(AnnouncementType.Unmute);
            }
            var visitorAnnouncements = new List <AnnouncementType>();

            if (visitorEnter.HasValue && visitorEnter.Value)
            {
                visitorAnnouncements.Add(AnnouncementType.Join);
            }
            if (visitorLeave.HasValue && visitorLeave.Value)
            {
                visitorAnnouncements.Add(AnnouncementType.Leave);
            }
            if (visitorMute.HasValue && visitorMute.Value)
            {
                visitorAnnouncements.Add(AnnouncementType.Mute);
            }
            if (visitorUnmute.HasValue && visitorUnmute.Value)
            {
                visitorAnnouncements.Add(AnnouncementType.Unmute);
            }

            try
            {
                await client.CallsAsync(new NewVoiceCall
                {
                    Account = new Account
                    {
                        Id    = accountId,
                        Name  = accountName,
                        Phone = accountPhone
                    },
                    Agent = new Agent
                    {
                        FirstName     = agentFirstName,
                        Id            = agentId,
                        LastName      = agentLastName,
                        Phone         = agentPhone,
                        Announcements = agentAnnouncements
                    },
                    Callbacks = new CallbacksRecord
                    {
                        Types = new CallbackType[]
                        {
                            CallbackType.CallEnd,
                            CallbackType.RecordingAvailable,
                            CallbackType.CallerEnter,
                            CallbackType.CallerHangup,
                            CallbackType.CallerMute,
                            CallbackType.CallerUnmute
                        },
                        Url = $"{MyUrlBase}{id}"

/*                        AgentAnswer = true,
 *                      AgentHangup = true,
 *                      CallEnd = true,
 *                      CallRecordingAvailable = true,
 *                      JoinerEnter = true,
 *                      JoinerHangup = true,
 *                      JoinerPickup = true,
 *                      JoinerUnmute = true,
 *                      Url = $"MyUrlBase{id}",
 *                      VisitorHangup = true,
 *                      VisitorAnswer = true
 */                 },
                    System   = "test",
                    SystemId = $"{Prefix}{id}",
                    Visitor  = new Visitor
                    {
                        FirstName     = visitorFirstName,
                        LastName      = visitorLastName,
                        Phone         = visitorPhone,
                        Announcements = visitorAnnouncements
                    }
                });

                var callId = Guid.NewGuid();
                _           = Log(id, "info", $"Call started for account ({accountId}/{accountName}/{accountPhone}) between agent ({agentId}/{agentFirstName} {agentLastName}/{agentPhone}) and visitor ({visitorFirstName} {visitorLastName}/{visitorPhone}) => {callId}");
                CallIds[id] = callId;
            }
            catch (Exception e)
            {
                _ = Log(id, "error", $"Call failed for account {accountId} between agent {agentPhone} and visitor {visitorPhone} due to error {e.GetType().Name}: {e.Message}");
                throw;
            }
        }
Esempio n. 22
0
 public IndexModel(swaggerClient client)
 {
     _client = client;
 }
Esempio n. 23
0
 public PhoneNumberCruder(swaggerClient sc, System.Guid customerId)
 {
     CustomerId = customerId;
     _sc        = sc;
 }
Esempio n. 24
0
        public static Boolean PlayAdventure()
        {
            string instanceID;
            string move;
            bool   error;
            string errormsg = "";



            var _httpClient = new System.Net.Http.HttpClient();
            var _client     = new swaggerClient(_httpClient)
            {
                BaseUrl = ApiUrl
            };



            move = "";

            try
            {
                DisplayIntro();
                Console.WriteLine();
                SetColor(ConsoleColor.Yellow);
                Console.WriteLine("cquit = quit game and capi = Display API endpoint");
                SetColor(ConsoleColor.Green);
                Console.WriteLine("");


                // default to game 1 until I we have selection system
                // Gets the first game and sets up the game
                gmr        = _client.Adventure3Async(1).GetAwaiter().GetResult();
                instanceID = gmr.InstanceID;
                error      = false;
            }
            catch (Exception e)
            {
                // oops! Looks like we had a problem starting the game.
                SetColor(ConsoleColor.Red);
                errormsg = "Error: Can not create new game (" + ApiUrl + ")";
                Console.WriteLine(errormsg);
                Console.WriteLine(e.ToString());
                SetColor(ConsoleColor.Green);
                return(false);
            }

            while (move != "cquit")
            {
                switch (move)
                {
                case "capi":
                    Console.WriteLine();
                    SetColor(ConsoleColor.Yellow);
                    Console.WriteLine("Api:" + ApiUrl);
                    SetColor(ConsoleColor.Green);
                    Console.WriteLine();
                    move = "";
                    break;

                default:

                    Console.WriteLine();
                    SetColor(ConsoleColor.Yellow);
                    Console.Write(gmr.RoomName);
                    Console.WriteLine();
                    SetColor(ConsoleColor.Green);
                    Console.WriteLine(gmr.RoomMessage);
                    SetColor(ConsoleColor.DarkCyan);
                    Console.WriteLine(gmr.ItemsMessage);
                    Console.WriteLine();
                    SetColor(ConsoleColor.White);
                    Console.Write("What now?"); SetColor(ConsoleColor.Green); Console.Write(" >"); SetColor(ConsoleColor.Green);

                    if (error == true)
                    {
                        Console.WriteLine();
                        SetColor(ConsoleColor.Red);
                        Console.WriteLine("Client Error:");
                        Console.WriteLine(errormsg);
                        SetColor(ConsoleColor.Green);
                        Console.WriteLine();
                    }

                    move = Console.ReadLine();

                    try
                    {
                        // once the game is setup by calling the get that returns the first gmr you then
                        // just pass the game move with the instance id
                        gmr = _client.Adventure2Async(instanceID, move).GetAwaiter().GetResult();
                    }
                    catch (Exception)
                    {
                        error = true;
                        SetColor(ConsoleColor.Red);
                        errormsg        = "Error: Can not Process Move - Possible Timeout. Try move again or LOOK.";
                        gmr.RoomMessage = errormsg;     // report the error ro the user;
                        SetColor(ConsoleColor.Green);
                    }
                    break;
                }
            }

            if (error)
            {
                Console.WriteLine(errormsg);
            }

            return(error);
        }
Esempio n. 25
0
 public AddressCruder(swaggerClient sc, System.Guid customerId)
 {
     CustomerId = customerId;
     _sc        = sc;
 }
Esempio n. 26
0
 public IncomingModel(swaggerClient client, GitHubClient github, ILogger <IncomingModel> logger)
 {
     _client = client;
     _github = github;
     _logger = logger;
 }