Ejemplo n.º 1
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_User_Is_Not_Found()
        {
            var inputQuery = new GetUserInputQuery(Guid.NewGuid());
            var errors     = new List <IError>
            {
                new Error(UserErrorCodeEnumeration.NotFound, UserErrorMessage.NotFound)
            };
            var getUserResult = GetResult <User> .Fail(errors);

            _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult);

            Func <Task <UserOutputQuery> > result = async() => await _queryHandler.HandleAsync(inputQuery);

            var exceptionResult = await result.Should().ThrowExactlyAsync <ResourceNotFoundException>();

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Ejemplo n.º 2
0
        public async Task HandleAsync_Should_Return_UserOutputQuery()
        {
            var inputQuery = new GetUserInputQuery(Guid.NewGuid());
            var user       = User.Builder()
                             .SetId(inputQuery.UserId)
                             .SetEmail("*****@*****.**")
                             .SetServiceActive(DefaultUserSettings.ServiceActive)
                             .SetAnnouncementPreferenceLimit(DefaultUserSettings.AnnouncementPreferenceLimit)
                             .SetAnnouncementSendingFrequency(DefaultUserSettings.AnnouncementSendingFrequency)
                             .Build();
            var getUserResult = GetResult <User> .Ok(user);

            var expectedResult = new UserOutputQuery(user.Id, user.Email, user.Picture, user.ServiceActive,
                                                     user.AnnouncementPreferenceLimit, user.AnnouncementSendingFrequency,
                                                     new List <RoomForRentAnnouncementPreferenceOutputQuery>(),
                                                     new List <FlatForRentAnnouncementPreferenceOutputQuery>());

            _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult);
            _mapperMock.Setup(x => x.Map <User, UserOutputQuery>(It.IsAny <User>())).Returns(expectedResult);

            var result = await _queryHandler.HandleAsync(inputQuery);

            result.Should().BeEquivalentTo(expectedResult);
        }