コード例 #1
0
        public void PredefinedContextTest()
        {
            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            var newContext = new Dictionary <string, object>()
            {
                ["key1"] = "value1",
                [PredefinedContext.LOCATION_CITY]    = "London",
                [PredefinedContext.OS_VERSION_CODE]  = 1,
                [PredefinedContext.APP_VERSION_CODE] = "1",
                [PredefinedContext.DEVICE_LOCALE]    = Array.Empty <string>(),
                [PredefinedContext.DEVICE_MODEL]     = null,
                [PredefinedContext.FLAGSHIP_CLIENT]  = "custom client"
            };

            defaultStrategy.UpdateContext(newContext);

            Assert.AreEqual(visitorDelegate.Context.Count, 6);
            Assert.AreEqual(visitorDelegate.Context[PredefinedContext.LOCATION_CITY], "London");

            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.PREDEFINED_CONTEXT_TYPE_ERROR,
                                                               PredefinedContext.APP_VERSION_CODE, "number"), "UpdateContext"), Times.Once());

            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.PREDEFINED_CONTEXT_TYPE_ERROR,
                                                               PredefinedContext.DEVICE_LOCALE, "string"), "UpdateContext"), Times.Once());

            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.PREDEFINED_CONTEXT_TYPE_ERROR,
                                                               PredefinedContext.DEVICE_MODEL, "string"), "UpdateContext"), Times.Once());
        }
コード例 #2
0
        public void UpdateContexTest()
        {
            var defaultStrategy = new DefaultStrategy(visitorDelegate);

            var newContext = new Dictionary <string, object>()
            {
                ["key1"] = "value1",
                ["key2"] = "value2"
            };

            defaultStrategy.UpdateContext(newContext);

            Assert.AreEqual(visitorDelegate.Context.Count, 5);

            var newContext2 = new Dictionary <string, object>()
            {
                ["key3"] = 5,
                ["key4"] = 1
            };

            defaultStrategy.UpdateContext(newContext2);

            Assert.AreEqual(visitorDelegate.Context.Count, 7);

            var newContext3 = new Dictionary <string, object>()
            {
                ["key5"] = true,
                ["key6"] = false
            };

            defaultStrategy.UpdateContext(newContext3);

            Assert.AreEqual(visitorDelegate.Context.Count, 9);

            defaultStrategy.UpdateContext("key1", "value3");
            Assert.AreEqual(visitorDelegate.Context["key1"], "value3");

            defaultStrategy.UpdateContext("key3", 10);
            Assert.AreEqual(10d, visitorDelegate.Context["key3"]);

            defaultStrategy.UpdateContext("key5", false);
            Assert.AreEqual(visitorDelegate.Context["key5"], false);

            var newContext4 = new Dictionary <string, object>()
            {
                ["key6"] = new object(),
            };

            defaultStrategy.UpdateContext(newContext4);
            Assert.AreEqual(visitorDelegate.Context.Count, 9);
            fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.CONTEXT_PARAM_ERROR, "key6"), "UpdateContex"), Times.Once());

            //Test clearContext

            defaultStrategy.ClearContext();
            Assert.AreEqual(visitorDelegate.Context.Count, 0);
        }