public void ErrorPlugin_CanProcessDifferentExceptionDataDictionaryTypes(IDictionary data, bool canMarkAsProcessed, int processedDataItemCount) { var errorPlugins = new List <IEventPlugin> { new ErrorPlugin(), new SimpleErrorPlugin() }; foreach (var plugin in errorPlugins) { if (data != null && data.Contains("@exceptionless")) { data.Remove("@exceptionless"); } var exception = new MyApplicationException("Test") { SetsDataProperty = data }; var client = CreateClient(); client.Configuration.AddDataExclusions("SetsDataProperty"); var context = new EventPluginContext(client, new Event()); context.ContextData.SetException(exception); plugin.Run(context); Assert.False(context.Cancel); Assert.Equal(canMarkAsProcessed, exception.Data != null && exception.Data.Contains("@exceptionless")); IData error = context.Event.GetError() as IData ?? context.Event.GetSimpleError(); Assert.NotNull(error); Assert.Equal(processedDataItemCount, error.Data.Count); } }
public void ErrorPlugin_CopyExceptionDataToRootErrorData() { var errorPlugins = new List <IEventPlugin> { new ErrorPlugin(), new SimpleErrorPlugin() }; foreach (var plugin in errorPlugins) { var exception = new MyApplicationException("Test") { RandomValue = "Test", SetsDataProperty = new Dictionary <object, string> { { 1, 1.GetType().Name }, { "test", "test".GetType().Name }, { Guid.NewGuid(), typeof(Guid).Name }, { false, typeof(bool).Name } } }; var client = CreateClient(); var context = new EventPluginContext(client, new Event()); context.ContextData.SetException(exception); plugin.Run(context); Assert.False(context.Cancel); IData error = context.Event.GetError() as IData ?? context.Event.GetSimpleError(); Assert.NotNull(error); Assert.Equal(5, error.Data.Count); } }
public void ErrorPlugin_IgnoredProperties() { var exception = new MyApplicationException("Test") { IgnoredProperty = "Test", RandomValue = "Test" }; var errorPlugins = new List<IEventPlugin> { new ErrorPlugin(), new SimpleErrorPlugin() }; foreach (var plugin in errorPlugins) { var client = new ExceptionlessClient(); var context = new EventPluginContext(client, new Event()); context.ContextData.SetException(exception); plugin.Run(context); IData error = context.Event.GetError() as IData ?? context.Event.GetSimpleError(); Assert.NotNull(error); Assert.True(error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties)); var json = error.Data[Error.KnownDataKeys.ExtraProperties] as string; Assert.Equal("{\"ignored_property\":\"Test\",\"random_value\":\"Test\"}", json); client.Configuration.AddDataExclusions("Ignore*"); context = new EventPluginContext(client, new Event()); context.ContextData.SetException(exception); plugin.Run(context); error = context.Event.GetError() as IData ?? context.Event.GetSimpleError(); Assert.NotNull(error); Assert.True(error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties)); json = error.Data[Error.KnownDataKeys.ExtraProperties] as string; Assert.Equal("{\"random_value\":\"Test\"}", json); } }
public async Task <IActionResult> Put(string id, [FromBody] ApplicationPostModel model) { var app = await _applicationManager.FindByIdAsync(id); if (app != null) { app.Name = model.Name; app.ApplicationId = model.ApplicationId; app.Description = model.Description; app.Enabled = model.Enabled; var result = await _applicationManager.UpdateAsync(app); if (result.Succeeded) { return(NoContent()); } var ex = new MyApplicationException(); ex.SetIdentityErrors(result.Errors); throw ex; } var msg = $"找不到指定的应用程序 {id}"; _logger.LogWarning(msg); return(NotFound(new ApiErrorResult <ApiError>(new ApiError(ApiErrorCodes.ObjectNotFound, msg)))); }
public async Task <IActionResult> Post([FromBody] ApplicationPostModel model) { if (await _applicationManager.Applications.AnyAsync(x => x.Name == model.Name || x.ApplicationId == model.ApplicationId)) { return(BadRequest(new ApiErrorResult <ApiError>(new ApiError(ApiErrorCodes.BadArgument, "存在重复的名称或应用程序Id。")))); } var app = new Application { Id = await _identityGenerator.GenerateAsync(), Name = model.Name, ApplicationId = model.ApplicationId, Description = model.Description, Enabled = model.Enabled }; var result = await _applicationManager.CreateApplicationAsync(app); if (result.Succeeded) { return(StatusCode(201, new ApiResult <ObjectCreationOutputModel <long> >(new ObjectCreationOutputModel <long>(app.Id, $"{Request.Scheme}://{Request.Host.Value}/api/applications/{app.Id}")))); } var ex = new MyApplicationException(); ex.SetIdentityErrors(result.Errors); throw ex; }
public async Task <IActionResult> Delete([FromRoute] string id) { var user = await _userManager.FindByEmailAsync(User.Identity.Name); user.AvatarId = _applicationSettings.CurrentValue.DefaultAvatar; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(Ok(new ApiResult <string>($"/api/files/{user.AvatarId}"))); } var ex = new MyApplicationException(); ex.SetIdentityErrors(result.Errors); throw ex; }
public async Task <IActionResult> Delete(string id) { var app = await _applicationManager.FindByIdAsync(id); if (app != null) { var result = await _applicationManager.RemoveApplicationAsync(app); if (result.Succeeded) { return(NoContent()); } var ex = new MyApplicationException(); ex.SetIdentityErrors(result.Errors); throw ex; } return(NotFound(new ApiErrorResult <ApiError>(new ApiError(ApiErrorCodes.ObjectNotFound, $"找不到指定的应用程序 {id}")))); }
public async Task <IActionResult> Patch([FromRoute] string id, [FromBody] AccountPasswordPatchModel model) { var user = await _userManager.FindByEmailAsync(User.Identity.Name); var result = await _userManager.ChangePasswordAsync(user, model.CurrentPassword, model.Password); if (result.Succeeded) { return(NoContent()); } if (result.Errors.FirstOrDefault(x => x.Code == _errorDescriber.PasswordMismatch().Code) != null) { return(BadRequest(new ApiErrorResult <ApiError>(new ApiError(ApiErrorCodes.BadArgument, "当前密码验证失败。")))); } var ex = new MyApplicationException(); ex.SetIdentityErrors(result.Errors); throw ex; }
public void ErrorPlugin_IgnoredProperties() { var exception = new MyApplicationException("Test") { IgnoredProperty = "Test", RandomValue = "Test" }; var errorPlugins = new List <IEventPlugin> { new ErrorPlugin(), new SimpleErrorPlugin() }; foreach (var plugin in errorPlugins) { var client = CreateClient(); var context = new EventPluginContext(client, new Event()); context.ContextData.SetException(exception); plugin.Run(context); IData error = context.Event.GetError() as IData ?? context.Event.GetSimpleError(); Assert.NotNull(error); Assert.True(error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties)); var json = error.Data[Error.KnownDataKeys.ExtraProperties] as string; Assert.Equal("{\"IgnoredProperty\":\"Test\",\"RandomValue\":\"Test\"}", json); client.Configuration.AddDataExclusions("Ignore*"); context = new EventPluginContext(client, new Event()); context.ContextData.SetException(exception); plugin.Run(context); error = context.Event.GetError() as IData ?? context.Event.GetSimpleError(); Assert.NotNull(error); Assert.True(error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties)); json = error.Data[Error.KnownDataKeys.ExtraProperties] as string; Assert.Equal("{\"RandomValue\":\"Test\"}", json); } }
public async Task <IActionResult> Patch(string id, [FromBody] ApplicationPatchSubscribersModel model) { var app = await _applicationManager.FindByIdAsync(id); if (app == null) { var msg = $"找不到指定的应用程序 {id}"; _logger.LogWarning(msg); return(NotFound(new ApiErrorResult <ApiError>(new ApiError(ApiErrorCodes.ObjectNotFound, msg)))); } var result = await _applicationManager.SetSubscribersAsync(app, model.UserList); if (result.Succeeded) { return(NoContent()); } var ex = new MyApplicationException(); ex.SetIdentityErrors(result.Errors); throw ex; }
public void ErrorPlugin_CopyExceptionDataToRootErrorData() { var errorPlugins = new List<IEventPlugin> { new ErrorPlugin(), new SimpleErrorPlugin() }; foreach (var plugin in errorPlugins) { var exception = new MyApplicationException("Test") { RandomValue = "Test", SetsDataProperty = new Dictionary<object, string> { { 1, 1.GetType().Name }, { "test", "test".GetType().Name }, { Guid.NewGuid(), typeof(Guid).Name }, { false, typeof(bool).Name } } }; var client = new ExceptionlessClient(); var context = new EventPluginContext(client, new Event()); context.ContextData.SetException(exception); plugin.Run(context); Assert.False(context.Cancel); IData error = context.Event.GetError() as IData ?? context.Event.GetSimpleError(); Assert.NotNull(error); Assert.Equal(5, error.Data.Count); } }
public void ErrorPlugin_CanProcessDifferentExceptionDataDictionaryTypes(IDictionary data, bool canMarkAsProcessed, int processedDataItemCount) { var errorPlugins = new List<IEventPlugin> { new ErrorPlugin(), new SimpleErrorPlugin() }; foreach (var plugin in errorPlugins) { if (data != null && data.Contains("@exceptionless")) data.Remove("@exceptionless"); var exception = new MyApplicationException("Test") { SetsDataProperty = data }; var client = new ExceptionlessClient(); client.Configuration.AddDataExclusions("SetsDataProperty"); var context = new EventPluginContext(client, new Event()); context.ContextData.SetException(exception); plugin.Run(context); Assert.False(context.Cancel); Assert.Equal(canMarkAsProcessed, exception.Data != null && exception.Data.Contains("@exceptionless")); IData error = context.Event.GetError() as IData ?? context.Event.GetSimpleError(); Assert.NotNull(error); Assert.Equal(processedDataItemCount, error.Data.Count); } }