public CampaignServiceTests()
        {
            var mapper = MapperHelper.CreateAutoMapper();

            _campaignClientMock             = new Mock <ICampaignClient>();
            _campaignCompletionServiceMock  = new Mock <ICampaignCompletionService>();
            _conditionCompletionServiceMock = new Mock <IConditionCompletionService>();
            _bonusOperationServiceMock      = new Mock <IBonusOperationService>();
            _bonusCalculatorServiceMock     = new Mock <IBonusCalculatorService>();
            _rabbitParticipatedInCampaignEventPublisherMock = new Mock <IRabbitPublisher <ParticipatedInCampaignEvent> >();
            _activeCampaignRepositoryMock = new Mock <IActiveCampaignRepository>();
            _campaignCacheServiceMock     = new Mock <ICampaignCacheService>();

            _campaignService = new CampaignService(
                _campaignClientMock.Object,
                _campaignCompletionServiceMock.Object,
                _conditionCompletionServiceMock.Object,
                _bonusOperationServiceMock.Object,
                _rabbitParticipatedInCampaignEventPublisherMock.Object,
                _bonusCalculatorServiceMock.Object,
                EmptyLogFactory.Instance,
                _activeCampaignRepositoryMock.Object,
                _campaignCacheServiceMock.Object,
                mapper);
        }
Exemplo n.º 2
0
        public async Task ShouldSendCashInAndBonusIssues_WhenBonusOperationValid()
        {
            // Arrange
            var fixture = new BonusOperationServiceFixture();

            var bonusOperation = fixture.CreateBonusOperation();

            var mapper       = MapperHelper.CreateAutoMapper();
            var expectedType = mapper.Map <BonusOperationType>(bonusOperation.BonusOperationType);

            // Execute
            await fixture.OperationService.AddBonusOperationAsync(bonusOperation);

            // Assert

            fixture.BonusIssuedEventPublisher
            .Verify(c => c.PublishAsync(
                        It.Is <BonusIssuedEvent>(x =>
                                                 x.BonusOperationType == expectedType &&
                                                 x.Amount == bonusOperation.Reward &&
                                                 x.CampaignId == Guid.Parse(bonusOperation.CampaignId) &&
                                                 x.CustomerId == bonusOperation.CustomerId &&
                                                 x.OperationId != Guid.Empty &&
                                                 x.TimeStamp == bonusOperation.TimeStamp)),
                    Times.Once);
        }
Exemplo n.º 3
0
        public CampaignServiceBonusProcessingTestsFixture()
        {
            var mapper = MapperHelper.CreateAutoMapper();

            ConditionCompletionServiceMock       = new Mock <IConditionCompletionService>(MockBehavior.Strict);
            BonusOperationServiceMock            = new Mock <IBonusOperationService>(MockBehavior.Strict);
            CampaignCompletionServiceMock        = new Mock <ICampaignCompletionService>(MockBehavior.Strict);
            ParticipatedInCampaignEventPublisher = new Mock <IRabbitPublisher <ParticipatedInCampaignEvent> >();
            BonusCalculatorServiceMock           = new Mock <IBonusCalculatorService>(MockBehavior.Strict);
            CampaignClientMock           = new Mock <ICampaignClient>();
            ConnectionMultiplexerMock    = new Mock <IConnectionMultiplexer>();
            ActiveCampaignRepositoryMock = new Mock <IActiveCampaignRepository>();
            CampaignCacheServiceMock     = new Mock <ICampaignCacheService>();

            CreateConditionTestData();

            SetupCommonMocks();

            CampaignServiceInstance = new CampaignService(
                CampaignClientMock.Object,
                CampaignCompletionServiceMock.Object,
                ConditionCompletionServiceMock.Object,
                BonusOperationServiceMock.Object,
                ParticipatedInCampaignEventPublisher.Object,
                BonusCalculatorServiceMock.Object,
                EmptyLogFactory.Instance,
                ActiveCampaignRepositoryMock.Object,
                CampaignCacheServiceMock.Object,
                mapper);
        }
        public ReferralRepositoryTests()
        {
            var contextFixture = new ReferralRepositoryFixture();

            var bonusEngineContext = contextFixture.ReferralContext;

            var msSqlContextFactory = new SqlContextFactoryFake <ReferralContext>(c => bonusEngineContext);

            _referralRepository = new ReferralRepository(msSqlContextFactory, MapperHelper.CreateAutoMapper());
        }
Exemplo n.º 5
0
        public PropertyPurchaseServiceTestsFixture()
        {
            ReferralLeadRepositoryMock    = new Mock <IReferralLeadRepository>(MockBehavior.Strict);
            PropertyPurchaseRepositorMock = new Mock <IPropertyPurchaseRepository>(MockBehavior.Strict);
            StakeServiceMock = new Mock <IStakeService>(MockBehavior.Strict);

            Service = new PropertyPurchaseService(
                ReferralLeadRepositoryMock.Object,
                PropertyPurchaseRepositorMock.Object,
                StakeServiceMock.Object,
                new CommissionManager(MapperHelper.CreateAutoMapper()));

            ReferralLead = new ReferralLeadEncrypted
            {
                Id                = Guid.NewGuid(),
                AgentId           = AgentId,
                PhoneNumberHash   = PhoneNumber,
                EmailHash         = Email,
                ConfirmationToken = ConfirmationToken,
                CampaignId        = Guid.NewGuid()
            };

            ReferralLeadWithDetails = new ReferralLeadEncryptedWithDetails
            {
                Id                = Guid.NewGuid(),
                AgentId           = AgentId,
                PhoneNumberHash   = PhoneNumber,
                EmailHash         = Email,
                ConfirmationToken = ConfirmationToken
            };

            PropertyPurchase = new PropertyPurchase
            {
                Id             = Guid.NewGuid(),
                ReferralLeadId = Guid.NewGuid(),
                Timestamp      = DateTime.UtcNow
            };

            ReferralLeads = new List <ReferralLeadEncrypted> {
                ReferralLead
            };

            ReferralLeadsWithDetails = new List <ReferralLeadEncryptedWithDetails> {
                ReferralLeadWithDetails
            };

            PropertyPurchases = new List <PropertyPurchase>
            {
                PropertyPurchase,
                PropertyPurchase,
                PropertyPurchase
            };

            SetupCalls();
        }
        public BurnRuleServiceTests()
        {
            MapperHelper.CreateAutoMapper();

            _burnRuleContentRepositoryMock = new Mock <IBurnRuleContentRepository>();
            _burnRuleRepositoryMock        = new Mock <IBurnRuleRepository>();
            _spendRuleChangeEventPublisher = new Mock <IRabbitPublisher <SpendRuleChangedEvent> >();
            _burnRuleContentValidationMock = new Mock <IRuleContentValidationService>();
            _burnRulePartnerRepositoryMock = new Mock <IBurnRulePartnerRepository>();
            _fileServiceMock = new Mock <IFileService>();
        }
        public CampaignRepositoryTest()
        {
            var mapper = MapperHelper.CreateAutoMapper();

            var contextFixture = new CampaignContextFixture();

            var bonusEngineContext = contextFixture.BonusEngineContext;

            var postgresContextFactory = new MsSqlContextFactory <CampaignContext>(
                dbCtx => bonusEngineContext, contextFixture.DbContextOptions);

            _campaignRepository = new CampaignRepository(postgresContextFactory, mapper);
        }
        public BonusOperationServiceFixture()
        {
            var mapper = MapperHelper.CreateAutoMapper();

            BonusIssuedEventPublisher = new Mock <IRabbitPublisher <BonusIssuedEvent> >(MockBehavior.Strict);
            BonusIssuedEventPublisher.Setup(c => c.PublishAsync(It.IsAny <BonusIssuedEvent>()))
            .Returns(Task.CompletedTask);

            OperationService = new BonusOperationService(
                BonusIssuedEventPublisher.Object,
                mapper,
                EmptyLogFactory.Instance);
        }
        public CommonReferralServiceTestsFixture()
        {
            //ReferralLeadServiceMock = new Mock<IReferralLeadService>(MockBehavior.Strict);
            ReferralHotelsServiceMock = new Mock <IReferralHotelsService>(MockBehavior.Strict);
            FriendReferralServiceMock = new Mock <IFriendReferralService>(MockBehavior.Strict);

            Service = new CommonReferralService(
                //ReferralLeadServiceMock.Object,
                ReferralHotelsServiceMock.Object,
                FriendReferralServiceMock.Object,
                MapperHelper.CreateAutoMapper());

            ReferralHotelList  = new List <ReferralHotelWithProfile>();
            ReferralFriendList = new List <ReferralFriend>();

            SetupCalls();
        }
Exemplo n.º 10
0
        public CampaignCacheServiceTests()
        {
            var mapper = MapperHelper.CreateAutoMapper();

            _campaignClientMock           = new Mock <ICampaignClient>();
            _activeCampaignRepositoryMock = new Mock <IActiveCampaignRepository>();
            _dbMock          = new Mock <IDatabase>();
            _mockMultiplexer = new Mock <IConnectionMultiplexer>();

            _mockMultiplexer
            .Setup(_ => _.GetDatabase(It.IsAny <int>(), It.IsAny <object>()))
            .Returns(_dbMock.Object);

            _campaignCacheService = new CampaignCacheService(
                EmptyLogFactory.Instance,
                _mockMultiplexer.Object,
                _campaignClientMock.Object,
                _activeCampaignRepositoryMock.Object,
                "BonusEngine",
                "connectionString",
                mapper);
        }
        private CampaignService GetCampaignServiceInstance(
            ICampaignRepository campaignRepository,
            IConditionService conditionService,
            ICampaignValidationService campaignValidationService,
            IRabbitPublisher <CampaignChangeEvent> campaignChangeEventPublisher,
            IConfigurationRepository configurationRepository)
        {
            var fileServiceMock = new Mock <IFileService>();
            var spendRuleContentRepositoryMock = new Mock <IEarnRuleContentRepository>();
            var mapper = MapperHelper.CreateAutoMapper();

            return(new CampaignService(
                       campaignRepository,
                       conditionService,
                       campaignValidationService,
                       EmptyLogFactory.Instance,
                       campaignChangeEventPublisher,
                       configurationRepository,
                       fileServiceMock.Object,
                       spendRuleContentRepositoryMock.Object,
                       mapper));
        }
Exemplo n.º 12
0
        public LocationServiceTestsFixture()
        {
            MapperHelper.CreateAutoMapper();

            CustomerProfileClientMock = new Mock <ICustomerProfileClient>(MockBehavior.Strict);
            LocationRepositoryMock    = new Mock <ILocationRepository>();
            GeocodingReaderMock       = new Mock <IGeocodingReader>();

            LocationService = new LocationService(
                CustomerProfileClientMock.Object,
                EmptyLogFactory.Instance,
                LocationRepositoryMock.Object,
                GeocodingReaderMock.Object);

            Partner = new Partner
            {
                Id               = Guid.NewGuid(),
                Name             = "Partner 1",
                Description      = "Partner 1 Desc",
                BusinessVertical = Vertical.Hospitality,
                ClientId         = "clientId1",
                CreatedAt        = DateTime.UtcNow,
                AmountInCurrency = 1,
                AmountInTokens   = 2,
                Locations        = new List <Location>
                {
                    new Location
                    {
                        Id            = LocationIds[0],
                        Name          = "Holiday Inn",
                        Address       = "Dubai",
                        CreatedAt     = DateTime.UtcNow,
                        ContactPerson = new ContactPerson
                        {
                            FirstName   = "Name 1",
                            LastName    = "Name 2",
                            Email       = "Email",
                            PhoneNumber = "Phone Number"
                        }
                    },
                    new Location
                    {
                        Id            = LocationIds[1],
                        Name          = "Holiday Relax",
                        Address       = "Bahri",
                        CreatedAt     = DateTime.UtcNow,
                        ContactPerson = new ContactPerson
                        {
                            FirstName   = "Name 1",
                            LastName    = "Name 2",
                            Email       = "Email",
                            PhoneNumber = "Phone Number"
                        }
                    },
                    new Location
                    {
                        Id            = LocationIds[2],
                        Name          = "Holiday Relax",
                        Address       = "Bahri",
                        CreatedAt     = DateTime.UtcNow,
                        ContactPerson = new ContactPerson
                        {
                            FirstName   = "Name 1",
                            LastName    = "Name 2",
                            Email       = "Email",
                            PhoneNumber = "Phone Number"
                        }
                    }
                }
            };

            PartnerContactResponse = new PartnerContactResponse
            {
                PartnerContact = new PartnerContact
                {
                    FirstName   = "Owner",
                    LastName    = "Johnson",
                    Email       = "*****@*****.**",
                    PhoneNumber = "123-123-123",
                    LocationId  = LocationIds[0].ToString()
                }
            };

            Partners = (new List <Partner>
            {
                Partner
            }.AsReadOnly(), 1);

            Location = new Location
            {
                Id            = LocationIds[2],
                Name          = "Holiday Relax",
                Address       = "Bahri",
                CreatedAt     = DateTime.UtcNow,
                ContactPerson = new ContactPerson
                {
                    FirstName   = "Name 1",
                    LastName    = "Name 2",
                    Email       = "Email",
                    PhoneNumber = "Phone Number"
                }
            };
        }
        public ReferralLeadServiceTestsFixture()
        {
            StakeServiceMock = new Mock <IStakeService>(MockBehavior.Strict);
            PropertyIntegrationClientMock = new Mock <IMAVNPropertyIntegrationClient>(MockBehavior.Strict);
            EventPublisher                   = new Mock <IRabbitPublisher <PropertyLeadApprovedReferralEvent> >(MockBehavior.Strict);
            ReferralLeadRepositoryMock       = new Mock <IReferralLeadRepository>(MockBehavior.Strict);
            NotificationPublisherServiceMock = new Mock <INotificationPublisherService>(MockBehavior.Strict);
            SettingsServiceMock              = new Mock <ISettingsService>(MockBehavior.Strict);
            HashingManagerMock               = new Mock <IHashingManager>(MockBehavior.Strict);
            CustomerProfileMock              = new Mock <ICustomerProfileClient>(MockBehavior.Strict);
            DictionariesClientMock           = new Mock <IDictionariesClient>(MockBehavior.Strict);
            AgentManagementServiceMock       = new Mock <IAgentManagementClient>(MockBehavior.Strict);
            PropertyPurchaseRepositoryMock   = new Mock <IPropertyPurchaseRepository>(MockBehavior.Strict);
            LeadStateChangePublisherMock     = new Mock <IRabbitPublisher <LeadStateChangedEvent> >(MockBehavior.Strict);

            Service = new ReferralLeadService(
                StakeServiceMock.Object,
                PropertyIntegrationClientMock.Object,
                EventPublisher.Object,
                ReferralLeadRepositoryMock.Object,
                NotificationPublisherServiceMock.Object,
                SettingsServiceMock.Object,
                HashingManagerMock.Object,
                AgentManagementServiceMock.Object,
                CustomerProfileMock.Object,
                DictionariesClientMock.Object,
                PropertyPurchaseRepositoryMock.Object,
                LeadStateChangePublisherMock.Object,
                MapperHelper.CreateAutoMapper(),
                EmptyLogFactory.Instance);

            ReferralLead = new ReferralLead
            {
                Id                 = Guid.NewGuid(),
                AgentId            = AgentId,
                FirstName          = FirstName,
                LastName           = LastName,
                Email              = Email,
                PhoneNumber        = PhoneNumber,
                PhoneCountryCodeId = CountryCode,
                ConfirmationToken  = ConfirmationToken,
                AgentSalesforceId  = AgentSalesforceId,
                Note               = Note
            };

            ReferralLeads = new List <ReferralLeadEncrypted>
            {
                new ReferralLeadEncrypted
                {
                    Id      = Guid.NewGuid(),
                    AgentId = Guid.Parse("78ceb436-29a9-499c-92fc-ec77152e32d8"),
                    State   = ReferralLeadState.Pending
                },
                new ReferralLeadEncrypted
                {
                    Id    = Guid.NewGuid(),
                    State = ReferralLeadState.Pending
                },
                new ReferralLeadEncrypted
                {
                    Id                 = Guid.Parse("57e80137-984c-44f0-ad6f-b555d46cd934"),
                    AgentId            = Guid.Parse("78ceb436-29a9-499c-92fc-ec77152e32d8"),
                    EmailHash          = "*****@*****.**",
                    ConfirmationToken  = "3l2k3h4lk",
                    State              = ReferralLeadState.Pending,
                    PhoneNumberHash    = "2384324092345",
                    PhoneCountryCodeId = 359,
                    AgentSalesforceId  = "agentsfid"
                },
                new ReferralLeadEncrypted
                {
                    Id                 = Guid.NewGuid(),
                    AgentId            = Guid.NewGuid(),
                    State              = ReferralLeadState.Confirmed,
                    EmailHash          = "*****@*****.**",
                    PhoneNumberHash    = "0881212838",
                    PhoneCountryCodeId = 359,
                    ConfirmationToken  = "9l2l7a4lk"
                },
                new ReferralLeadEncrypted
                {
                    Id                 = Guid.NewGuid(),
                    AgentId            = Guid.NewGuid(),
                    State              = ReferralLeadState.Approved,
                    EmailHash          = "*****@*****.**",
                    PhoneNumberHash    = "0884543421",
                    PhoneCountryCodeId = 359,
                    ConfirmationToken  = "7a00a3a8p"
                },
                new ReferralLeadEncrypted
                {
                    Id                 = Guid.NewGuid(),
                    AgentId            = Guid.NewGuid(),
                    State              = ReferralLeadState.Approved,
                    EmailHash          = "*****@*****.**",
                    PhoneNumberHash    = "0884543421",
                    PhoneCountryCodeId = 359,
                    ConfirmationToken  = "1b9yhklj3"
                }
            };

            ReferralLeadsWithDetails = new List <ReferralLeadEncryptedWithDetails>
            {
                new ReferralLeadEncryptedWithDetails
                {
                    Id      = Guid.NewGuid(),
                    AgentId = Guid.Parse("78ceb436-29a9-499c-92fc-ec77152e32d8"),
                    State   = ReferralLeadState.Pending
                },
                new ReferralLeadEncryptedWithDetails
                {
                    Id    = Guid.NewGuid(),
                    State = ReferralLeadState.Pending
                },
                new ReferralLeadEncryptedWithDetails
                {
                    Id                 = Guid.Parse("57e80137-984c-44f0-ad6f-b555d46cd934"),
                    AgentId            = Guid.Parse("78ceb436-29a9-499c-92fc-ec77152e32d8"),
                    EmailHash          = "*****@*****.**",
                    ConfirmationToken  = "3l2k3h4lk",
                    State              = ReferralLeadState.Pending,
                    PhoneNumberHash    = "2384324092345",
                    PhoneCountryCodeId = 359,
                    AgentSalesforceId  = "agentsfid"
                },
                new ReferralLeadEncryptedWithDetails
                {
                    Id                 = Guid.NewGuid(),
                    AgentId            = Guid.NewGuid(),
                    State              = ReferralLeadState.Confirmed,
                    EmailHash          = "*****@*****.**",
                    PhoneNumberHash    = "0881212838",
                    PhoneCountryCodeId = 359,
                    ConfirmationToken  = "9l2l7a4lk"
                },
                new ReferralLeadEncryptedWithDetails
                {
                    Id                 = Guid.NewGuid(),
                    AgentId            = Guid.NewGuid(),
                    State              = ReferralLeadState.Approved,
                    EmailHash          = "*****@*****.**",
                    PhoneNumberHash    = "0884543421",
                    PhoneCountryCodeId = 359,
                    ConfirmationToken  = "7a00a3a8p"
                },
                new ReferralLeadEncryptedWithDetails
                {
                    Id                 = Guid.NewGuid(),
                    AgentId            = Guid.NewGuid(),
                    State              = ReferralLeadState.Approved,
                    EmailHash          = "*****@*****.**",
                    PhoneNumberHash    = "0884543421",
                    PhoneCountryCodeId = 359,
                    ConfirmationToken  = "1b9yhklj3"
                }
            };

            ReferralLeadProfileResponse = new ReferralLeadProfileResponse
            {
                ErrorCode = ReferralLeadProfileErrorCodes.None,
                Data      = new ReferralLeadProfile
                {
                    ReferralLeadId = Guid.NewGuid(),
                    Email          = Email,
                    FirstName      = FirstName,
                    LastName       = LastName,
                    PhoneNumber    = PhoneNumber,
                    Note           = Note
                }
            };

            SetupCalls();
        }
Exemplo n.º 14
0
        public PartnerServiceTestsFixture()
        {
            var mapper = MapperHelper.CreateAutoMapper();

            PartnerRepositoryMock       = new Mock <IPartnerRepository>(MockBehavior.Strict);
            LocationServiceMock         = new Mock <ILocationService>(MockBehavior.Strict);
            CredentialsClientMock       = new Mock <ICredentialsClient>(MockBehavior.Strict);
            CustomerProfileClientMock   = new Mock <ICustomerProfileClient>(MockBehavior.Strict);
            LocationsRepositoryMock     = new Mock <ILocationRepository>(MockBehavior.Strict);
            PartnerCreatedPublisherMock = new Mock <IRabbitPublisher <PartnerCreatedEvent> >(MockBehavior.Strict);

            PartnerService = new PartnerService(
                PartnerRepositoryMock.Object,
                LocationServiceMock.Object,
                CredentialsClientMock.Object,
                CustomerProfileClientMock.Object,
                LocationsRepositoryMock.Object,
                PartnerCreatedPublisherMock.Object,
                mapper,
                EmptyLogFactory.Instance);

            Partner = new Partner
            {
                Id               = Guid.NewGuid(),
                Name             = "Partner 1",
                Description      = "Partner 1 Desc",
                BusinessVertical = Vertical.Hospitality,
                ClientId         = "clientId1",
                CreatedAt        = DateTime.UtcNow,
                AmountInCurrency = 1,
                AmountInTokens   = 2,
                Locations        = new List <Location>
                {
                    new Location
                    {
                        Id            = LocationId,
                        Name          = "Holiday Inn",
                        Address       = "Dubai",
                        CreatedAt     = DateTime.UtcNow,
                        ContactPerson = null
                    },
                    new Location
                    {
                        Id            = Guid.NewGuid(),
                        Name          = "Holiday Relax",
                        Address       = "Bahri",
                        CreatedAt     = DateTime.UtcNow,
                        ContactPerson = null
                    }
                }
            };

            PartnerContactResponse = new PartnerContactResponse
            {
                PartnerContact = new PartnerContact
                {
                    FirstName   = "Owner",
                    LastName    = "Johnson",
                    Email       = "*****@*****.**",
                    PhoneNumber = "123-123-123",
                    LocationId  = LocationId.ToString()
                }
            };

            Partners = (new List <Partner>
            {
                Partner
            }.AsReadOnly(), 1);
        }
        public ReferralHotelsServiceTests()
        {
            _customerProfileClientMock.Setup(o => o.CustomerProfiles
                                             .GetByCustomerIdAsync(It.Is <string>(customerId => customerId == _customerId), It.IsAny <bool>(), It.IsAny <bool>()))
            .ReturnsAsync((string customerId, bool includeNonVerified, bool includeDeactivated) => new CustomerProfileResponse
            {
                ErrorCode = CustomerProfileErrorCodes.None,
                Profile   = new CustomerProfile.Client.Models.Responses.CustomerProfile
                {
                    Email      = _customerEmail,
                    CustomerId = customerId
                }
            });

            _customerProfileClientMock.Setup(o => o.CustomerProfiles
                                             .GetByCustomerIdAsync(It.Is <string>(customerId => customerId != _customerId), It.IsAny <bool>(), It.IsAny <bool>()))
            .ReturnsAsync((string customerId, bool includeNonVerified, bool includeDeactivated) => new CustomerProfileResponse
            {
                ErrorCode = CustomerProfileErrorCodes.CustomerProfileDoesNotExist
            });

            _customerProfileClientMock
            .Setup(o => o.ReferralHotelProfiles.AddAsync(It.IsAny <ReferralHotelProfileRequest>()))
            .ReturnsAsync((ReferralHotelProfileRequest referralHotelProfileRequest) =>
                          new ReferralHotelProfileResponse {
                ErrorCode = ReferralHotelProfileErrorCodes.None
            });

            _customerProfileClientMock.Setup(o => o.ReferralHotelProfiles
                                             .GetByIdAsync(It.Is <Guid>(referralId => referralId == _referralId)))
            .ReturnsAsync((Guid referralId) => new ReferralHotelProfileResponse
            {
                ErrorCode = ReferralHotelProfileErrorCodes.None,
                Data      = new ReferralHotelProfile {
                    ReferralHotelId = _referralId, Email = _email
                }
            });

            _customerProfileClientMock.Setup(o => o.ReferralHotelProfiles
                                             .GetByIdAsync(It.Is <Guid>(referralId => referralId != _referralId)))
            .ReturnsAsync((Guid referralId) => new ReferralHotelProfileResponse
            {
                ErrorCode = ReferralHotelProfileErrorCodes.ReferralHotelProfileDoesNotExist
            });

            _referralHotelsRepositoryMock.Setup(o => o.GetByReferrerIdAsync(It.IsAny <string>()))
            .ReturnsAsync((string referralId) =>
                          _referralHotelsEncrypted.Where(o => o.ReferrerId == referralId).ToList());

            _referralHotelsRepositoryMock.Setup(o =>
                                                o.GetByEmailHashAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((string emailHash, string partnerId, string location) =>
            {
                var expression = _referralHotelsEncrypted.Where(o => o.EmailHash == emailHash);

                if (!string.IsNullOrEmpty(partnerId))
                {
                    expression = expression.Where(o => o.PartnerId == partnerId);
                }

                if (!string.IsNullOrEmpty(location))
                {
                    expression = expression.Where(o => o.Location == location);
                }

                return(expression.ToList());
            });

            _referralHotelsRepositoryMock.Setup(o => o.CreateAsync(It.IsAny <ReferralHotelEncrypted>()))
            .ReturnsAsync((ReferralHotelEncrypted referralHotelEncrypted) =>
            {
                referralHotelEncrypted.Id = _referralId.ToString();
                referralHotelEncrypted.CreationDateTime = DateTime.UtcNow;

                return(referralHotelEncrypted);
            });

            _referralHotelsRepositoryMock.Setup(o => o.UpdateAsync(It.IsAny <ReferralHotelEncrypted>()))
            .ReturnsAsync((ReferralHotelEncrypted referralHotelEncrypted) => referralHotelEncrypted);

            _referralHotelsRepositoryMock.Setup(o => o.GetByConfirmationTokenAsync(It.IsAny <string>()))
            .ReturnsAsync((string confirmationToken) =>
                          _referralHotelsEncrypted.SingleOrDefault(o => o.ConfirmationToken == confirmationToken));

            _currencyConverterClientMock.Setup(o => o.Converter.ConvertAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <decimal>()))
            .ReturnsAsync(new ConverterResponse()
            {
                ErrorCode = ConverterErrorCode.None
            });

            _partnerManagementClientMock.Setup(o => o.Partners.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(new PartnerDetailsModel());

            _hashingManagerMock.Setup(o => o.GenerateBase(It.IsAny <string>()))
            .Returns((string value) => value);

            _settingsServiceMock.Setup(o => o.GetLeadConfirmationTokenLength())
            .Returns(() => _confirmationTokenLength);

            _service = new ReferralHotelsService(
                _stakeServiceMock.Object,
                _customerProfileClientMock.Object,
                _currencyConverterClientMock.Object,
                _campaignClientMock.Object,
                _partnerManagementClientMock.Object,
                _rabbitPublisherMock.Object,
                _notificationPublisherServiceMock.Object,
                _referralHotelsRepositoryMock.Object,
                _settingsServiceMock.Object,
                _hashingManagerMock.Object,
                _referralExpirationPeriod,
                _referralLimitPeriod,
                _referralLimit,
                MapperHelper.CreateAutoMapper(),
                "AED",
                EmptyLogFactory.Instance);
        }
        public ReferralLeadServiceNewTests()
        {
            _referralLeadProfile = new ReferralLeadProfile
            {
                ReferralLeadId = _referralId,
                FirstName      = "first name",
                LastName       = "last name",
                PhoneNumber    = "+70000000000",
                Email          = "*****@*****.**",
                Note           = "note"
            };

            _referralLeadCreateInfo = new ReferralLead
            {
                FirstName          = _referralLeadProfile.FirstName,
                LastName           = _referralLeadProfile.LastName,
                PhoneCountryCodeId = _countryPhoneCode.Id,
                PhoneNumber        = "000 000 00 00",
                Email   = _referralLeadProfile.Email,
                Note    = _referralLeadProfile.Note,
                AgentId = Guid.Parse(_customerId)
            };

            _agent = new AgentModel
            {
                CustomerId   = Guid.Parse(_customerId),
                Status       = AgentStatus.ApprovedAgent,
                SalesforceId = "SalesforceId"
            };

            _customerProfileClientMock.Setup(o => o.CustomerProfiles.GetByCustomerIdAsync(
                                                 It.Is <string>(customerId => customerId == _customerId), It.IsAny <bool>(), It.IsAny <bool>()))
            .ReturnsAsync((string customerId, bool includeNonVerified, bool includeDeactivated) => new CustomerProfileResponse
            {
                ErrorCode = CustomerProfileErrorCodes.None
            });

            _customerProfileClientMock
            .Setup(o => o.ReferralLeadProfiles.AddAsync(It.IsAny <ReferralLeadProfileRequest>()))
            .ReturnsAsync((ReferralLeadProfileRequest request) => new ReferralLeadProfileResponse());

            _customerProfileClientMock.Setup(o => o.ReferralLeadProfiles.GetByIdAsync(
                                                 It.Is <Guid>(referralId => referralId == _referralId)))
            .ReturnsAsync((Guid referralId) => new ReferralLeadProfileResponse
            {
                ErrorCode = ReferralLeadProfileErrorCodes.None, Data = _referralLeadProfile
            });

            _dictionariesClientMock.Setup(o => o.Salesforce.GetCountryPhoneCodeByIdAsync(
                                              It.Is <int>(id => id == _countryPhoneCode.Id)))
            .ReturnsAsync((int id) => _countryPhoneCode);

            _agentManagementClientMock.Setup(o => o.Agents.GetByCustomerIdAsync(
                                                 It.Is <Guid>(customerId => customerId == Guid.Parse(_customerId))))
            .ReturnsAsync((Guid customerId) => _agent);

            _referralLeadRepositoryMock.Setup(o => o.CreateAsync(It.IsAny <ReferralLeadEncrypted>()))
            .ReturnsAsync((ReferralLeadEncrypted referralLeadEncrypted) =>
            {
                referralLeadEncrypted.Id = _referralId;
                referralLeadEncrypted.CreationDateTime = DateTime.UtcNow;

                return(referralLeadEncrypted);
            });

            _referralLeadRepositoryMock.Setup(o => o.GetByEmailHashAsync(It.IsAny <string>()))
            .ReturnsAsync((string emailHash) =>
                          _referralLeadsEncrypted.Where(o => o.EmailHash == emailHash).ToList());

            _referralLeadRepositoryMock.Setup(o => o.GetByPhoneNumberHashAsync(It.IsAny <int>(), It.IsAny <string>()))
            .ReturnsAsync((int countryPhoneCodeId, string phoneNumberHash) =>
                          _referralLeadsEncrypted.Where(o => o.PhoneNumberHash == phoneNumberHash &&
                                                        o.PhoneCountryCodeId == countryPhoneCodeId).ToList());

            _referralLeadRepositoryMock.Setup(o => o.GetApprovedAsync())
            .ReturnsAsync(() => _referralLeadsEncrypted.Where(o => o.State == ReferralLeadState.Approved).ToList());

            _hashingManagerMock.Setup(o => o.GenerateBase(It.IsAny <string>()))
            .Returns((string value) => value);

            _settingsServiceMock.Setup(o => o.GetLeadConfirmationTokenLength())
            .Returns(() => _confirmationTokenLength);

            _service = new ReferralLeadService(
                _stakeServiceMock.Object,
                _propertyIntegrationClientMock.Object,
                _propertyLeadApprovedReferralPublisherMock.Object,
                _referralLeadRepositoryMock.Object,
                _notificationPublisherServiceMock.Object,
                _settingsServiceMock.Object,
                _hashingManagerMock.Object,
                _agentManagementClientMock.Object,
                _customerProfileClientMock.Object,
                _dictionariesClientMock.Object,
                _propertyPurchaseRepositoryMock.Object,
                _leadStateChangedPublisherMock.Object,
                MapperHelper.CreateAutoMapper(),
                EmptyLogFactory.Instance);
        }