Пример #1
0
 static HomeController()
 {
     VWO.Configure(LogLevel.DEBUG);
     VWO.Configure(new CustomLogger());
     SettingsFile = SettingsProvider.GetSettings(VWOConfig.AccountId, VWOConfig.SdkKey);
     VWOClient    = VWO.Instantiate(SettingsFile, isDevelopmentMode: true, userProfileService: new UserProfileService());
 }
Пример #2
0
        public void Instantiate_Should_Return_VWOClient_For_Valid_Settings_File_And_Call_Settings_Processor()
        {
            var validSettings = new FileReaderApiCaller().Execute <Settings>(null);
            var mockValidator = Mock.GetValidator();

            VWO.Configure(mockValidator.Object);
            var mockSettingProcessor = Mock.GetSettingsProcessor();

            VWO.Configure(mockSettingProcessor.Object);

            var vwoClient = VWO.Instantiate(validSettings);

            Assert.NotNull(vwoClient);
            Assert.IsType <VWO>(vwoClient);

            mockSettingProcessor.Verify(mock => mock.ProcessAndBucket(It.IsAny <Settings>()), Times.Once);
            mockSettingProcessor.Verify(mock => mock.ProcessAndBucket(It.Is <Settings>(val => ReferenceEquals(val, validSettings))), Times.Once);
        }
Пример #3
0
        public void Instantiate_Should_Return_Null_When_Settings_Processor_Returns_Null_Account_Settings()
        {
            var inValidSettings = new Settings(null, null, -2, -1);
            var mockValidator   = Mock.GetValidator();

            VWO.Configure(mockValidator.Object);
            var mockSettingProcessor = Mock.GetSettingsProcessor();

            //Mock.SetupProcessAndBucket(mockSettingProcessor, returnValue: null);
            VWO.Configure(mockSettingProcessor.Object);

            var vwoClient = VWO.Instantiate(inValidSettings);

            Assert.Null(vwoClient);

            mockValidator.Verify(mock => mock.SettingsFile(It.IsAny <Settings>()), Times.Once);
            mockValidator.Verify(mock => mock.SettingsFile(It.Is <Settings>(val => ReferenceEquals(inValidSettings, val))), Times.Once);

            mockSettingProcessor.Verify(mock => mock.ProcessAndBucket(It.IsAny <Settings>()), Times.Once);
            mockSettingProcessor.Verify(mock => mock.ProcessAndBucket(It.Is <Settings>(val => ReferenceEquals(val, inValidSettings))), Times.Once);
        }
Пример #4
0
        public void Instantiate_Should_Return_Null_For_InValid_Settings_File_And_Call_Settings_Processor()
        {
            var inValidSettings = new Settings(null, null, -2, -1);
            var mockValidator   = Mock.GetValidator();

            Mock.SetupSettingsFile(mockValidator, false);
            VWO.Configure(mockValidator.Object);
            var mockSettingProcessor = Mock.GetSettingsProcessor();

            VWO.Configure(mockSettingProcessor.Object);

            var vwoClient = VWO.Instantiate(inValidSettings);

            Assert.Null(vwoClient);

            mockValidator.Verify(mock => mock.SettingsFile(It.IsAny <Settings>()), Times.Once);
            mockValidator.Verify(mock => mock.SettingsFile(It.Is <Settings>(val => ReferenceEquals(inValidSettings, val))), Times.Once);

            mockSettingProcessor.Verify(mock => mock.ProcessAndBucket(It.IsAny <Settings>()), Times.Never);
            mockSettingProcessor.Verify(mock => mock.ProcessAndBucket(It.Is <Settings>(val => ReferenceEquals(val, inValidSettings))), Times.Never);
        }
        public void GetVariation_Should_Return_Desired_Output(string campaignTestKey, string userId, bool expectedPartOfCampaign, string expectedVariationName)
        {
            AppContext.Configure(new FileReaderApiCaller("Campaign50percVariation50-50"));
            VWO.Configure(new Validator());
            var settings = VWO.GetSettings(123456, "sampleSdkKey");
            Assert.NotNull(settings);
            Assert.Equal(123456, settings.AccountId);
            Assert.Equal("sampleSdkKey", settings.SdkKey);

            var vwoClient = VWO.Instantiate(settings, isDevelopmentMode: true);
            var getVariationResponse = vwoClient.GetVariation(campaignTestKey, userId);
            if (expectedPartOfCampaign)
            {
                Assert.NotNull(getVariationResponse);
                Assert.NotEmpty(getVariationResponse);
                Assert.Equal(expectedVariationName, getVariationResponse);
            }
            else
            {
                Assert.Null(expectedVariationName);
                Assert.Null(getVariationResponse);
            }

            var activateResponse = vwoClient.Activate(campaignTestKey, userId);
            if (expectedPartOfCampaign)
            {
                Assert.NotNull(activateResponse);
                Assert.NotEmpty(activateResponse);
                Assert.Equal(expectedVariationName, activateResponse);
            }
            else
            {
                Assert.Null(expectedVariationName);
                Assert.Null(activateResponse);
            }

            var trackResponse = vwoClient.Track(campaignTestKey, userId, "CUSTOM");
            Assert.Equal(expectedPartOfCampaign, trackResponse);
        }