public async Task ShouldGetReferral_WhenExistingReferralCodeIsPassed()
        {
            // Arrange
            var referral = new Domain.Models.Referral
            {
                CustomerId   = Guid.NewGuid(),
                Id           = Guid.NewGuid().ToString("D"),
                ReferralCode = "123456"
            };

            var fixture = new ReferralServiceTestsFixture()
            {
                Referral  = null,
                Referrals = new List <Domain.Models.Referral>()
                {
                    referral
                }
            };

            // Act
            var result = await fixture.Service.GetReferralByReferralCodeAsync(fixture.ReferralCode);

            // Assert
            Assert.Equal(referral, result);
        }
        public async Task ShouldGenerateReferral_WhenCollisionForReferralCodeIsDetected()
        {
            // Arrange
            var referral = new Domain.Models.Referral
            {
                CustomerId   = Guid.NewGuid(),
                Id           = Guid.NewGuid().ToString("D"),
                ReferralCode = "123456"
            };

            var fixture = new ReferralServiceTestsFixture()
            {
                Referral  = null,
                Created   = true,
                Referrals = new List <Domain.Models.Referral>()
                {
                    referral,
                    referral
                }
            };

            // Act
            var result = await fixture.Service.GetOrCreateReferralForCustomerIdAsync(fixture.CustomerId);

            // Assert
            Assert.Equal(fixture.ReferralCode, result);

            fixture.ReferralRepositoryMock.Verify(c => c.GetByReferralCodeAsync(It.IsAny <string>()), Times.Exactly(3));
            fixture.ReferralRepositoryMock.Verify(c => c.CreateIfNotExistAsync(It.IsAny <Domain.Models.Referral>()), Times.Once);
        }
        public FriendReferralHistoryServiceTestsFixture()
        {
            ReferralServiceMock                 = new Mock <IReferralService>(MockBehavior.Strict);
            FriendReferralPublisherMock         = new Mock <IRabbitPublisher <FriendReferralEvent> >(MockBehavior.Strict);
            FriendReferralHistoryRepositoryMock = new Mock <IFriendReferralHistoryRepository>(MockBehavior.Strict);
            CustomerProfileClientMock           = new Mock <ICustomerProfileClient>(MockBehavior.Strict);
            NotificationPublisherServiceMock    = new Mock <INotificationPublisherService>(MockBehavior.Strict);
            CampaignClientMock = new Mock <ICampaignClient>(MockBehavior.Strict);

            Service = new FriendReferralService(
                ReferralServiceMock.Object,
                FriendReferralPublisherMock.Object,
                CustomerProfileClientMock.Object,
                FriendReferralHistoryRepositoryMock.Object,
                NotificationPublisherServiceMock.Object,
                CampaignClientMock.Object,
                EmptyLogFactory.Instance);

            Referral = new Domain.Models.Referral()
            {
                CustomerId   = CustomerId,
                Id           = Guid.NewGuid().ToString("D"),
                ReferralCode = ReferralCode
            };

            SetupCalls();
        }
        public async Task <bool> CreateIfNotExistAsync(Domain.Models.Referral referral)
        {
            using (var context = _msSqlContextFactory.CreateDataContext())
            {
                if (await context.Referrals.AnyAsync(x => x.CustomerId == referral.CustomerId))
                {
                    return(false);
                }

                await context.AddAsync(_mapper.Map <ReferralEntity>(referral));

                await context.SaveChangesAsync();

                return(true);
            }
        }
예제 #5
0
        private async Task <Domain.Models.Referral> GetProcessedReferral(ReferralHotelModel hotelReferral)
        {
            var referralContract = new Domain.Models.Referral
            {
                ReferralId = hotelReferral.Id
            };

            switch (hotelReferral.State)
            {
            case ReferralHotelState.Pending:
                referralContract.ReferralStatus = ReferralStatus.ReferralNotConfirmed;
                break;

            case ReferralHotelState.Confirmed:
                referralContract.ReferralStatus = ReferralStatus.OK;
                break;

            case ReferralHotelState.Used:
                referralContract.ReferralStatus = ReferralStatus.ReferralAlreadyUsed;
                break;

            case ReferralHotelState.Expired:
                referralContract.ReferralStatus = ReferralStatus.ReferralExpired;
                break;

            default:
                _log.Warning($"Received unknown status for hotel referral with id: {hotelReferral.Id}. ",
                             null, hotelReferral.Id);
                return(null);
            }

            var referrer = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(hotelReferral.ReferrerId);

            if (referrer.Profile != null)
            {
                referralContract.ReferrerEmail          = referrer.Profile.Email;
                referralContract.ReferrerAdditionalInfo =
                    $"{referrer.Profile.FirstName} {referrer.Profile.LastName}";
            }
            else
            {
                _log.Warning($"Could not get information about referrer with id: {hotelReferral.ReferrerId}." +
                             $" Error code: {referrer.ErrorCode.ToString()}");
            }

            return(referralContract);
        }
        public async Task ShouldThrowArgumentNullException_WhenNullReferralCodeIsPassed()
        {
            // Arrange
            var referral = new Domain.Models.Referral
            {
                CustomerId   = Guid.NewGuid(),
                Id           = Guid.NewGuid().ToString("D"),
                ReferralCode = "123456"
            };

            var fixture = new ReferralServiceTestsFixture();

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await fixture.Service.GetReferralByReferralCodeAsync(null);
            });
        }
        public async Task ShouldThrowCustomerNotFound_WhenNonExistingReferralCodeIsPassed()
        {
            // Arrange
            var referral = new Domain.Models.Referral
            {
                CustomerId   = Guid.NewGuid(),
                Id           = Guid.NewGuid().ToString("D"),
                ReferralCode = "123456"
            };

            var fixture = new ReferralServiceTestsFixture();

            // Act

            // Assert
            await Assert.ThrowsAsync <CustomerNotFoundException>(async() =>
            {
                await fixture.Service.GetReferralByReferralCodeAsync(fixture.ReferralCode);
            });
        }
        public ReferralServiceTestsFixture()
        {
            ReferralRepositoryMock = new Mock <IReferralRepository>(MockBehavior.Strict);
            HashingManagerMock     = new Mock <IHashingManager>(MockBehavior.Strict);

            Service = new ReferralService(
                ReferralRepositoryMock.Object,
                6,
                HashingManagerMock.Object,
                EmptyLogFactory.Instance);

            Referral = new Domain.Models.Referral()
            {
                CustomerId   = CustomerId,
                Id           = Guid.NewGuid().ToString("D"),
                ReferralCode = ReferralCode
            };

            SetupCalls();
        }
        public async Task ShouldNotCreateCustomerReferral_WhenExistentCustomerIdIsPassed()
        {
            // Arrange
            var referral = new Domain.Models.Referral
            {
                CustomerId   = Guid.NewGuid(),
                Id           = Guid.NewGuid().ToString("D"),
                ReferralCode = "123456"
            };

            var fixture = new ReferralServiceTestsFixture()
            {
                Referral = referral
            };

            // Act
            await fixture.Service.CreateReferralForCustomerIfNotExistAsync(fixture.CustomerId);

            // Assert
            fixture.ReferralRepositoryMock.Verify(c =>
                                                  c.CreateIfNotExistAsync(It.Is <Domain.Models.Referral>(
                                                                              x => x.CustomerId == fixture.CustomerId)), Times.Never);
        }