public async Task CheckLinkSharing_LinkSharingDisabled_ForbiddenError() { var env = new TestEnvironment(); env.SetUser(User02, SystemRoles.User); env.SetProject(Project03); RpcMethodErrorResult result = await env.Controller.CheckLinkSharing() as RpcMethodErrorResult; Assert.That(result.ErrorCode, Is.EqualTo((int)RpcErrorCode.InvalidRequest), "The user should be forbidden to join the project"); }
public async Task Invite_SharingDisabled_ForbiddenError() { var env = new TestEnvironment(); env.SetUser(User02, SystemRoles.User); env.SetProject(Project01); const string email = "*****@*****.**"; RpcMethodErrorResult result = await env.Controller.Invite(email) as RpcMethodErrorResult; Assert.That(result.ErrorCode, Is.EqualTo((int)RpcErrorCode.InvalidRequest), "The user should be forbidden from inviting other users"); }
// This method gets called by a runtime. // Use this method to add services to the container public void ConfigureServices(IServiceCollection services) { var globalJsonSerializerOptions = new System.Text.Json.JsonSerializerOptions { //Example json config IgnoreNullValues = false, WriteIndented = true }; void ConfigureRpc(RpcServerConfiguration config) { //(Optional) Hard cap on batch size, will block requests will larger sizes, defaults to no limit config.BatchRequestLimit = 5; //(Optional) If true returns full error messages in response, defaults to false config.ShowServerExceptions = false; //(Optional) Configure how the router serializes requests config.JsonSerializerSettings = globalJsonSerializerOptions; //(Optional) Configure custom exception handling for exceptions during invocation of the method config.OnInvokeException = (context) => { if (context.Exception is InvalidOperationException) { //Handle a certain type of exception and return a custom response instead //of an internal server error int customErrorCode = 1; var customData = new { Field = "Value" }; var response = new RpcMethodErrorResult(customErrorCode, "Custom message", customData); return(OnExceptionResult.UseObjectResponse(response)); } //Continue to throw the exception return(OnExceptionResult.DontHandle()); }; } services .AddJsonRpcWithSwagger(ConfigureRpc, globalJsonSerializerOptions); }