コード例 #1
0
        public async void GetUserRelations_ReturnsBadRequestObjectResult_WhenTheUserIdIsInvalid()
        {
            var controller = new FriendsRelationsController(_loggerMock.Object, _mockUserService.Object, _mockRelationService.Object);

            //Act
            var result = await controller.GetUserFriends(ConstIds.InvalidGuid, _paginationsParams);

            //Assert
            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result.Result);

            Assert.Equal($"{ConstIds.InvalidGuid} is not valid guid.", badRequestObjectResult.Value);
        }
コード例 #2
0
        public async void GetUserRelations_ReturnsInternalServerErrorResult_WhenExceptionThrownInService()
        {
            //Arrange
            _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>()))
            .Throws(new ArgumentNullException(nameof(Guid)))
            .Verifiable();

            var controller = new FriendsRelationsController(_loggerMock.Object, _mockUserService.Object, _mockRelationService.Object);

            //Act
            var result = await controller.GetUserFriends(ConstIds.ExampleUserId, _paginationsParams);

            //Assert
            var internalServerErrorResult = Assert.IsType <StatusCodeResult>(result.Result);

            Assert.Equal(StatusCodes.Status500InternalServerError, internalServerErrorResult.StatusCode);
            _mockUserService.Verify();
        }
コード例 #3
0
        public async void GetUserRelations_ReturnsNotFoundObjectResult_WhenTheUserDoesntExist()
        {
            //Arrange
            _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>()))
            .ReturnsAsync(false)
            .Verifiable();

            var controller = new FriendsRelationsController(_loggerMock.Object, _mockUserService.Object, _mockRelationService.Object);

            //Act
            var result = await controller.GetUserFriends(ConstIds.ExampleUserId, _paginationsParams);

            //Assert
            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result.Result);

            Assert.Equal($"User: {ConstIds.ExampleUserId} not found.", notFoundObjectResult.Value);
            _mockUserService.Verify();
        }