Beispiel #1
0
        public async Task HandleAsync_Should_Throw_ValidationException_When_State_Is_Not_Found()
        {
            var command = new UpdateCityCommand(Guid.NewGuid(), Array.Empty <byte>(), "NewName", "NewPolishName",
                                                Guid.NewGuid());
            var city = City.Builder()
                       .SetId(command.CityId)
                       .SetRowVersion(command.RowVersion)
                       .SetName("Name")
                       .SetPolishName("PolishName")
                       .SetStateId(Guid.NewGuid())
                       .Build();
            var getCityResult = GetResult <City> .Ok(city);

            var errors = new Collection <IError>
            {
                new Error(StateErrorCodeEnumeration.NotFound, StateErrorMessage.NotFound)
            };
            var getStateResult = GetResult <State> .Fail(errors);

            _cityGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getCityResult);
            _stateGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getStateResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(command);

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #2
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_FlatForRentAnnouncementPreference_Is_Not_Found()
        {
            var inputQuery = new GetFlatForRentAnnouncementPreferenceInputQuery(Guid.NewGuid(), 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 errors = new Collection <IError>
            {
                new Error(FlatForRentAnnouncementPreferenceErrorCode.NotFound, FlatForRentAnnouncementPreferenceErrorMessage.NotFound)
            };
            var getFlatForRentAnnouncementPreferenceResult =
                GetResult <FlatForRentAnnouncementPreference> .Fail(errors);

            _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult);
            _flatForRentAnnouncementPreferenceGetterServiceMock
            .Setup(x => x.GetByByUserAndId(It.IsAny <User>(), It.IsAny <Guid>()))
            .Returns(getFlatForRentAnnouncementPreferenceResult);

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

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #3
0
        public async Task ValidateAsync_Should_Set_Fail_GrantValidationResult_When_Account_Does_Not_Exist()
        {
            var errors = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound)
            };
            var getAccountResult = GetResult <Account> .Fail(errors);

            var context = new ResourceOwnerPasswordValidationContext
            {
                Request = new ValidatedTokenRequest
                {
                    GrantType = GrantType.ResourceOwnerPassword
                }
            };
            var expectedResult = new GrantValidationResult(TokenRequestErrors.InvalidTarget, "Invalid credentials");

            _accountGetterServiceMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(getAccountResult);

            Func <Task> result = async() => await _resourceOwnerPasswordValidator.ValidateAsync(context);

            await result.Should().NotThrowAsync <Exception>();

            context.Result.Should().BeEquivalentTo(expectedResult);
        }
Beispiel #4
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_Room_For_Rent_Announcement_Preference_Is_Not_Found()
        {
            var command = new UpdateRoomForRentAnnouncementPreferenceCommand(Guid.NewGuid(), Guid.NewGuid(),
                                                                             Guid.NewGuid(), 1, 1500, RoomTypeEnumeration.Double, new List <Guid> {
                Guid.NewGuid()
            });
            var user = User.Builder()
                       .SetId(command.UserId)
                       .SetEmail("*****@*****.**")
                       .SetServiceActive(DefaultUserSettings.ServiceActive)
                       .SetAnnouncementPreferenceLimit(DefaultUserSettings.AnnouncementPreferenceLimit)
                       .SetAnnouncementSendingFrequency(DefaultUserSettings.AnnouncementSendingFrequency)
                       .Build();
            var getUserResult = GetResult <User> .Ok(user);

            var errors = new Collection <IError>
            {
                new Error(RoomForRentAnnouncementPreferenceErrorCode.NotFound,
                          RoomForRentAnnouncementPreferenceErrorMessage.NotFound)
            };
            var getRoomForRentAnnouncementPreferenceResult = GetResult <RoomForRentAnnouncementPreference> .Fail(errors);

            _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult);
            _roomForRentAnnouncementPreferenceGetterServiceMock
            .Setup(x => x.GetByByUserAndId(It.IsAny <User>(), It.IsAny <Guid>()))
            .Returns(getRoomForRentAnnouncementPreferenceResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(command);

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #5
0
        public async Task ProvideAccountForExternalLoginAsync_Should_Return_Created_Account()
        {
            var errors = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound)
            };
            var getAccountResult = GetResult <Account> .Fail(errors);

            const string email   = "*****@*****.**";
            var          account = Account.Builder()
                                   .SetId(Guid.NewGuid())
                                   .SetEmail(email)
                                   .SetConfirmed(true)
                                   .SetPasswordHash(string.Empty)
                                   .SetSecurityStamp(Guid.NewGuid())
                                   .SetCreated(DateTimeOffset.UtcNow)
                                   .SetRoles(new List <Guid> {
                Guid.NewGuid()
            })
                                   .Build();

            _accountGetterServiceMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(getAccountResult);
            _accountCreatorServiceMock.Setup(x => x.CreateAsync(It.IsAny <Guid>(), It.IsAny <string>(),
                                                                It.IsAny <string>(), It.IsAny <Guid>())).ReturnsAsync(account);

            var result = await _accountProviderService.ProvideAccountForExternalLoginAsync(email, Guid.NewGuid());

            result.Email.Should().Be(email);
            result.Confirmed.Should().BeTrue();
        }
Beispiel #6
0
        public async Task IsActiveAsync_Should_Set_IsActive_To_False_When_Account_Is_Not_Found()
        {
            var errors = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound)
            };
            var getAccountResult = GetResult <Account> .Fail(errors);

            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, "*****@*****.**"),
                new Claim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString())
            };
            var claimsIdentities = new List <ClaimsIdentity>
            {
                new ClaimsIdentity(claims)
            };
            var cp      = new ClaimsPrincipal(claimsIdentities);
            var context = new IsActiveContext(cp, new Client(), "caller");

            _accountGetterServiceMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(getAccountResult);

            Func <Task> result = async() => await _profileService.IsActiveAsync(context);

            await result.Should().NotThrowAsync <Exception>();

            context.IsActive.Should().BeFalse();
        }
Beispiel #7
0
        public async Task VerifyEmailIsNotTakenAsync_Should_Return_VerificationResult_With_Success_True()
        {
            const string email            = "*****@*****.**";
            var          getAccountResult = GetResult <Account> .Fail(new List <IError>());

            var expectedResult = VerificationResult.Ok();

            _accountGetterServiceMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>())).ReturnsAsync(getAccountResult);

            var result = await _accountVerificationService.VerifyEmailIsNotTakenAsync(email);

            result.Should().BeEquivalentTo(expectedResult);
        }
Beispiel #8
0
        public async Task <GetResult <User> > GetByIdAsync(Guid id)
        {
            var user = await _userRepository.GetByIdAsync(id);

            if (user is null)
            {
                var errors = new List <IError>
                {
                    new Error(UserErrorCodeEnumeration.NotFound, UserErrorMessage.NotFound)
                };
                return(GetResult <User> .Fail(errors));
            }
            return(GetResult <User> .Ok(user));
        }
Beispiel #9
0
        public async Task <GetResult <FlatForRentAnnouncement> > GetByIdAsync(Guid id)
        {
            var flatForRentAnnouncement = await _flatForRentAnnouncementRepository.GetByIdAsync(id);

            if (flatForRentAnnouncement is null)
            {
                var errors = new Collection <IError>
                {
                    new Error(FlatForRentAnnouncementErrorCodeEnumeration.NotFound, FlatForRentAnnouncementErrorMessage.NotFound)
                };
                return(GetResult <FlatForRentAnnouncement> .Fail(errors));
            }
            return(GetResult <FlatForRentAnnouncement> .Ok(flatForRentAnnouncement));
        }
Beispiel #10
0
        public async Task <GetResult <City> > GetByIdAsync(Guid id)
        {
            var city = await _cityRepository.GetByIdAsync(id);

            if (city is null)
            {
                var errors = new Collection <IError>
                {
                    new Error(CityErrorCodeEnumeration.NotFound, CityErrorMessage.NotFound)
                };
                return(GetResult <City> .Fail(errors));
            }
            return(GetResult <City> .Ok(city));
        }
Beispiel #11
0
        public GetResult <RoomForRentAnnouncementPreference> GetByByUserAndId(User user, Guid id)
        {
            var roomForRentAnnouncementPreference = user.RoomForRentAnnouncementPreferences.SingleOrDefault(x => x.Id == id);

            if (roomForRentAnnouncementPreference is null)
            {
                var errors = new Collection <IError>
                {
                    new Error(RoomForRentAnnouncementPreferenceErrorCode.NotFound, RoomForRentAnnouncementPreferenceErrorMessage.NotFound)
                };
                return(GetResult <RoomForRentAnnouncementPreference> .Fail(errors));
            }
            return(GetResult <RoomForRentAnnouncementPreference> .Ok(roomForRentAnnouncementPreference));
        }
Beispiel #12
0
        public async Task <GetResult <State> > GetByIdAsync(Guid id)
        {
            var state = await _stateRepository.GetByIdAsync(id);

            if (state is null)
            {
                var errors = new Collection <IError>
                {
                    new Error(StateErrorCodeEnumeration.NotFound, StateErrorMessage.NotFound)
                };
                return(GetResult <State> .Fail(errors));
            }

            return(GetResult <State> .Ok(state));
        }
Beispiel #13
0
        public async Task GetByEmailAsync_Should_Return_GetResult_With_Errors_When_Account_Is_Not_Found()
        {
            const string email  = "*****@*****.**";
            var          errors = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound)
            };
            var expectedResult = GetResult <Account> .Fail(errors);

            _accountRepositoryMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>())).Returns(Task.FromResult <Account>(null));

            var result = await _accountGetterService.GetByEmailAsync(email);

            result.Should().BeEquivalentTo(expectedResult);
        }
Beispiel #14
0
        public async Task <GetResult <Account> > GetByEmailAsync(string email)
        {
            var account = await _accountRepository.GetByEmailAsync(email);

            if (account is null)
            {
                var errors = new Collection <IError>
                {
                    new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound)
                };
                return(GetResult <Account> .Fail(errors));
            }

            return(GetResult <Account> .Ok(account));
        }
Beispiel #15
0
        public async Task GetByIdAsync_Should_Return_GetResult_With_Errors_When_State_Is_Not_Found()
        {
            var id     = Guid.NewGuid();
            var errors = new Collection <IError>
            {
                new Error(StateErrorCodeEnumeration.NotFound, StateErrorMessage.NotFound)
            };
            var expectedResult = GetResult <State> .Fail(errors);

            _stateRepositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).Returns(Task.FromResult <State>(null));

            var result = await _stateGetterService.GetByIdAsync(id);

            result.Should().BeEquivalentTo(expectedResult);
        }
Beispiel #16
0
        public async Task GetByIdAsync_Should_Return_GetResult_Fail()
        {
            var errors = new Collection <IError>
            {
                new Error(RoomForRentAnnouncementErrorCodeEnumeration.NotFound, RoomForRentAnnouncementErrorMessage.NotFound)
            };
            var expectedResult = GetResult <RoomForRentAnnouncement> .Fail(errors);

            _roomForRentAnnouncementRepositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult <RoomForRentAnnouncement>(null));

            var result = await _service.GetByIdAsync(Guid.NewGuid());

            result.Should().BeEquivalentTo(expectedResult);
        }
Beispiel #17
0
        public async Task <GetResult <Role> > GetByIdAsync(Guid id)
        {
            var role = await _roleRepository.GetByIdAsync(id);

            if (role is null)
            {
                var errors = new Collection <IError>
                {
                    new Error(RoleErrorCodeEnumeration.NotFound, RoleErrorMessage.NotFound)
                };
                return(GetResult <Role> .Fail(errors));
            }

            return(GetResult <Role> .Ok(role));
        }
Beispiel #18
0
        public async Task GetByIdAsync_Should_Return_GetResult_With_Errors_When_CityDistrict_Is_Not_Found()
        {
            var errors = new Collection <IError>
            {
                new Error(CityDistrictErrorCodeEnumeration.NotFound, CityDistrictErrorMessage.NotFound)
            };
            var expectedResult = GetResult <CityDistrict> .Fail(errors);

            _cityDistrictRepositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult <CityDistrict>(null));

            var result = await _service.GetByIdAsync(Guid.NewGuid());

            result.Should().BeEquivalentTo(expectedResult);
        }
Beispiel #19
0
        public async Task VerifyUserDoesNotExistAsync_Should_Return_VerificationResult_With_Success_True()
        {
            var errors = new List <IError>
            {
                new Error(UserErrorCodeEnumeration.NotFound, UserErrorMessage.NotFound)
            };
            var getUserResult = GetResult <User> .Fail(errors);

            var expectedResult = VerificationResult.Ok();

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

            var result = await _service.VerifyUserDoesNotExistAsync(Guid.NewGuid());

            result.Should().BeEquivalentTo(expectedResult);
        }
Beispiel #20
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_FlatForRentAnnouncement_Is_Not_Found()
        {
            var errors = new Collection <IError>
            {
                new Error(FlatForRentAnnouncementErrorCodeEnumeration.NotFound, FlatForRentAnnouncementErrorMessage.NotFound)
            };
            var getFlatForRentAnnouncementResult = GetResult <FlatForRentAnnouncement> .Fail(errors);

            _flatForRentAnnouncementGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getFlatForRentAnnouncementResult);

            Func <Task <FlatForRentAnnouncementOutputQuery> > result = async() => await _queryHandler.HandleAsync(new GetFlatForRentAnnouncementInputQuery(Guid.NewGuid()));

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #21
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_State_Is_Not_Found()
        {
            var command = new DeleteStateCommand(Guid.NewGuid(), new byte[] { 1, 2, 4, 8, 16, 32, 64 });
            var errors  = new Collection <IError>
            {
                new Error(StateErrorCodeEnumeration.NotFound, StateErrorMessage.NotFound)
            };
            var getStateResult = GetResult <State> .Fail(errors);

            _stateGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getStateResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(command);

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #22
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_Role_Is_Not_Found()
        {
            var deleteRoleCommand = new DeleteRoleCommand(Guid.NewGuid(), Array.Empty <byte>());
            var errors            = new Collection <IError>
            {
                new Error(RoleErrorCodeEnumeration.NotFound, RoleErrorMessage.NotFound)
            };
            var getRoleResult = GetResult <Role> .Fail(errors);

            _roleGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getRoleResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(deleteRoleCommand);

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #23
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_State_Does_Not_Exist()
        {
            var command = new UpdateStateCommand(Guid.NewGuid(), Array.Empty <byte>(), "NewName", "NewPolishName");
            var errors  = new Collection <IError>
            {
                new Error(StateErrorCodeEnumeration.NotFound, StateErrorMessage.NotFound)
            };
            var getStateResult = GetResult <State> .Fail(errors);

            _stateGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getStateResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(command);

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #24
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_User_Is_Not_Found()
        {
            var inputQuery = new GetFlatForRentAnnouncementPreferenceInputQuery(Guid.NewGuid(), 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 <FlatForRentAnnouncementPreferenceOutputQuery> > result = async() => await _queryHandler.HandleAsync(inputQuery);

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #25
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_State_Does_Not_Exist()
        {
            var id     = Guid.NewGuid();
            var errors = new Collection <IError>
            {
                new Error(StateErrorCodeEnumeration.NotFound, StateErrorMessage.NotFound)
            };
            var getStateResult = GetResult <State> .Fail(errors);

            _stateGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getStateResult);

            Func <Task <StateOutputQuery> > result = async() => await _queryHandler.HandleAsync(new GetStateInputQuery(id));

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #26
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_User_Is_Not_Found()
        {
            var command = new DeleteUserCommand(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> result = async() => await _commandHandler.HandleAsync(command);

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #27
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_Account_Is_Not_Found()
        {
            var changePasswordCommand = new ChangePasswordCommand(Guid.NewGuid(), "OldPassword", "NewPassword");
            var errors = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound)
            };
            var getAccountResult = GetResult <Account> .Fail(errors);

            _accountGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getAccountResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(changePasswordCommand);

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #28
0
        public async Task HandleAsync_Should_Throw_ValidationException_When_State_Is_Not_Found()
        {
            var stateId = Guid.NewGuid();
            var command = new CreateCityCommand(Guid.NewGuid(), "Name", "PolishName", stateId);
            var errors  = new Collection <IError>
            {
                new Error(StateErrorCodeEnumeration.NotFound, StateErrorMessage.NotFound)
            };
            var getStateResult = GetResult <State> .Fail(errors);

            _stateGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getStateResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(command);

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #29
0
        public async Task HandleAsync_Should_Throw_ValidationException_When_Account_Is_Not_Found()
        {
            var resetPasswordCommand = new ResetPasswordCommand("*****@*****.**", "123456", "Password");
            var errors = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound)
            };
            var getAccountResult = GetResult <Account> .Fail(errors);

            _accountGetterServiceMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(getAccountResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(resetPasswordCommand);

            var exceptionResult = await result.Should().ThrowAsync <ValidationException>();

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Beispiel #30
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_FlatForRentAnnouncement_Is_Not_Found()
        {
            var errors = new Collection <IError>
            {
                new Error(FlatForRentAnnouncementErrorCodeEnumeration.NotFound, FlatForRentAnnouncementErrorMessage.NotFound)
            };
            var getFlatForRentAnnouncementResult = GetResult <FlatForRentAnnouncement> .Fail(errors);

            var updateFlatForRentAnnouncementCommand = new UpdateFlatForRentAnnouncementCommand(Guid.NewGuid(), "Title",
                                                                                                "http://sourceUrl", Guid.NewGuid(), "Description", null, null, new List <Guid>());

            _flatForRentAnnouncementGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getFlatForRentAnnouncementResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(updateFlatForRentAnnouncementCommand);

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }