public void PhoneManagerApp_ProcessAllPotentialCandidatePhoneNumbers_WithCookie_WithFoundPhoneNumberNoPersist_ReturnsCookie()
        {
            // Arrange
            // generate test data
            var dataModel = new PhoneManagerModel()
            {
                DefaultCampaignQueryStringKey = "fsource", DefaultPersistDurationInDays = 32
            };

            dataModel.PhoneManagerCampaignDetail = new List <PhoneManagerCampaignDetail>()
            {
                new PhoneManagerCampaignDetail()
                {
                    Id = "1201", TelephoneNumber = "0800 123 4567", CampaignCode = "testcode"
                }
            };
            var testPhoneManagerData = dataModel.ToXmlString();

            var _dataProvider = MockProviders.Repository(testPhoneManagerData);

            var foundRecord = new PhoneManagerCampaignDetail()
            {
                Id = "1201", TelephoneNumber = "FOUND PHONENUMBER"
            };

            var _cookie = new CookieHolder()
            {
                Model =
                    new OutputModel()
                {
                    Id = "1202",
                    TelephoneNumber = "9999 999 9999"
                }
            };

            // generate the required result
            var correctResult = new FinalResultModel()
            {
                OutputCookieHolder = new CookieHolder(),
                OutputModelResult  = new OutputModel()
                {
                    Id = "1202",
                    TelephoneNumber = "9999 999 9999"
                },
                OutputResultSource = OutputSource.ExisitingCookie
            };

            PhoneManager target = new PhoneManager(null, _dataProvider, null, null, null, null);

            //Act
            FinalResultModel retVal = target.ProcessAllPotentialCandidatePhoneNumbers(_cookie, foundRecord);

            //Assert
            Assert.AreEqual(retVal.OutputResultSource, correctResult.OutputResultSource);
            Assert.AreEqual(retVal.OutputModelResult.Id, correctResult.OutputModelResult.Id);
        }
示例#2
0
        /// <summary>
        /// Pass all available available PhoneNumber records to decide finally which PhoneNumber to use
        /// </summary>
        internal FinalResultModel ProcessAllPotentialCandidatePhoneNumbers(CookieHolder exisitingCookie, PhoneManagerCampaignDetail foundRecord)
        {
            FinalResultModel result = new FinalResultModel();

            // check if there is an exisiting cookie we can use, and check if we want to use it
            if (exisitingCookie?.Model?.IsValid() ?? false)                                                                                                                       // we have a valid exisiting cookie
            {
                bool useExisitingCookieForSession = true;                                                                                                                         // let's assume we will want to use the existing cookie

                if ((foundRecord?.IsValidToSaveAsCookie() ?? false) && (foundRecord?.OverwritePersistingItem ?? false) && !exisitingCookie.Model.MatchesFoundRecord(foundRecord)) // foundRecordFromCriteria needs persisting and it should override any exisiting cookie
                {
                    useExisitingCookieForSession = false;                                                                                                                         // don't use the cookie as the _foundRecordFromCriteria has requested to overwrite any exisiting cookie
                }

                if (useExisitingCookieForSession)                      // continue using the exisiting cookie - no need to save a newc ookie
                {
                    result.OutputModelResult  = exisitingCookie.Model; // use the cookie data
                    result.OutputResultSource = OutputSource.ExisitingCookie;
                    return(result);
                }
            }

            // check if we have a valid _foundRecordFromCriteria that we can use
            if (foundRecord?.IsValid() ?? false) // we have a valid foundRecordFromCriteria object that we can use
            {
                result.OutputModelResult = new OutputModel()
                {
                    Id = foundRecord.Id,
                    TelephoneNumber  = foundRecord.TelephoneNumber,
                    CampaignCode     = foundRecord.CampaignCode,
                    AltMarketingCode = foundRecord.AltMarketingCode
                };

                if (foundRecord.IsValidToSaveAsCookie()) // it is requesting to be persisted via a cookie
                {
                    result.OutputCookieHolder = new CookieHolder()
                    {
                        Expires = DateTime.Today.AddDays((foundRecord.PersistDurationOverride > 0) ? foundRecord.PersistDurationOverride : _repository.GetDefaultSettings()?.DefaultPersistDurationInDays ?? 0), // persist duration in days - if foundRecord has persistDurationOverride set then use that, otherwise use the default admin setting
                        Model   = result.OutputModelResult
                    };
                }
                result.OutputResultSource = OutputSource.FoundRecordFromCriteria;
                return(result);
            }

            // as a last resort, output placeholder phone number
            result.OutputModelResult = new OutputModel()
            {
                Id = "P",
                TelephoneNumber = AppConstants.LastResortPhoneNumberPlaceholder
            };

            result.OutputResultSource = OutputSource.LastResortPlaceholder;
            return(result);
        }
        public void PhoneManagerApp_ProcessAllPotentialCandidatePhoneNumbers_WithNoCookie_WithNoFoundPhoneNumber_WithNoDefaultPhonenumber_ReturnsLastResortPhoneNumber()
        {
            // Arrange
            // generate test data
            var dataModel = new PhoneManagerModel()
            {
                DefaultCampaignQueryStringKey = "fsource", DefaultPersistDurationInDays = 32
            };

            dataModel.PhoneManagerCampaignDetail = new List <PhoneManagerCampaignDetail>()
            {
                new PhoneManagerCampaignDetail()
                {
                    Id = "1201", TelephoneNumber = "0800 123 4567", CampaignCode = "testcode"
                }
            };
            var testPhoneManagerData = dataModel.ToXmlString();

            var _dataProvider = MockProviders.Repository(testPhoneManagerData);

            // generate the required result
            var correctResult = new FinalResultModel()
            {
                OutputCookieHolder = null,
                OutputModelResult  = new OutputModel()
                {
                    TelephoneNumber = AppConstants.LastResortPhoneNumberPlaceholder
                },
                OutputResultSource = OutputSource.LastResortPlaceholder
            };

            PhoneManager target = new PhoneManager(null, _dataProvider, null, null, null, null);
            //PrivateObject obj = new PrivateObject(target); // MS Test

            //Act
            FinalResultModel retVal = target.ProcessAllPotentialCandidatePhoneNumbers(new CookieHolder(), new PhoneManagerCampaignDetail());

            //FinalResultModel retVal = (FinalResultModel)obj.Invoke("ProcessAllPotentialCandidatePhoneNumbers", new object[] { new CookieHolder(), new PhoneManagerCampaignDetail() }); // MS Test

            //Assert
            Assert.AreEqual(retVal.OutputResultSource, correctResult.OutputResultSource);
            Assert.AreEqual(retVal.OutputModelResult.TelephoneNumber, correctResult.OutputModelResult.TelephoneNumber);
        }