コード例 #1
0
        public void TestManagerAddClientContextCustomAttribute()
        {
            string KEY1   = Guid.NewGuid().ToString();
            string KEY2   = Guid.NewGuid().ToString();
            string VALUE1 = Guid.NewGuid().ToString();
            string VALUE2 = Guid.NewGuid().ToString();
            string appID  = Guid.NewGuid().ToString();

            MobileAnalyticsManager manager = MobileAnalyticsManager.GetOrCreateInstance(appID, Credentials, RegionEndpoint.USEast1, new MobileAnalyticsManagerConfig());

            manager.AddCustomAttributeToClientContext(KEY1, VALUE1);
            manager.AddCustomAttributeToClientContext(KEY2, VALUE2);

            var    type                = manager.GetType();
            var    property            = type.GetProperty("ClientContext", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var    clientContext       = property.GetValue(manager, null) as ClientContext;
            string clientContextString = clientContext.ToJsonString();

            Assert.IsTrue(clientContextString.IndexOf("custom") > 0);
            Assert.IsTrue(clientContextString.IndexOf(KEY1) > 0);
            Assert.IsTrue(clientContextString.IndexOf(KEY2) > 0);
            Assert.IsTrue(clientContextString.IndexOf(VALUE1) > 0);
            Assert.IsTrue(clientContextString.IndexOf(VALUE2) > 0);

            Assert.IsTrue(clientContextString.IndexOf("custom") < clientContextString.IndexOf(KEY1));
            Assert.IsTrue(clientContextString.IndexOf("custom") < clientContextString.IndexOf(KEY2));
            Assert.IsTrue(clientContextString.IndexOf(KEY1) < clientContextString.IndexOf(VALUE1));
            Assert.IsTrue(clientContextString.IndexOf(KEY2) < clientContextString.IndexOf(VALUE2));
        }