Ejemplo n.º 1
0
        private WebServiceClient CreateClient(string type, string ipAddress = "1.2.3.4",
                                              HttpStatusCode status         = HttpStatusCode.OK, string?contentType = null, string content = "")
        {
            var service = type.Replace("Async", "");

            contentType ??= $"application/vnd.maxmind.com-{service}+json";

            _server
            .Given(
                Request.Create()
                .WithPath($"/geoip/v2.1/{service}/{ipAddress}")
                .UsingGet()
                )
            .RespondWith(
                Response.Create()
                .WithStatusCode(status)
                .WithHeader("Content-Type", contentType)
                .WithBody(content)
                );

            var host = _server.Urls[0].Replace("http://", "");

            return(new WebServiceClient(6, "0123456789",
                                        locales: new List <string> {
                "en"
            },
                                        host: host,
                                        timeout: 3000,
                                        disableHttps: true
                                        ));
        }
        public async Task ShouldCreateScheduleWhenRequested()
        {
            var scheduleWebAPi = RestService.For <IScheduleWebApi>(ScheduleWebApiBaseUrl);
            var workloadItems  = new List <WorkloadItem>
            {
                Any.Instance <WorkloadItem>(),
                Any.Instance <WorkloadItem>()
            };

            var maintenanceWindowServiceLocation = new ServiceLocation
            {
                Location = new Uri("http://localhost:5678")
            };

            _mockServer.Given(
                Request.Create().UsingGet().WithPath("/MaintenanceWindowService"))
            .RespondWith(
                Response.Create().WithSuccess().WithBodyAsJson(maintenanceWindowServiceLocation));

            var maintenanceWindows = Any.Instance <MaintenanceWindow>();

            _mockServer.Given(
                Request.Create().UsingGet().WithPath("/Planned"))
            .RespondWith(
                Response.Create().WithSuccess().WithBodyAsJson(maintenanceWindows));

            var result = await scheduleWebAPi.CreateScheduleAsync(workloadItems);

            result.Should().NotBe(Guid.Empty);
        }
        public async Task ShouldCreateScheduleWhenRequested()
        {
            var scheduleWebApiClient = new JsonServiceClient(ScheduleWebApiBaseUrl);

            var maintenanceWindowServiceLocation = new ServiceLocation
            {
                Location = new Uri("http://localhost:5678")
            };

            _mockServer.Given(
                Request.Create().UsingGet().WithPath("/MaintenanceWindowService"))
            .RespondWith(
                Response.Create().WithSuccess().WithBodyAsJson(maintenanceWindowServiceLocation));

            var maintenanceWindows = Any.Instance <MaintenanceWindow>();

            _mockServer.Given(
                Request.Create().UsingGet().WithPath("/Planned"))
            .RespondWith(
                Response.Create().WithSuccess().WithBodyAsJson(maintenanceWindows));

            var workloadItems = new List <WorkloadItem>
            {
                Any.Instance <WorkloadItem>(),
                Any.Instance <WorkloadItem>()
            };
            var createScheduleRequest = new CreateScheduleRequest
            {
                WorkloadItems = workloadItems
            };

            var result = await scheduleWebApiClient.PostAsync(createScheduleRequest).ConfigureAwait(false);

            result.Id.Should().NotBe(Guid.Empty);
        }
Ejemplo n.º 4
0
        private void BuildTestScenario(WireMockServer p_server)
        {
            p_server
            .Given(Request.Create()
                   .WithPath("/todo/items")
                   .UsingGet())
            .InScenario("To do list")
            .WillSetStateTo("TodoList State Started")
            .RespondWith(Response.Create()
                         .WithBody("Buy milk"));

            p_server
            .Given(Request.Create()
                   .WithPath("/todo/items")
                   .UsingPost())
            .InScenario("To do list")
            .WhenStateIs("TodoList State Started")
            .WillSetStateTo("Cancel newspaper item added")
            .RespondWith(Response.Create()
                         .WithStatusCode(201));

            p_server
            .Given(Request.Create()
                   .WithPath("/todo/items")
                   .UsingGet())
            .InScenario("To do list")
            .WhenStateIs("Cancel newspaper item added")
            .RespondWith(Response.Create()
                         .WithBody("Buy milk;Cancel newspaper subscription"));
        }
Ejemplo n.º 5
0
        public async Task Return_Success_Response_When_Request_Is_Successful()
        {
            BankPaymentResponse bankPaymentResponse = (new BankPaymentResponse {
                PaymentIdentifier = Guid.NewGuid().ToString(), PaymentStatus = PaymentStatus.Success
            });

            _server
            .Given(Request.Create()
                   .WithPath($"/api/payment").UsingPost())
            .RespondWith(Response.Create()
                         .WithStatusCode(200)
                         .WithHeader("Content-Type", "application/json")
                         .WithBody(bankPaymentResponse.ToJson()));
            _mockAcquiryBankOptions.SetupGet(x => x.CurrentValue)
            .Returns(new AcquiringBankSettings {
                ApiUrl = _server.Urls.First()
            });
            var sut = new AcquiringBankClient(new HttpClient(), _mockAcquiryBankOptions.Object, _mockLogger.Object);


            var response = await sut.ProcessPayment(new BankPaymentRequest
            {
                Amount          = 100,
                Currency        = "EUR",
                CardExpiryYear  = "24",
                CardExpiryMonth = "4",
                CardNumber      = "5564876598743467",
                CVV             = "782",
                MerchantId      = Guid.NewGuid().ToString()
            });

            response.Should().BeEquivalentTo(bankPaymentResponse);
        }
        public async Task CanGetEmptyStatusListAsync()
        {
            server.Reset();

            var expected = new List <DurableFunctionStatus>();

            server
            .Given(
                Request
                .Create()
                .WithPath("/runtime/webhooks/durabletask/instances")
                .UsingGet()
                )
            .RespondWith(
                Response
                .Create()
                .WithStatusCode(200)
                .WithBody("[]")
                );

            var client = new DurableFunctionClient(server.Ports[0]);
            var actual = await client.GetAllFunctionStatuses();

            actual.Should().BeEquivalentTo(expected);
        }
        public async Task TestClientAuthenticationWithApiKeyAuthentication()
        {
            var user = UserTestData.Users.First();

            using var client = new CloudFlareClient(WireMockConnection.ApiKeyAuthentication, _connectionInfo);

            IDictionary <string, WireMockList <string> > headers = null;

            _wireMockServer
            .Given(Request.Create().WithPath($"/{UserEndpoints.Base}").UsingGet())
            .RespondWith(Response.Create().WithStatusCode(200)
                         .WithBody(x =>
            {
                headers = x.Headers;
                return(WireMockResponseHelper.CreateTestResponse(user));
            }));

            await client.Users.GetDetailsAsync();

            headers.Should().ContainKey("X-Auth-Email");
            headers.First(x => x.Key == "X-Auth-Email").Value.Should().BeEquivalentTo(WireMockConnection.EmailAddress);

            headers.Should().ContainKey("X-Auth-Key");
            headers.First(x => x.Key == "X-Auth-Key").Value.Should().BeEquivalentTo(WireMockConnection.Key);
        }
        public MiddlewareAndPolicyTests()
        {
            _server = WireMockServer.Start();

            _server
            .Given(Request.Create()
                   .WithPath(_endpointUri)
                   .UsingGet())
            .InScenario("Timeout-then-resolved")
            .WillSetStateTo("Transient issue resolved")
            .RespondWith(Response.Create()
                         .WithStatusCode(HttpStatusCode.RequestTimeout));

            _server
            .Given(Request.Create()
                   .WithPath(_endpointUri)
                   .UsingGet())
            .InScenario("Timeout-then-resolved")
            .WhenStateIs("Transient issue resolved")
            .WillSetStateTo("All ok")
            .RespondWith(Response.Create()
                         .WithStatusCode(HttpStatusCode.OK)
                         .WithHeader("Content-Type", "text/plain")
                         .WithBody("Hello world!"));

            _server
            .Given(Request.Create()
                   .WithPath(_endpointUriTimeout)
                   .UsingGet())
            .RespondWith(Response.Create()
                         .WithStatusCode(HttpStatusCode.RequestTimeout));
        }
        public void Setup()
        {
            _server = WireMockServer.Start();
            _server
            .Given(
                Request.Create()
                .UsingGet()
                .WithPath($"/api/v1/data/1"))
            .RespondWith(
                Response.Create()
                .WithStatusCode(HttpStatusCode.OK)
                .WithHeader("Content-Type", "application/json")
                .WithBody(TestData.DataObjTests.DefaultJson));
            _server
            .Given(
                Request.Create()
                .UsingGet()
                .WithPath($"/api/v1/person/1"))
            .RespondWith(
                Response.Create()
                .WithStatusCode(HttpStatusCode.OK)
                .WithHeader("Content-Type", "application/json")
                .WithBody(TestData.PersonTests.DefaultJson));

            _restClient = new RestClient($"http://localhost:{_server.Ports.FirstOrDefault()}")
            {
                Encoding = Encoding.UTF8,
                AutomaticDecompression    = true,
                UseSynchronizationContext = false
            };
            _restClient.UseSerializer(() => new JsonSerializer {
                DateFormat = "yyyy-MM-ddTHH:mm:ss.FFFFFFFZ"
            });
        }
        public SampleWireMock ConfigureBuilder()
        {
            mockServer
            .Given(
                Request.Create().WithPath($"/".Split('?')[0]).UsingGet()
                )
            .RespondWith(
                Response.Create()
                .WithStatusCode(200)
                );

            mockServer
            .Given(
                Request.Create().WithPath($"/").UsingGet()
                )
            .RespondWith(
                Response.Create()
                .WithStatusCode(200)
                );

            mockServer
            .Given(
                Request.Create().WithPath($"/api/health").UsingGet()
                )
            .RespondWith(
                Response.Create()
                .WithStatusCode(200)
                );

            return(this);
        }
Ejemplo n.º 11
0
        public async Task TestAPIBaz()
        {
            // Arrange
            TestServer _server = new TestServer(new WebHostBuilder()
                                                .UseStartup <Startup>());

            // HttpClient _client = _server.CreateClient();

            _wireMockServer
            //.Given(Request.Create().WithUrl("https://api.ipify.org?format=json").UsingGet())
            .Given(Request.Create().WithPath("/api/learning/baz").UsingGet())
            .RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithBody(@"{ ""ip"": ""0.0.0.0"" }")
                );

            // Act
            var httpClient = new HttpClient();
            var response   = await httpClient.GetAsync($"{_wireMockServer.Urls[0]}/api/learning/baz");

            response.EnsureSuccessStatusCode();

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

            // Assert
            Assert.AreEqual(@"{ ""ip"": ""0.0.0.0"" }", responseString);
        }
        public async Task ValidateShouldReturnTrueOnValidTIHJwt()
        {
            var validToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOiIxNTk5NzUzMTk5IiwiYWNjZXNzX3Rva2VuIjoidGVzdF9hY2Nlc3NfdG9rZW4iLCJpZCI6IjAifQ.osL8kyPx90gUapZzz6Iv-H8DPwgtJTMSKTJA1VtMirU";
            var validExp   = _DateTimeProvider.Now().AddHours(_ClaimLifetimeHours - .1).ToUnixTimeU64();
            var testClaims = new Dictionary <string, string>
            {
                { "id", "0" },
                { "exp", validExp.ToString() },
                { "access_token", validToken }
            };

            _Server.Reset();
            _Server.Given(
                Request.Create()
                .WithHeader("Authorization", "Bearer " + validToken)
                .WithPath("/ggdghornl_test/oauth2/v1/verify").UsingGet()
                )
            .RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBody("{\"audience\":1234}")
                );

            Assert.True(await _JwtClaimValidator.ValidateAsync(testClaims));
        }
Ejemplo n.º 13
0
        public FederatedEndpointFixture()
        {
            Server1 = WireMockServer.Start();
            Server2 = WireMockServer.Start();

            Server1.Given(Request.Create()
                          .WithPath("/query")
                          .UsingGet()
                          .WithParam("query", MatchBehaviour.AcceptOnMatch))
            .RespondWith(Response.Create()
                         .WithBody(Server1ResultsXml, encoding: Encoding.UTF8)
                         .WithHeader("Content-Type", MimeTypesHelper.SparqlResultsXml[0])
                         .WithStatusCode(HttpStatusCode.OK));
            Server1.Given(Request.Create().WithPath("/query2").UsingGet().WithParam("query"))
            .RespondWith(Response.Create().WithBody(Server1ConstructResults, encoding: Encoding.UTF8)
                         .WithHeader("Content-Type", "application/n-triples").WithStatusCode(HttpStatusCode.OK));

            Server2
            .Given(Request.Create().WithPath("/query").UsingGet().WithParam("query"))
            .RespondWith(Response.Create().WithBody(Server2ResultsXml, encoding: Encoding.UTF8)
                         .WithHeader("Content-Type", MimeTypesHelper.SparqlResultsXml[0]).WithStatusCode(HttpStatusCode.OK));
            Server2.Given(Request.Create().WithPath("/query2").UsingGet().WithParam("query"))
            .RespondWith(Response.Create().WithBody(Server2ConstructResults, encoding: Encoding.UTF8)
                         .WithHeader("Content-Type", "application/n-triples").WithStatusCode(HttpStatusCode.OK));
            Server2.Given(Request.Create().WithPath("/fail"))
            .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.Forbidden));
            Server2.Given(Request.Create().WithPath("/timeout"))
            .RespondWith(Response.Create().WithDelay(4000).WithBody(Server2ResultsXml, encoding: Encoding.UTF8)
                         .WithHeader("Content-Type", MimeTypesHelper.SparqlResultsXml[0]).WithStatusCode(HttpStatusCode.OK));
        }
        public async Task TestGetUserMembershipsAsync()
        {
            var displayOptions = new DisplayOptions {
                Page = 1, PerPage = 20, Order = OrderType.Asc
            };
            var membershipFilter = new MembershipFilter {
                AccountName = "tothnet", MembershipOrder = MembershipOrder.Status, Status = Status.Accepted
            };

            _wireMockServer
            .Given(Request.Create()
                   .WithPath($"/{MembershipEndpoints.Base}/")
                   .WithParam(Filtering.Page)
                   .WithParam(Filtering.PerPage)
                   .WithParam(Filtering.Order)
                   .WithParam(Filtering.Status)
                   .WithParam(Filtering.AccountName)
                   .WithParam(Filtering.Direction)
                   .UsingGet())
            .RespondWith(Response.Create().WithStatusCode(200)
                         .WithBody(WireMockResponseHelper.CreateTestResponse(UserMembershipTestsData.Memberships)));

            using var client = new CloudFlareClient(WireMockConnection.ApiKeyAuthentication, _connectionInfo);

            var userMembership = await client.Users.Memberships.GetAsync(membershipFilter, displayOptions);

            userMembership.Result.Should().BeEquivalentTo(UserMembershipTestsData.Memberships);
        }
Ejemplo n.º 15
0
 public void StubData()
 {
     Stub
     .Given(Request
            .Create()
            .WithUrl(BaseUrl)
            .UsingGet())
     .RespondWith(Response.Create().WithBody("hello"));
 }
        public async Task Setup()
        {
            var services = new ServiceCollection();

            string eventsJson;
            var    names        = Assembly.GetExecutingAssembly().GetManifestResourceNames();
            var    eventsStream = Assembly.GetExecutingAssembly()
                                  .GetManifestResourceStream("EA.Usage.Tracking.Client.Test.Events.json");

            using (var reader = new StreamReader(eventsStream, Encoding.UTF8))
                eventsJson = await reader.ReadToEndAsync();

            var events = new PagedResponse <UsageTrackingEvent>()
            {
                Data = new List <UsageTrackingEvent>()
                {
                    new UsageTrackingEvent()
                    {
                        Id = 1, Name = "Test", DateCreated = DateTime.Now
                    }
                }
            };

            services.AddHttpClient("usageTracking", c =>
            {
                c.BaseAddress = new Uri(baseUrl);
            });

            services.AddScoped <IUsageTrackingClient, UsageTrackingClient>();

            stub.Given(
                Request
                .Create()
                .WithPath("/ApplicationEvent"))
            .RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyAsJson(events));

            stub.Given(
                Request
                .Create()
                .WithPath("/ApplicationUsage"))
            .RespondWith(
                Response.Create()
                .WithStatusCode(201));

            var mockAuthClient = new Mock <IAuthClient>();

            mockAuthClient.Setup(x => x.GetAuthenticationHeader())
            .Returns(Task.FromResult(new AuthenticationHeaderValue("test")));

            services.AddScoped <IAuthClient>(c => mockAuthClient.Object);

            _servicesProvider = services.BuildServiceProvider();
        }
        public FakeApiGatewayHost()
        {
            stub = FluentMockServer.Start(new FluentMockServerSettings
            {
                Urls = new[] { "http://+:5003" },
                StartAdminInterface = true
            });

            stub.Given(
                Request.Create()
                .WithPath("/api/eml/accounts/registrationemail")
                .WithHeader("ipm-eml-auth", "1234")
                //.WithHeader("Content-Type", "application/vnd.h2020ipmdecisions.email+json")
                .WithBody(new WildcardMatcher("*[email protected]*"))
                .UsingPost())
            .RespondWith(Response.Create()
                         .WithStatusCode(200)
                         .WithHeader("Content-Type", "application/json"));

            stub.Given(
                Request.Create()
                .WithPath("/api/eml/accounts/registrationemail")
                .WithHeader("ipm-eml-auth", "1234")
                //.WithHeader("Content-Type", "application/vnd.h2020ipmdecisions.email+json")
                .WithBody(new WildcardMatcher("*emailservicedown*"))
                .UsingPost())
            .RespondWith(Response.Create()
                         .WithStatusCode(400)
                         .WithHeader("Content-Type", "application/json")
                         .WithBody(@"{ ""message"": ""No connection could be made because the target machine actively refused it."" }"));

            stub.Given(
                Request.Create()
                .WithPath("/api/eml/accounts/forgotpassword")
                .WithHeader("ipm-eml-auth", "1234")
                //.WithHeader("Content-Type", "application/vnd.h2020ipmdecisions.email+json")
                .WithBody(new WildcardMatcher("*"))
                .UsingPost())
            .AtPriority(10)
            .RespondWith(Response.Create()
                         .WithStatusCode(200)
                         .WithHeader("Content-Type", "application/json"));

            stub.Given(
                Request.Create()
                .WithPath("/api/eml/accounts/forgotpassword")
                .WithHeader("ipm-eml-auth", "1234")
                //.WithHeader("Content-Type", "application/vnd.h2020ipmdecisions.email+json")
                .WithBody(new WildcardMatcher("*failemail*"))
                .UsingPost())
            .AtPriority(1)
            .RespondWith(Response.Create()
                         .WithStatusCode(400)
                         .WithHeader("Content-Type", "application/json")
                         .WithBody(@"{ ""message"": ""No connection could be made because the target machine actively refused it."" }"));
        }
Ejemplo n.º 18
0
        public async Task TestCreateDnsRecordAsync()
        {
            var zone      = ZoneTestData.Zones.First();
            var dnsRecord = DnsRecordTestData.DnsRecords.First();
            var newRecord = new NewDnsRecord
            {
                Name     = dnsRecord.Name,
                Content  = dnsRecord.Content,
                Priority = dnsRecord.Priority,
                Proxied  = dnsRecord.Proxied,
                Ttl      = dnsRecord.Ttl,
                Type     = dnsRecord.Type
            };

            _wireMockServer
            .Given(Request.Create().WithPath($"/{ZoneEndpoints.Base}/{zone.Id}/{DnsRecordEndpoints.Base}").UsingPost())
            .RespondWith(Response.Create().WithStatusCode(200)
                         .WithBody(WireMockResponseHelper.CreateTestResponse(dnsRecord)));

            using var client = new CloudFlareClient(WireMockConnection.ApiKeyAuthentication, _connectionInfo);

            var created = await client.Zones.DnsRecords.AddAsync(zone.Id, newRecord);

            created.Result.Should().BeEquivalentTo(dnsRecord);
        }
Ejemplo n.º 19
0
 private static void SetupGetVendorDetailsResponse()
 {
     // Return sample values for Account 100 and ALE 2000
     _fakeCustomerEngagementApi.Given(
         Request.Create().WithPath($"/Finance/{_customerEngagementCompanyName}/vendor/aleid={_hashedLegalEntityId}")
         .UsingGet()
         )
     .RespondWith(
         Response.Create()
         .WithStatusCode((int)HttpStatusCode.OK)
         .WithHeader("Content-Type", "application/json")
         .WithBody(GetSampleJsonResponse("VendorData.json")));
 }
Ejemplo n.º 20
0
 private void RegisterSelectQueryGetHandler(string query = "SELECT * WHERE {?s ?p ?o}")
 {
     _server.Given(Request.Create()
                   .WithPath("/sparql")
                   .UsingGet()
                   .WithParam(queryParams =>
                              queryParams.ContainsKey("query") &&
                              queryParams["query"].Any(q => HttpUtility.UrlDecode(q).StartsWith(query))))
     .RespondWith(Response.Create()
                  .WithBody(SparqlResultsXml, encoding: Encoding.UTF8)
                  .WithHeader("Content-Type", MimeTypesHelper.SparqlResultsXml[0])
                  .WithStatusCode(HttpStatusCode.OK));
 }
Ejemplo n.º 21
0
        public ResponseWithProxyTests()
        {
            _guid = Guid.NewGuid();

            _server = WireMockServer.Start();
            _server.Given(Request.Create().UsingPost().WithPath($"/{_guid}"))
            .RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 42 }).WithHeader("Content-Type", "application/json"));
            _server.Given(Request.Create().UsingPost().WithPath($"/{_guid}/append"))
            .RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 10 }).WithHeader("Content-Type", "application/json"));
            _server.Given(Request.Create().UsingPost().WithPath($"/prepend/{_guid}"))
            .RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 11 }).WithHeader("Content-Type", "application/json"));
            _server.Given(Request.Create().UsingPost().WithPath($"/prepend/{_guid}/append"))
            .RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 12 }).WithHeader("Content-Type", "application/json"));
        }
Ejemplo n.º 22
0
        public async Task GetBannerInfo_StudentIdentifier_ShouldCallCorrectApiAndReturnBackStudentInfo(string identifier)
        {
            var bannerInfo = new BannerPersonInfo()
            {
                EmailAddress = identifier,
                WVUPID       = Utils.ParseOrDefault(identifier, 11243213),
                FirstName    = "Billy",
                LastName     = "Loel",
                Teacher      = false
            };

            var cleanedIdentifier = identifier.Split("@")[0];

            server
            .Given(Request.Create().WithPath($"/student/{cleanedIdentifier}").UsingGet())
            .RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyAsJson(bannerInfo)
                );

            var studentInfo = await bannerApi.GetBannerInfo(identifier);

            Assert.NotNull(studentInfo);
            Assert.False(studentInfo.Teacher);
        }
        public async Task WithProxyUrl_WhenACallWasMadeWithProxyUrl_Should_BeOK()
        {
            _server.ResetMappings();
            _server.Given(Request.Create().UsingAnyMethod())
            .RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings {
                Url = "http://localhost:9999"
            }));

            await _httpClient.GetAsync("");

            _server.Should()
            .HaveReceivedACall()
            .WithProxyUrl($"http://localhost:9999");
        }
        public async Task List()
        {
            _server.Given(Request.Create().WithParam("watch", MatchBehaviour.RejectOnMatch, "true").UsingGet())
            .RespondWith(Response.Create().WithBodyAsJson(TestData.ListPodsTwoItems));
            var sut = new KubernetesInformer <V1Pod>(_kubernetes);

            var result = await sut.GetResource(ResourceStreamType.List).ToList().TimeoutIfNotDebugging();;

            result.Should().HaveCount(2);
            result[0].EventFlags.Should().HaveFlag(EventTypeFlags.ResetStart);
            result[1].EventFlags.Should().HaveFlag(EventTypeFlags.ResetEnd);
            result[0].Value.Should().BeEquivalentTo(TestData.ListPodsTwoItems.Items[0]);
            result[1].Value.Should().BeEquivalentTo(TestData.ListPodsTwoItems.Items[1]);
        }
 private void RegisterSelectQueryGetHandler(Predicate <string> queryPredicate, string results)
 {
     _server
     .Given(Request.Create()
            .WithPath("/sparql")
            .UsingGet()
            .WithParam(queryParams =>
                       queryParams.ContainsKey("query") &&
                       queryParams["query"].Any(q => queryPredicate(HttpUtility.UrlDecode(q)))))
     .RespondWith(Response.Create()
                  .WithBody(results, encoding: Encoding.UTF8)
                  .WithHeader("Content-Type", MimeTypesHelper.SparqlResultsXml[0])
                  .WithStatusCode(HttpStatusCode.OK));
 }
Ejemplo n.º 26
0
        public async Task TestGetRolesAsync()
        {
            var accountId = AccountTestData.Accounts.First().Id;

            _wireMockServer
            .Given(Request.Create().WithPath($"/{AccountEndpoints.Base}/{accountId}/{AccountEndpoints.Roles}").UsingGet())
            .RespondWith(Response.Create().WithStatusCode(200)
                         .WithBody(WireMockResponseHelper.CreateTestResponse(RoleTestData.Roles)));

            using var client = new CloudFlareClient(WireMockConnection.ApiKeyAuthentication, _connectionInfo);

            var roles = await client.Accounts.Roles.GetAsync(accountId);

            roles.Result.Should().BeEquivalentTo(RoleTestData.Roles);
        }
Ejemplo n.º 27
0
        public CommitmentsV2ApiBuilder WithPing()
        {
            _server
            .Given(
                Request.Create()
                .WithPath($"/api/ping")
                .UsingGet()
                )
            .RespondWith(
                Response.Create()
                .WithStatusCode((int)HttpStatusCode.OK)
                );

            return(this);
        }
Ejemplo n.º 28
0
        public TrainingProviderApiBuilder WithPing()
        {
            _server
            .Given(
                Request.Create()
                .WithPath($"/ping")
                .UsingGet()
                )
            .RespondWith(
                Response.Create()
                .WithStatusCode((int)HttpStatusCode.OK)
                );

            return(this);
        }
Ejemplo n.º 29
0
        public async Task TestGetUserDetailsAsync()
        {
            var user = UserTestData.Users.First();

            _wireMockServer
            .Given(Request.Create().WithPath($"/{UserEndpoints.Base}").UsingGet())
            .RespondWith(Response.Create().WithStatusCode(200)
                         .WithBody(WireMockResponseHelper.CreateTestResponse(user)));

            using var client = new CloudFlareClient(WireMockConnection.ApiKeyAuthentication, _connectionInfo);

            var userDetails = await client.Users.GetDetailsAsync();

            userDetails.Result.Should().BeEquivalentTo(user);
        }
Ejemplo n.º 30
0
        public async Task Get_DeveRetornarOk_QuandoRequestForValido()
        {
            //Arrange
            var chaveCampeonato = ChaveClassificacaoBuilder.Novo().ComParticipantesFixos().Build();
            var participantes   = chaveCampeonato.ObterParticipantes();

            _wireMockServer
            .Given(_request)
            .RespondWith(Response.Create().WithSuccess().WithBodyAsJson(participantes));

            //Act
            var response = await _httpClient.GetAsync(_endpoint);

            //Assert
            response.Should().Be200Ok().And.BeAs(participantes);
        }