public async Task HandleAsync_Should_Throw_ValidationException_When_City_And_City_Districts_Verification_Fails() { var command = new CreateRoomForRentAnnouncementPreferenceCommand(Guid.NewGuid(), Guid.NewGuid(), 1, 1000, RoomTypeEnumeration.Single, 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(CityErrorCodeEnumeration.IncorrectCityDistricts, CityErrorMessage.IncorrectCityDistricts) }; var cityAndCityDistrictsVerificationResult = VerificationResult.Fail(errors); _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult); _cityVerificationServiceMock .Setup(x => x.VerifyCityAndCityDistrictsAsync(It.IsAny <Guid>(), It.IsAny <IEnumerable <Guid> >())) .ReturnsAsync(cityAndCityDistrictsVerificationResult); Func <Task> result = async() => await _commandHandler.HandleAsync(command); var exceptionResult = await result.Should().ThrowExactlyAsync <ValidationException>(); exceptionResult.And.Errors.Should().BeEquivalentTo(errors); }
public async Task HandleAsync_Should_Throw_ValidationException_When_Flat_For_Rent_Announcement_Preferences_Verification_Fails() { var command = new CreateRoomForRentAnnouncementPreferenceCommand(Guid.NewGuid(), Guid.NewGuid(), 1, 1000, RoomTypeEnumeration.Single, 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 cityAndCityDistrictsVerificationResult = VerificationResult.Ok(); var announcementPreferenceLimitIsNotExceededVerificationResult = VerificationResult.Ok(); var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder() .SetId(command.RoomForRentAnnouncementPreferenceId) .SetCityId(command.CityId) .SetPriceMin(command.PriceMin) .SetPriceMax(command.PriceMax) .SetRoomType(command.RoomType) .SetCityDistricts(command.CityDistricts) .Build(); var errors = new Collection <IError> { new Error(RoomForRentAnnouncementPreferenceErrorCode.ExpansibleCityDistricts, RoomForRentAnnouncementPreferenceErrorMessage.ExpansibleCityDistricts) }; var roomForRentAnnouncementPreferencesVerificationResult = VerificationResult.Fail(errors); _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult); _cityVerificationServiceMock .Setup(x => x.VerifyCityAndCityDistrictsAsync(It.IsAny <Guid>(), It.IsAny <IEnumerable <Guid> >())) .ReturnsAsync(cityAndCityDistrictsVerificationResult); _userVerificationServiceMock .Setup(x => x.VerifyAnnouncementPreferenceLimitIsNotExceeded(It.IsAny <int>(), It.IsAny <int>())) .Returns(announcementPreferenceLimitIsNotExceededVerificationResult); _mapperMock.Setup(x => x.Map <CreateRoomForRentAnnouncementPreferenceCommand, RoomForRentAnnouncementPreference>( It.IsAny <CreateRoomForRentAnnouncementPreferenceCommand>())) .Returns(roomForRentAnnouncementPreference); _roomForRentAnnouncementPreferenceVerificationServiceMock .Setup(x => x.VerifyRoomForRentAnnouncementPreferences( It.IsAny <IEnumerable <RoomForRentAnnouncementPreference> >())) .Returns(roomForRentAnnouncementPreferencesVerificationResult); Func <Task> result = async() => await _commandHandler.HandleAsync(command); var exceptionResult = await result.Should().ThrowExactlyAsync <ValidationException>(); exceptionResult.And.Errors.Should().BeEquivalentTo(errors); }
public async Task HandleAsync_Should_Create_Room_For_Rent_Announcement_Preference() { var command = new CreateRoomForRentAnnouncementPreferenceCommand(Guid.NewGuid(), Guid.NewGuid(), 1, 1000, RoomTypeEnumeration.Single, 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 cityAndCityDistrictsVerificationResult = VerificationResult.Ok(); var announcementPreferenceLimitIsNotExceededVerificationResult = VerificationResult.Ok(); var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder() .SetId(command.RoomForRentAnnouncementPreferenceId) .SetCityId(command.CityId) .SetPriceMin(command.PriceMin) .SetPriceMax(command.PriceMax) .SetRoomType(command.RoomType) .SetCityDistricts(command.CityDistricts) .Build(); var roomForRentAnnouncementPreferencesVerificationResult = VerificationResult.Ok(); _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult); _cityVerificationServiceMock .Setup(x => x.VerifyCityAndCityDistrictsAsync(It.IsAny <Guid>(), It.IsAny <IEnumerable <Guid> >())) .ReturnsAsync(cityAndCityDistrictsVerificationResult); _userVerificationServiceMock .Setup(x => x.VerifyAnnouncementPreferenceLimitIsNotExceeded(It.IsAny <int>(), It.IsAny <int>())) .Returns(announcementPreferenceLimitIsNotExceededVerificationResult); _mapperMock.Setup(x => x.Map <CreateRoomForRentAnnouncementPreferenceCommand, RoomForRentAnnouncementPreference>( It.IsAny <CreateRoomForRentAnnouncementPreferenceCommand>())) .Returns(roomForRentAnnouncementPreference); _roomForRentAnnouncementPreferenceVerificationServiceMock .Setup(x => x.VerifyRoomForRentAnnouncementPreferences( It.IsAny <IEnumerable <RoomForRentAnnouncementPreference> >())) .Returns(roomForRentAnnouncementPreferencesVerificationResult); _communicationBusMock .Setup(x => x.DispatchDomainEventsAsync(It.IsAny <User>(), It.IsAny <CancellationToken>())) .Returns(Task.CompletedTask); _userRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <User>())).Returns(Task.CompletedTask); _integrationEventBusMock.Setup(x => x.PublishIntegrationEventAsync(It.IsAny <IIntegrationEvent>())) .Returns(Task.CompletedTask); Func <Task> result = async() => await _commandHandler.HandleAsync(command); await result.Should().NotThrowAsync <Exception>(); }
public async Task <IActionResult> CreateRoomForRentAnnouncementPreferenceAsync([FromRoute] Guid id, [FromBody] CreateRoomForRentAnnouncementPreferenceRequest request) { var authResult = await _authorizationService.AuthorizeAsync(User, id, ResourceOwnerPolicy.ResourceOwnerPolicyName); if (!authResult.Succeeded) { return(CreateErrorResult(HttpStatusCode.Forbidden)); } var createRoomForRentAnnouncementPreferenceCommand = new CreateRoomForRentAnnouncementPreferenceCommand(id, request.CityId, request.PriceMin, request.PriceMax, request.RoomType.ConvertToEnumeration(), request.CityDistricts); await _communicationBus.SendCommandAsync(createRoomForRentAnnouncementPreferenceCommand); Response.Headers.Add(HeaderNameConstants.XCorrelationId, createRoomForRentAnnouncementPreferenceCommand.CorrelationId.ToString()); return(Accepted()); }
public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_User_Is_Not_Found() { var command = new CreateRoomForRentAnnouncementPreferenceCommand(Guid.NewGuid(), Guid.NewGuid(), 1, 1000, RoomTypeEnumeration.Single, new List <Guid> { 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); }