public async void CoreAuthenticationErrorShouldThrowException(string type, ClientRunner cr, Type t) { var errors = new List <string> { "ACCOUNT_ID_REQUIRED", "ACCOUNT_ID_UNKNOWN", "AUTHORIZATION_INVALID", "LICENSE_KEY_REQUIRED", "USER_ID_REQUIRED", "USER_ID_UNKNOWN" }; foreach (var error in errors) { var msg = "Appropriate user-readable error message"; var client = CreateClientCore(type, status: HttpStatusCode.Unauthorized, content: ErrorJson(error, msg)); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <AuthenticationException>(exception); Assert.Contains(msg, exception.Message); } }
public override async Task RunClient(IAsyncStreamReader <ClientArgs> requestStream, IServerStreamWriter <ClientStatus> responseStream, ServerCallContext context) { if (!await requestStream.MoveNext()) { throw new InvalidOperationException(); } var clientConfig = requestStream.Current.Setup; var clientRunner = ClientRunner.Start(_loggerFactory, clientConfig); try { await responseStream.WriteAsync(new ClientStatus { Stats = clientRunner.GetStats(false) }); while (await requestStream.MoveNext()) { var reset = requestStream.Current.Mark.Reset; await responseStream.WriteAsync(new ClientStatus { Stats = clientRunner.GetStats(reset) }); } } finally { _logger.LogInformation("Exiting RunClient."); await clientRunner.StopAsync(); } }
public void SurprisingStatusShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.MultipleChoices); Assert.That(async() => await cr(client), Throws.TypeOf <HttpException>() .And.Message.Contains("Received an unexpected response for")); }
static void Main() { var runner = ClientRunner.OnWorkerThread(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(runner.WithClient(GFApi.CreateClient()))); }
public void NoErrorBodyShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Forbidden); Assert.That(async() => await cr(client), Throws.TypeOf <HttpException>() .And.Message.Contains("with no body")); }
public async Task AddressNotFoundShouldThrowException(string type, ClientRunner cr, Type t) { var ip = "1.2.3.16"; var client = CreateClient(type, ip, HttpStatusCode.NotFound, content: ErrorJson("IP_ADDRESS_NOT_FOUND", "The value 1.2.3.16 is not in the database.")); await cr(client, ip); }
public void EmptyBodyShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type); Assert.That(async() => await cr(client), Throws.TypeOf <HttpException>() .And.Message.Contains("message body")); }
public void BadContentTypeShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.OK, content: CountryJson, contentType: "bad/content-type"); Assert.That(async() => await cr(client), Throws.TypeOf <GeoIP2Exception>() .And.Message.Contains("but it does not appear to be JSON")); }
public void WeirdErrorBodyShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Forbidden, content: "{\"weird\": 42}"); Assert.That(async() => await cr(client), Throws.TypeOf <HttpException>() .And.Message.Contains("does not specify code or error keys")); }
public async void CoreSurprisingStatusShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClientCore(type, status: HttpStatusCode.MultipleChoices); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <HttpException>(exception); Assert.Contains("Received an unexpected response for", exception.Message); }
public void UndeserializableJsonShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.OK, content: "{\"invalid\":yes}"); Assert.That(async() => await cr(client), Throws.TypeOf <GeoIP2Exception>() .And.Message.Contains("Received a 200 response but not decode it as JSON")); }
public void UnexpectedErrorBodyShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Forbidden, content: "{\"invalid\": }"); Assert.That(async() => await cr(client), Throws.TypeOf <HttpException>() .And.Message.Contains("it did not include the expected JSON body")); }
public void InternalServerErrorShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.InternalServerError, content: "Internal Server Error"); Assert.That(async() => await cr(client), Throws.TypeOf <HttpException>() .And.Message.Contains("Received a server (500) error")); }
public void WebServiceErrorShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Forbidden, content: ErrorJson("IP_ADDRESS_INVALID", "The value 1.2.3 is not a valid IP address")); Assert.That(async() => await cr(client), Throws.TypeOf <InvalidRequestException>() .And.Message.Contains("not a valid IP address")); }
public async void CoreNoErrorBodyShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClientCore(type, status: HttpStatusCode.Forbidden); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <HttpException>(exception); Assert.Contains("with no body", exception.Message); }
public void MissingUserIdShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Unauthorized, content: ErrorJson("USER_ID_REQUIRED", "You have not supplied a MaxMind user ID in the Authorization header.")); Assert.That(async() => await cr(client), Throws.TypeOf <AuthenticationException>() .And.Message.Contains("You have not supplied a MaxMind user ID in the Authorization header.")); }
public async void CoreEmptyBodyShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClientCore(type); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <HttpException>(exception); Assert.Contains("message body", exception.Message); }
public void AddressReservedShouldThrowException(string type, ClientRunner cr, Type t) { var ip = "1.2.3.17"; var client = CreateClient(type, ip, HttpStatusCode.Forbidden, content: ErrorJson("IP_ADDRESS_RESERVED", "The value 1.2.3.17 belongs to a reserved or private range.")); Assert.That(async() => await cr(client, ip), Throws.TypeOf <AddressNotFoundException>() .And.Message.Contains("The value 1.2.3.17 belongs to a reserved or private range")); }
public void BadCharsetRequirementShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.NotAcceptable, content: "Cannot satisfy your Accept-Charset requirements", contentType: "text/plain"); Assert.That(async() => await cr(client), Throws.TypeOf <HttpException>() .And.Message.Contains("Cannot satisfy your Accept-Charset requirements")); }
public async void CoreWeirdErrorBodyShouldThrowExceptionAsync(string type, ClientRunner cr, Type t) { var client = CreateClientCore(type, status: HttpStatusCode.Forbidden, content: "{\"weird\": 42}"); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <HttpException>(exception); Assert.Contains("does not specify code or error keys", exception.Message); }
public void UnknownUserIdShouldThrowException(string type, ClientRunner cr, Type t) { var msg = "You have supplied an invalid MaxMind user ID and/or license key in the Authorization header."; var client = CreateClient(type, status: HttpStatusCode.Unauthorized, content: ErrorJson("USER_ID_UNKNOWN", msg)); Assert.That(async() => await cr(client), Throws.TypeOf <AuthenticationException>() .And.Message.Contains(msg)); }
public void PermissionRequiredShouldThrowException(string type, ClientRunner cr, Type t) { var msg = "You do not have permission to use this web service."; var client = CreateClient(type, status: HttpStatusCode.Forbidden, content: ErrorJson("PERMISSION_REQUIRED", msg)); Assert.That(async() => await cr(client), Throws.TypeOf <PermissionRequiredException>() .And.Message.Contains(msg)); }
public async void CoreUndeserializableJsonShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClientCore(type, status: HttpStatusCode.OK, content: "{\"invalid\":yes}"); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <GeoIP2Exception>(exception); Assert.Contains("Received a 200 response but not decode it as JSON", exception.Message); }
/* * helper: If you dont like duplicationg code. Use this */ private static (ServerRunner serverRunner, Player playerInit, ClientRunner clientRunner) InitiateServer() { var server = new ServerRunner(); server.Start(); var client = new ClientRunner("127.0.0.1", 32123); client.Start(); client.JoinServer("player"); return(server, server.GetPlayer("player"), client); }
public async void CoreAddressNotFoundShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClientCore(type, status: HttpStatusCode.NotFound, content: ErrorJson("IP_ADDRESS_NOT_FOUND", "The value 1.2.3.16 is not in the database.")); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <AddressNotFoundException>(exception); Assert.Contains("The value 1.2.3.16 is not in the database", exception.Message); }
public async void UnexpectedErrorBodyShouldThrowExceptionAsync(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Forbidden, content: "{\"invalid\": }"); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <HttpException>(exception); Assert.Contains("it did not include the expected JSON body", exception.Message); }
public void OutOfQueriesShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.PaymentRequired, content: ErrorJson("OUT_OF_QUERIES", "The license key you have provided is out of queries. Please purchase more queries to use this service.")); Assert.That(async() => await cr(client), Throws.TypeOf <OutOfQueriesException>() .And.Message.Contains("The license key you have provided is out of queries")); }
public async void CoreBadContentTypeShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClientCore(type, status: HttpStatusCode.OK, content: CountryJson, contentType: "bad/content-type"); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <GeoIP2Exception>(exception); Assert.Contains("but it does not appear to be JSON", exception.Message); }
public async void CoreInternalServerErrorShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClientCore(type, status: HttpStatusCode.InternalServerError, content: "Internal Server Error"); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <HttpException>(exception); Assert.Contains("Received a server (500) error", exception.Message); }
public void InvalidAuthShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Unauthorized, content: ErrorJson("AUTHORIZATION_INVALID", "You have supplied an invalid MaxMind user ID and/or license key in the Authorization header.")); Assert.That(async() => await cr(client), Throws.TypeOf <AuthenticationException>() .And.Message.Contains("You have supplied an invalid MaxMind user ID and/or license key")); }
public async void CoreWebServiceErrorShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClientCore(type, status: HttpStatusCode.Forbidden, content: ErrorJson("IP_ADDRESS_INVALID", "The value 1.2.3 is not a valid IP address")); var exception = await Record.ExceptionAsync(async() => await cr(client)); Assert.NotNull(exception); Assert.IsType <InvalidRequestException>(exception); Assert.Contains("not a valid IP address", exception.Message); }
public override void Run() { var json = DataFileLoader.Load(File); var config = JsonConvert.DeserializeObject<FileRunnerConfig>(json, new ClaimConverter()); if (config.Clients != null) { var r = new ClientRunner(this); r.Run(config.Clients); } if (config.Scopes != null) { var r = new ScopeRunner(this); r.Run(config.Scopes); } }
public async Task IncorrectlyFormattedIPAddressShouldThrowException(string type, ClientRunner cr, Type t) { await cr(CreateClient(type), "foo"); }
public async Task InternalServerErrorShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.InternalServerError, content: "Internal Server Error"); await cr(client); }
public async Task InvalidAuthShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Unauthorized, content: ErrorJson("AUTHORIZATION_INVALID", "You have supplied an invalid MaxMind user ID and/or license key in the Authorization header.")); await cr(client); }
public async Task CorrectlyFormattedResponseShouldDeserializeIntoResponseObject(string type, ClientRunner cr, Type t) { var client = CreateClient(type, content: CountryJson); var result = await cr(client); Assert.That(result, Is.Not.Null); Assert.That(result.GetType(), Is.EqualTo(t)); }
public async Task WebServiceErrorShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Forbidden, content: ErrorJson("IP_ADDRESS_INVALID", "The value 1.2.3 is not a valid IP address")); await cr(client); }
public async Task WeirdErrorBodyShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Forbidden, content: "{\"weird\": 42}"); await cr(client); }
public async Task MissingLicenseShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Unauthorized, content: ErrorJson("LICENSE_KEY_REQUIRED", "You have not supplied a MaxMind license key in the Authorization header.")); await cr(client); }
public async Task UndeserializableJsonShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.OK, content: "{\"invalid\":yes}"); await cr(client); }
public async Task MissingUserIdShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Unauthorized, content: ErrorJson("USER_ID_REQUIRED", "You have not supplied a MaxMind user ID in the Authorization header.")); await cr(client); }
public async Task SurprisingStatusShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.MultipleChoices); await cr(client); }
public async Task EmptyBodyShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type); await cr(client); }
public async Task NoErrorBodyShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.Forbidden); await cr(client); }
public async Task OutOfQueriesShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.PaymentRequired, content: ErrorJson("OUT_OF_QUERIES", "The license key you have provided is out of queries. Please purchase more queries to use this service.")); await cr(client); }
public async Task MeEndpointIsCalledCorrectly(string type, ClientRunner cr, Type t) { var client = CreateClient(type, "me", content: CountryJson); var result = await cr(client, null); Assert.That(result, Is.Not.Null); }
public async Task BadContentTypeShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.OK, content: CountryJson, contentType: "bad/content-type"); await cr(client); }
public async Task BadCharsetRequirementShouldThrowException(string type, ClientRunner cr, Type t) { var client = CreateClient(type, status: HttpStatusCode.NotAcceptable, content: "Cannot satisfy your Accept-Charset requirements", contentType: "text/plain"); await cr(client); }
public async Task AddressReservedShouldThrowException(string type, ClientRunner cr, Type t) { var ip = "1.2.3.17"; var client = CreateClient(type, ip, HttpStatusCode.Forbidden, content: ErrorJson("IP_ADDRESS_RESERVED", "The value 1.2.3.17 belongs to a reserved or private range.")); await cr(client, ip); }