Skip to content

tests for ticket and user service#75

Open
saenkaaa111 wants to merge 13 commits intodevfrom
serviceTests
Open

tests for ticket and user service#75
saenkaaa111 wants to merge 13 commits intodevfrom
serviceTests

Conversation

@saenkaaa111
Copy link
Collaborator

No description provided.

@saenkaaa111 saenkaaa111 requested review from Stepa28 and Svyatopes March 1, 2022 17:51
Copy link
Collaborator

@Stepa28 Stepa28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно дотестить сервисы, 37% это что-то оч мало
image


[HttpGet("{id}")]
[AuthorizeRole(Role.User, Role.Admin)]
public ActionResult<TicketModel> GetTicketById(int id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

при каких обстоятельствах у тебя не сработает if на 69 строке?

if (user.Persons.Contains(entity.Person))
if (user.Role == Role.Admin)
_ticketRepository.Update(entity, true);
else if(user.Persons.Contains(entity.Person))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это в один if замечательно схловывается

CheckUserRole(userId, Role.Admin);
var entity = _ticketRepository.GetById(id);
ThrowIfEntityNotFound(entity, id);
_ticketRepository.Update(entity, false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ThrowIfEntityNotFound в базовом сервисе(BaseService) есть, посмотри

.Returns(ticketsFiltredByIsDeletedProp);
_userRepositoryMock.Setup(x => x.GetById(userId)).Returns(new User() { Role = Role.Admin});

expectedTicketModels = expectedTicketModels.Where(o => !o.IsDeleted || allIncluded).ToList();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это подготовка данных, они должны готовятся в TicketServiceTestCaseSource

public void GetListTest(List<Ticket> tickets, List<TicketModel> expectedTicketModels, bool allIncluded, int userId)
{
// given
var ticketsFiltredByIsDeletedProp = tickets.Where(o => !o.IsDeleted || allIncluded).ToList();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в TicketServiceTestCaseSource должно быть

public void GetByIdNegativeAuthorizationExceptionTest(Role role, int userId)
{
//given
_userRepositoryMock.Setup(x => x.GetById(It.IsAny<int>())).Returns(new User() { Role = role, Id = userId});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут достаточно только Role, Id не обязателен

_userRepositoryMock.Verify(s => s.GetById(userId), Times.Exactly(2));
_ticketRepositoryMock.Verify(s => s.GetById(5), Times.Once);
_ticketRepositoryMock.Verify(s => s.Update(ticket, true), Times.Once);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

на Restore негативные есть, а на Delete где?



// when then
// then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

удали лишнюю строчку (ко всем негативным)

_userRepositoryMock.Setup(x => x.GetList(false)).Returns(usersFiltredByIsDeletedProp);
_userRepositoryMock.Setup(x => x.GetById(userId)).Returns(entities[0]);

List<UserModel> expectedFiltredByIsDeletedProp = expected.Where(o => !o.IsDeleted).ToList();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в UserServiceTestCaseSource

_userRepositoryMock.Setup(x => x.GetList(true)).Returns(usersFiltredByIsDeletedProp);
_userRepositoryMock.Setup(x => x.GetById(userId)).Returns(entities[0]);

List<UserModel> expectedFiltredByIsDeletedProp = expected.Where(o => o.IsDeleted).ToList();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в UserServiceTestCaseSource

@saenkaaa111 saenkaaa111 requested a review from Stepa28 March 2, 2022 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants