Exemplo n.º 1
0
        internal static ConfigurationBuilder ConfigWithFlagsJson(User user, string appKey, string flagsJson)
        {
            var            flags            = DecodeFlagsJson(flagsJson);
            IUserFlagCache stubbedFlagCache = new UserFlagInMemoryCache();

            if (user != null && user.Key != null)
            {
                stubbedFlagCache.CacheFlagsForUser(flags, user);
            }

            return(Configuration.BuilderInternal(appKey)
                   .FlagCacheManager(new MockFlagCacheManager(stubbedFlagCache))
                   .ConnectivityStateManager(new MockConnectivityStateManager(true))
                   .EventProcessor(new MockEventProcessor())
                   .UpdateProcessorFactory(MockPollingProcessor.Factory(null))
                   .PersistentStorage(new MockPersistentStorage())
                   .DeviceInfo(new MockDeviceInfo("")));
        }
        public async void IdentifyPassesUserToUpdateProcessorFactory()
        {
            MockPollingProcessor stub = new MockPollingProcessor("{}");
            User newUser = User.WithKey("new-user");

            var config = TestUtil.ConfigWithFlagsJson(simpleUser, appKey, "{}")
                         .UpdateProcessorFactory(stub.AsFactory())
                         .Build();

            using (var client = await LdClient.InitAsync(config, simpleUser))
            {
                Assert.Same(simpleUser, stub.ReceivedUser);

                await client.IdentifyAsync(newUser);

                Assert.Same(newUser, stub.ReceivedUser);
            }
        }
        public async void IdentifyWithAutoGeneratedAnonUserPassesGeneratedUserToUpdateProcessorFactory()
        {
            MockPollingProcessor stub = new MockPollingProcessor("{}");
            User anonUserIn           = User.Builder((String)null).Anonymous(true).Build();

            var config = TestUtil.ConfigWithFlagsJson(simpleUser, appKey, "{}")
                         .UpdateProcessorFactory(stub.AsFactory())
                         .Build();

            using (var client = await LdClient.InitAsync(config, simpleUser))
            {
                Assert.Same(simpleUser, stub.ReceivedUser);

                await client.IdentifyAsync(anonUserIn);

                Assert.NotSame(simpleUser, stub.ReceivedUser);
                Assert.Equal(MockDeviceInfo.GeneratedId, stub.ReceivedUser.Key);
                Assert.True(stub.ReceivedUser.Anonymous);
            }
        }
        public static Configuration Config(User user, string appKey)
        {
            var stubbedFlagCache = JSONReader.StubbedFlagCache(user);

            // overriding the default implementation of dependencies for testing purposes
            var mockOnlineConnectionManager = new MockConnectionManager(true);
            var mockFlagCacheManager        = new MockFlagCacheManager(stubbedFlagCache);
            var mockPollingProcessor        = new MockPollingProcessor();
            var mockPersister       = new MockPersister();
            var mockDeviceInfo      = new MockDeviceInfo();
            var featureFlagListener = new FeatureFlagListenerManager();

            Configuration configuration = Configuration.Default(appKey)
                                          .WithFlagCacheManager(mockFlagCacheManager)
                                          .WithConnectionManager(mockOnlineConnectionManager)
                                          .WithUpdateProcessor(mockPollingProcessor)
                                          .WithPersister(mockPersister)
                                          .WithDeviceInfo(mockDeviceInfo)
                                          .WithFeatureFlagListenerManager(featureFlagListener);

            return(configuration);
        }