public async Task GetGroupByIdHandler_ShouldReturnGroup_WhenGroupExists() { // Arrange GetGroupByIdQuery request = new GetGroupByIdQuery { GroupId = 1 }; IEnumerable <Group> expectedGroups = new[] { new Group { GroupId = 1 } }; IQueryable <Group> queryableMock = expectedGroups .AsQueryable() .BuildMock() .Object; _unitOfWorkMock .Setup(m => m.Groups.GetById(request.GroupId)) .Returns(queryableMock); GetGroupByIdQuery.Handler handler = new GetGroupByIdQuery.Handler(_mapperMock, _unitOfWorkMock.Object); // Act GroupResource group = await handler.Handle(request); // Assert Assert.NotNull(group); Assert.Equal(request.GroupId, group.GroupId); }
public async Task GetGroupByIdHandler_ShouldReturnNull_WhenGroupDoesNotExist() { // Arrange GetGroupByIdQuery request = new GetGroupByIdQuery { GroupId = 3891 }; IQueryable <Group> emptyQueryable = Enumerable .Empty <Group>() .AsQueryable() .BuildMock() .Object; _unitOfWorkMock .Setup(m => m.Groups.GetById(request.GroupId)) .Returns(emptyQueryable); GetGroupByIdQuery.Handler handler = new GetGroupByIdQuery.Handler(_mapperMock, _unitOfWorkMock.Object); // Act GroupResource group = await handler.Handle(request); // Assert Assert.Null(group); }