Beispiel #1
0
        private async Task PublishToSearch(IList <SearchCourse> courses)
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _mcConfig.SearchAndCompareApiKey);
                httpClient.Timeout = TimeSpan.FromMinutes(120);
                var client = new SearchAndCompareApi(httpClient, _mcConfig.SearchAndCompareApiUrl);
                _logger.Information($"Sending {courses.Count()} courses to Search API...");
                var success = await client.SaveCoursesAsync(courses);

                if (!success)
                {
                    throw new Exception("Publishing to Search API failed. Check search API logs for details");
                }
            }
        }
        public async Task SaveCourses_CallsCorrectUrl()
        {
            mockHttp.Setup(x => x.PostAsync(It.Is <Uri>(y => y.AbsoluteUri == "https://api.example.com/courses"), It.IsAny <StringContent>())).ReturnsAsync(
                new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK
            }
                ).Verifiable();

            var course = CoursesControllerTests.GetCourse(1);

            course.IsValid(false).Should().BeTrue();

            var result = await sut.SaveCoursesAsync(new List <Course>(){ course });

            result.Should().BeTrue();
            mockHttp.VerifyAll();
        }