public async Task Create_handle_response_success_false_if_model_is_not_valid() { // Arrange var logError = new CreateLogErrorViewModel(); var expected = new Response <CreateLogErrorViewModel>( data: logError, success: false, errors: new[] { "UserId must be greater than 0", "Title cannot be null", "Title cannot be empty", "Source cannot be null", "Source cannot be empty", "Level cannot be empty", "Level Informed value cannot be assigned", "Environment cannot be empty", "Environment Informed value cannot be assigned" }); //Act var service = new LogErrorService(_logErrorRepositoryMock.Object, _userRepositoryMock.Object); var result = await service.CreateAsync(logError); // Assert result .Should().BeEquivalentTo(expected); }
public async Task Create_handle_response_success_false_if_userId_is_not_be_greater_zero() { // Arrange var logError = new CreateLogErrorViewModelBuilder() .WithUserId(0) .Build(); var expected = new Response <CreateLogErrorViewModel>( data: logError, success: false, errors: new[] { "UserId must be greater than 0" }); //Act var service = new LogErrorService(_logErrorRepositoryMock.Object, _userRepositoryMock.Object); var result = await service.CreateAsync(logError); // Assert result .Should().BeEquivalentTo(expected); }
public void OnException(ExceptionContext context) { if (!context.ExceptionHandled && context.Exception != null) { string UserGlobalID = Accessor.HttpContext.User.Identity.Name == null ? "" : Accessor.HttpContext.User.Identity.Name; var result = new JsonResult(new ResponseMessage().GetMessage("Error while processing your request. please try after some time.", context.Exception.Message, MessageConstants.Error, false)); LogError logError = new LogError { CreatedBy = UserGlobalID, ErrorMessage = context.Exception.Message, Source = context.RouteData.Values["controller"] + "/" + context.RouteData.Values["action"], FunctionName = "", InnerException = context.Exception.InnerException == null?"": context.Exception.InnerException.ToString(), RecordStatusId = 1, StackTrace = context.Exception.StackTrace.ToString() }; LogErrorService.SaveLogError(logError); context.Result = result; //LogActivityService.WriteLogActivity("[" + UserGID + "][Exception][" + context.RouteData.Values["controller"] + "/" + context.RouteData.Values["action"] + "]" + context.Exception.Message, Accessor.HttpContext.Connection.RemoteIpAddress.ToString(), Environment.CurrentDirectory + "\\Log"); } }
public async Task Create_handle_response_success_false_if_user_not_found() { // Arrange var logError = new CreateLogErrorViewModelBuilder().Build(); _userRepositoryMock.Setup(svc => svc.GetAsync(It.IsAny <int>())) .Returns(Task.FromResult <User>(null)); var expected = new Response <CreateLogErrorViewModel>( data: logError, success: false, errors: new[] { $"User with id {logError.UserId} not found" }); // Act var service = new LogErrorService(_logErrorRepositoryMock.Object, _userRepositoryMock.Object); var result = await service.CreateAsync(logError); // Assert _userRepositoryMock.Verify(u => u.GetAsync(It.IsAny <int>())); result .Should().BeEquivalentTo(expected); }