コード例 #1
0
        public void TestBucketLogsCorrectlyWhenUserProfileFailsToSave()
        {
            Experiment experiment = ProjectConfig.Experiments[6];
            Variation  variation  = experiment.Variations[0];
            Decision   decision   = new Decision(variation.Id);
            Bucketer   bucketer   = new Bucketer(LoggerMock.Object);

            UserProfileServiceMock.Setup(up => up.Save(It.IsAny <Dictionary <string, object> >())).Throws(new System.Exception());

            var experimentBucketMap = new Dictionary <string, Decision>();

            experimentBucketMap[experiment.Id] = decision;

            UserProfile expectedUserProfile = new UserProfile(UserProfileId, experimentBucketMap);
            UserProfile saveUserProfile     = new UserProfile(UserProfileId, new Dictionary <string, Decision>());

            DecisionService decisionService = new DecisionService(bucketer,
                                                                  ErrorHandlerMock.Object, ProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);

            decisionService.SaveVariation(experiment, variation, saveUserProfile);

            LoggerMock.Verify(l => l.Log(LogLevel.ERROR, string.Format
                                             ("Failed to save variation \"{0}\" of experiment \"{1}\" for user \"{2}\".", variation.Id, experiment.Id, UserProfileId))
                              , Times.Once);
            ErrorHandlerMock.Verify(er => er.HandleError(It.IsAny <OptimizelySDK.Exceptions.OptimizelyRuntimeException>()), Times.Once);
        }