示例#1
0
        protected override void WriteInternal(LogLevel level, object message, Exception exception)
        {
            var str = message?.ToString();

            if (_showLogs)
            {
                Console.WriteLine("*** LOG: [" + level + "] " + str);
            }
            LogSinkScope.WithCurrent(s => s.Messages.Add(new LogItem {
                Level = level, Text = str
            }));
        }
        public void InitFailsOn401Sync(UpdateMode mode)
        {
            WithServer(server =>
            {
                server.ForAllRequests(r => r.WithStatusCode(401));

                using (var log = new LogSinkScope())
                {
                    var config = BaseConfig(server, mode);
                    using (var client = TestUtil.CreateClient(config, _user))
                    {
                        Assert.False(client.Initialized);
                    }
                }
            });
        }
        public void InitCanTimeOutSync()
        {
            WithServer(server =>
            {
                server.ForAllRequests(r => r.WithDelay(TimeSpan.FromSeconds(2)).WithJsonBody(PollingData(_flagData1)));

                using (var log = new LogSinkScope())
                {
                    var config = BaseConfig(server, builder => builder.IsStreamingEnabled(false));
                    using (var client = TestUtil.CreateClient(config, _user, TimeSpan.FromMilliseconds(200)))
                    {
                        Assert.False(client.Initialized);
                        Assert.Null(client.StringVariation(_flagData1.First().Key, null));
                        Assert.Contains(log.Messages, m => m.Level == LogLevel.Warn &&
                                        m.Text == "Client did not successfully initialize within 200 milliseconds.");
                    }
                }
            });
        }
        public async Task InitFailsOn401Async(UpdateMode mode)
        {
            await WithServerAsync(async server =>
            {
                server.ForAllRequests(r => r.WithStatusCode(401));

                using (var log = new LogSinkScope())
                {
                    var config = BaseConfig(server, mode);

                    // Currently the behavior of LdClient.InitAsync is somewhat inconsistent with LdClient.Init if there is
                    // an unrecoverable error: LdClient.Init throws an exception, but LdClient.InitAsync returns a task that
                    // will complete successfully with an uninitialized client.
                    using (var client = await TestUtil.CreateClientAsync(config, _user))
                    {
                        Assert.False(client.Initialized);
                    }
                }
            });
        }