Пример #1
0
        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);
        }
Пример #2
0
        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);
        }