public void AllAttributesPrivateMakesAttributesPrivate()
        {
            var f    = new EventOutputFormatter(new SimpleConfiguration());
            var user = User.Builder("userkey")
                       .Anonymous(true)
                       .Avatar("http://avatar")
                       .Country("US")
                       .Custom("custom1", "value1")
                       .Custom("custom2", "value2")
                       .Email("*****@*****.**")
                       .FirstName("first")
                       .IPAddress("1.2.3.4")
                       .LastName("last")
                       .Name("me")
                       .Secondary("s")
                       .Build();
            var userJson = LdValue.Parse(@"{
                ""key"":""userkey"",
                ""anonymous"":true,
                ""privateAttrs"":[
                    ""avatar"", ""country"", ""custom1"", ""custom2"", ""email"",
                    ""firstName"", ""ip"", ""lastName"", ""name"", ""secondary""
                ]
                }");
            var config   = new SimpleConfiguration()
            {
                AllAttributesPrivate = true
            };

            TestInlineUserSerialization(user, userJson, config);
        }
Пример #2
0
        public void CommonRequestHeadersHaveUserAgent()
        {
            var config = new SimpleConfiguration();
            IDictionary <string, string> headers = Util.GetRequestHeaders(config, SimpleClientEnvironment.Instance);

            Assert.Equal("CommonClient/1.0.0", headers["User-Agent"]);
        }
Пример #3
0
        private void TestPrivateAttribute(string privateAttrName, bool globallyPrivate)
        {
            var builder = User.Builder("userkey")
                          .Anonymous(true)
                          .SecondaryKey("s");
            var topJsonBuilder = LdValue.BuildObject()
                                 .Add("key", "userkey")
                                 .Add("anonymous", true)
                                 .Add("secondary", "s");
            var customJsonBuilder = LdValue.BuildObject();
            Action <string, Func <string, IUserBuilderCanMakeAttributePrivate>, string, LdValue.ObjectBuilder> setAttr =
                (attrName, setter, value, jsonBuilder) =>
            {
                if (attrName == privateAttrName)
                {
                    if (globallyPrivate)
                    {
                        setter(value);
                    }
                    else
                    {
                        setter(value).AsPrivateAttribute();
                    }
                }
                else
                {
                    setter(value);
                    jsonBuilder.Add(attrName, value);
                }
            };

            setAttr("avatar", builder.Avatar, "http://avatar", topJsonBuilder);
            setAttr("country", builder.Country, "US", topJsonBuilder);
            setAttr("custom1", v => builder.Custom("custom1", v), "value1", customJsonBuilder);
            setAttr("custom2", v => builder.Custom("custom2", v), "value2", customJsonBuilder);
            setAttr("email", builder.Email, "*****@*****.**", topJsonBuilder);
            setAttr("firstName", builder.FirstName, "first", topJsonBuilder);
            setAttr("ip", builder.IPAddress, "1.2.3.4", topJsonBuilder);
            setAttr("lastName", builder.LastName, "last", topJsonBuilder);
            setAttr("name", builder.Name, "me", topJsonBuilder);

            topJsonBuilder.Add("custom", customJsonBuilder.Build());
            topJsonBuilder.Add("privateAttrs", LdValue.ArrayOf(LdValue.Of(privateAttrName)));
            var userJson = topJsonBuilder.Build();
            var config   = new SimpleConfiguration();

            if (globallyPrivate)
            {
                config.PrivateAttributeNames = new HashSet <string> {
                    privateAttrName
                };
            }
            ;

            TestInlineUserSerialization(builder.Build(), userJson, config);
        }
Пример #4
0
        public void CommonRequestHeadersHaveSdkKey()
        {
            var config = new SimpleConfiguration
            {
                SdkKey = "MyKey"
            };
            IDictionary <string, string> headers = Util.GetRequestHeaders(config, SimpleClientEnvironment.Instance);

            Assert.Equal("MyKey", headers["Authorization"]);
        }
 public StreamManagerTest()
 {
     _mockEventSource = new Mock <IEventSource>();
     _mockEventSource.Setup(es => es.StartAsync()).Returns(Task.CompletedTask);
     _eventSource        = _mockEventSource.Object;
     _eventSourceCreator = new StubEventSourceCreator(_eventSource);
     _config             = new SimpleConfiguration
     {
         SdkKey = SdkKey
     };
     _mockStreamProcessor = new Mock <IStreamProcessor>();
     _streamProcessor     = _mockStreamProcessor.Object;
     _streamProperties    = new StreamProperties(StreamUri, HttpMethod.Get, null);
 }
 private IEventProcessor MakeProcessor(SimpleConfiguration config)
 {
     return(new DefaultEventProcessor(config, new TestUserDeduplicator(),
                                      Util.MakeHttpClient(config, SimpleClientEnvironment.Instance), EventsUriPath));
 }
        private void TestInlineUserSerialization(User user, LdValue expectedJsonValue, SimpleConfiguration config)
        {
            config.InlineUsersInEvents = true;
            var f            = new EventOutputFormatter(config);
            var emptySummary = new EventSummary();

            var featureEvent = EventFactory.Default.NewFeatureRequestEvent(
                new FlagEventPropertiesBuilder("flag").Build(),
                user,
                new EvaluationDetail <LdValue>(LdValue.Null, null, EvaluationReason.OffReason),
                LdValue.Null);
            var outputEvent = LdValue.Parse(f.SerializeOutputEvents(new Event[] { featureEvent }, emptySummary, out var count)).Get(0);

            Assert.Equal(1, count);
            Assert.Equal(LdValue.Null, outputEvent.Get("userKey"));
            Assert.Equal(expectedJsonValue, outputEvent.Get("user"));

            var identifyEvent = EventFactory.Default.NewIdentifyEvent(user);

            outputEvent = LdValue.Parse(f.SerializeOutputEvents(new Event[] { featureEvent }, emptySummary, out count)).Get(0);
            Assert.Equal(1, count);
            Assert.Equal(LdValue.Null, outputEvent.Get("userKey"));
            Assert.Equal(expectedJsonValue, outputEvent.Get("user"));

            var customEvent = EventFactory.Default.NewCustomEvent("custom", user, LdValue.Null);

            outputEvent = LdValue.Parse(f.SerializeOutputEvents(new Event[] { featureEvent }, emptySummary, out count)).Get(0);
            Assert.Equal(1, count);
            Assert.Equal(LdValue.Null, outputEvent.Get("userKey"));
            Assert.Equal(expectedJsonValue, outputEvent.Get("user"));

            var indexEvent = new IndexEvent(0, user);

            outputEvent = LdValue.Parse(f.SerializeOutputEvents(new Event[] { indexEvent }, emptySummary, out count)).Get(0);
            Assert.Equal(1, count);
            Assert.Equal(LdValue.Null, outputEvent.Get("userKey"));
            Assert.Equal(expectedJsonValue, outputEvent.Get("user"));
        }