mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
small fix
This commit is contained in:
@@ -83,20 +83,6 @@ public class FriendshipControllerTests
|
||||
Assert.That(badRequestResult.Value, Is.EqualTo("Query cannot be empty"));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task Search_NotFound_IfThrowsSearchUsersException()
|
||||
{
|
||||
// Arrange
|
||||
_friendsServiceMock.Setup(f => f.SearchUsersAsync(It.IsAny<string>(), It.IsAny<Guid>()))
|
||||
.ThrowsAsync(new SearchUsersException(_fixture.Create<string>()));
|
||||
|
||||
// Act
|
||||
var result = await _controller.Search(_fixture.Create<string>());
|
||||
// Assert
|
||||
Assert.That(result, Is.InstanceOf<NotFoundObjectResult>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Search_StatusCode500_IfThrowsSomeException()
|
||||
{
|
||||
|
||||
@@ -44,6 +44,11 @@ public class FriendsRequestQueryController : Controller
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Ok(new List<FriendshipDto>());
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
@@ -70,6 +75,11 @@ public class FriendsRequestQueryController : Controller
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Ok(new List<FriendshipDto>());
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
|
||||
@@ -41,10 +41,10 @@ public class FriendshipController : Controller
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
catch (SearchUsersException ex)
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return NotFound(new { error = ex.Message });
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -69,6 +69,11 @@ public class FriendshipController : Controller
|
||||
_logger.LogError(ex, ex.Message);
|
||||
return Ok(Array.Empty<UserDto>());
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
|
||||
@@ -61,15 +61,18 @@ public class FriendshipServiceTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SearchUsersAsync_Throws_SearchUsersException_IfThrowsNotFoundByKeyException_String_Guid()
|
||||
public async Task SearchUsersAsync_Returns_EmptyList_IfThrowsNotFoundByKeyException_String_Guid()
|
||||
{
|
||||
// Arrange
|
||||
_usersRepositoryMock
|
||||
.Setup(u => u.SearchPotentialFriendsAsync(It.IsAny<Guid>(), It.IsAny<string>()))
|
||||
.ThrowsAsync(new NotFoundByKeyException<(string,Guid)>(("test",Guid.NewGuid()),"test"));
|
||||
|
||||
// Axt & Assert
|
||||
Assert.ThrowsAsync<SearchUsersException>(async () => await _service.SearchUsersAsync("test", Guid.NewGuid()));
|
||||
// Act
|
||||
var users = await _service.SearchUsersAsync("test", Guid.NewGuid());
|
||||
|
||||
// & Assert
|
||||
Assert.That(users, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -33,8 +33,7 @@ public class FriendshipService : IFriendshipService
|
||||
}
|
||||
catch (NotFoundByKeyException<(string, Guid)> ex)
|
||||
{
|
||||
throw new SearchUsersException(
|
||||
$"Users with given query: \"{query}\" for user with id {currentId} was not found", ex);
|
||||
return [];
|
||||
}
|
||||
catch (NotFoundByKeyException<Guid> ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user