public async Task Create_log_error_bad_request_with_userId() { //Arrange var logError = new CreateLogErrorViewModelBuilder() .WithUserId(0) .Build(); var expected = new Response <CreateLogErrorViewModel>( data: logError, false, errors: new[] { "UserId must be greater than 0" } ); _logErrorServiceMock.Setup(x => x.CreateAsync(logError, default)) .Returns(Task.FromResult(expected)); //Act var logErrorController = new LogErrorsController(_logErrorServiceMock.Object, _loggerMock.Object); var actionResult = await logErrorController.PostAsync(logError); ////Assert var badRequestResult = Assert.IsType <BadRequestObjectResult>(actionResult.Result); badRequestResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest); var result = Assert.IsType <Response <CreateLogErrorViewModel> >(badRequestResult.Value); result.Should().BeEquivalentTo(expected); }
public async Task Create_log_error_success() { //Arrange var logError = new CreateLogErrorViewModelBuilder().Build(); var expected = new Response <CreateLogErrorViewModel>(logError, true); _logErrorServiceMock.Setup(x => x.CreateAsync(It.IsAny <CreateLogErrorViewModel>(), default)) .Returns(Task.FromResult(expected)); //Act var logErrorController = new LogErrorsController(_logErrorServiceMock.Object, _loggerMock.Object); var actionResult = await logErrorController.PostAsync(logError); //Assert var createdRequestResult = Assert.IsType <CreatedResult>(actionResult.Result); createdRequestResult.StatusCode.Should().Be((int)HttpStatusCode.Created); var result = Assert.IsType <Response <CreateLogErrorViewModel> >(createdRequestResult.Value); 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 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); }
public async Task Create_handle_response_success_false_if_log_error_is_not_persisted() { // Arrange var logError = new CreateLogErrorViewModelBuilder().Build(); _logErrorRepositoryMock.Setup(logErrorRepo => logErrorRepo.UnitOfWork.SaveEntitiesAsync(default))