public void Should_Return_BadRequest_When_Update_And_An_Error_Happens() { // Arrange var fakes = new Fakes(); var fakeHttp = fakes.FakeHttpContextAccessor(true).Object; var fakeRepository = fakes.FakeUserRepositoryException().Object; var hashService = new HashService(); var userService = new UserService(fakes.Mapper, fakeHttp, fakeRepository, hashService); var user = fakes.Get <User>().First(); var request = fakes.Get <UpdateUserRequest>().First(); // Act var controller = new UserController(fakes.Mapper, userService); var actual = controller.Put(user.Id, request); // Assert Assert.NotNull(actual); Assert.IsType <ObjectResult>(actual.Result); var result = actual.Result as ObjectResult; Assert.NotNull(result.Value); Assert.Equal(400, result.StatusCode); // Bad Request Assert.IsType <Response>(result.Value); }
public void Should_Return_BadRequest_When_Register_And_An_Error_Happens() { // Arrange var fakes = new Fakes(); var fakeConfig = fakes.FakeConfiguration().Object; var fakeUserRepository = fakes.FakeUserRepositoryException().Object; var hashService = new HashService(); var tokenService = new TokenService(fakeConfig); var authService = new AuthService(fakes.Mapper, fakeUserRepository, tokenService, hashService); var request = fakes.Get <RegisterUserRequest>().First(); // Act var controller = new AuthController(fakes.Mapper, authService); var actual = controller.Register(request); // Assert Assert.NotNull(actual); Assert.IsType <ObjectResult>(actual.Result); var result = actual.Result as ObjectResult; Assert.NotNull(result.Value); Assert.Equal(400, result.StatusCode); // Bad Request Assert.IsType <Response>(result.Value); }
public void Should_Return_BadRequest_When_Get_And_Exception_Is_Thrown() { // Arrange var fakes = new Fakes(); var fakeHttp = fakes.FakeHttpContextAccessor(true).Object; var fakeRepository = fakes.FakeUserRepositoryException().Object; var hashService = new HashService(); var expected = Responses.BadRequestResponse("Test Exception"); // Act var service = new UserService(fakes.Mapper, fakeHttp, fakeRepository, hashService); var actual = service.Get().Result; // Assert Assert.ThrowsAnyAsync <Exception>(() => service.Get()); Assert.IsType <Response>(actual); Assert.NotNull(actual); Assert.Equal(expected, actual, new ResponseComparer()); }
public void Should_Return_BadRequest_When_Register_And_Exception_Is_Thrown() { // Arrange var fakes = new Fakes(); var fakeConfig = fakes.FakeConfiguration().Object; var fakeUserRepository = fakes.FakeUserRepositoryException().Object; var tokenService = new TokenService(fakeConfig); var hashService = new HashService(); var request = fakes.Get <RegisterUserRequest>().First(); var expected = Responses.BadRequestResponse("Test Exception"); // Act var service = new AuthService(fakes.Mapper, fakeUserRepository, tokenService, hashService); var actual = service.Register(request).Result; // Assert Assert.ThrowsAnyAsync <Exception>(() => service.Register(request)); Assert.IsType <Response>(actual); Assert.NotNull(actual); Assert.Equal(expected, actual, new ResponseComparer()); }