Example #1
0
        public void TestRawObjectLastWrittenValueWins()
        {
            const string key               = "foo";
            const string detail            = "bar";
            const string detailNew         = "barnew";
            const string detailNewer       = "barnewer";
            const string detailNewest      = "barnewest";
            const string detailNewestFinal = "barnewestfinal";

            var context = new TelemetryContext();

            // Overwrite temp key value with new temp value
            context.StoreRawObject(key, detail, true);
            context.StoreRawObject(key, detailNew, true);
            Assert.IsTrue(context.TryGetRawObject(key, out object actualNew));
            Assert.AreSame(detailNew, actualNew);

            // Overwrite temp key value with new perm value
            context.StoreRawObject(key, detailNewer, false);
            Assert.IsTrue(context.TryGetRawObject(key, out object actualNewer));
            Assert.AreSame(detailNewer, actualNewer);

            // Overwrite perm key value with new perm value
            context.StoreRawObject(key, detailNewest, false);
            Assert.IsTrue(context.TryGetRawObject(key, out object actualNewest));
            Assert.AreSame(detailNewest, actualNewest);

            // Overwrite perm key value with new temp value
            context.StoreRawObject(key, detailNewestFinal, true);
            Assert.IsTrue(context.TryGetRawObject(key, out object actualNewestFinal));
            Assert.AreSame(detailNewestFinal, actualNewestFinal);
        }
Example #2
0
        public void TestRawObjectIsSharedOnDeepCopy()
        {
            string keyTemp       = "keyTemp";
            string detailTemp    = "valueTemp";
            var    detailTempObj = new MyCustomObject(detailTemp);
            string keyPerm       = "keyPerm";
            string detailPerm    = "valuePerm";
            var    detailPermObj = new MyCustomObject(detailPerm);

            var context = new TelemetryContext();

            context.StoreRawObject(keyTemp, detailTempObj);
            context.StoreRawObject(keyPerm, detailPermObj, false);
            Assert.IsTrue(context.TryGetRawObject(keyTemp, out object actualTemp));
            Assert.AreEqual(detailTempObj, actualTemp);
            Assert.IsTrue(context.TryGetRawObject(keyPerm, out object actualPerm));
            Assert.AreEqual(detailPermObj, actualPerm);

            var clonedContext = context.DeepClone();

            Assert.IsTrue(clonedContext.TryGetRawObject(keyTemp, out object actualTempFromClone));
            Assert.AreEqual(detailTempObj, actualTempFromClone);
            Assert.IsTrue(clonedContext.TryGetRawObject(keyPerm, out object actualPermFromClone));
            Assert.AreEqual(detailPermObj, actualPermFromClone);

            // Modify the object in original context
            context.TryGetRawObject(keyTemp, out object tempObjFromOriginal);
            ((MyCustomObject)tempObjFromOriginal).v = "new temp value";

            clonedContext.TryGetRawObject(keyTemp, out object tempObjFromClone);

            // validate that modifying original context affects the clone.
            Assert.AreEqual(((MyCustomObject)tempObjFromOriginal).v, ((MyCustomObject)tempObjFromClone).v);
        }
Example #3
0
        public void TestRawObjectIsOverwritten()
        {
            const string key       = "foo";
            const string detail    = "bar";
            const string detailNew = "barnew";

            var context = new TelemetryContext();

            context.StoreRawObject(key, detail);
            Assert.IsTrue(context.TryGetRawObject(key, out object actual));
            Assert.AreSame(detail, actual);

            context.StoreRawObject(key, detailNew);
            Assert.IsTrue(context.TryGetRawObject(key, out object actualNew));
            Assert.AreSame(detailNew, actualNew);
        }
Example #4
0
        public void TestTelemetryContextDoesNotThrowOnInvalidKeysValuesForRawObjectStore()
        {
            const string key     = "";
            const string detail  = "bar";
            var          context = new TelemetryContext();

            // These shouldn't throw.
            context.StoreRawObject(null, detail);
            context.StoreRawObject(null, detail, false);
            context.TryGetRawObject(null, out object actualDontExist);

            context.StoreRawObject(null, null);
            context.StoreRawObject(null, null, false);
            context.TryGetRawObject(null, out object actualDontExist1);

            context.StoreRawObject("key", null);
            Assert.IsTrue(context.TryGetRawObject("key", out object actual));
            Assert.AreSame(null, actual);

            context.StoreRawObject(key, detail);
            Assert.IsTrue(context.TryGetRawObject(key, out object actual1));
            Assert.AreSame(detail, actual1);

            context.StoreRawObject(string.Empty, detail);
            Assert.IsTrue(context.TryGetRawObject(string.Empty, out object actual2));
            Assert.AreSame(detail, actual2);
        }
Example #5
0
        public void TestClearsTempRawObjects()
        {
            const string keyTemp    = "fooTemp";
            const string detailTemp = "barTemp";
            const string keyPerm    = "fooPerm";
            const string detailPerm = "barPerm";

            var context = new TelemetryContext();

            context.StoreRawObject(keyTemp, detailTemp, true);
            context.StoreRawObject(keyPerm, detailPerm, false);

            Assert.IsTrue(context.TryGetRawObject(keyTemp, out object temp));
            Assert.IsTrue(context.TryGetRawObject(keyPerm, out object perm));

            context.ClearTempRawObjects();
            Assert.IsFalse(context.TryGetRawObject(keyTemp, out object tempAfterCleanup));
            Assert.IsTrue(context.TryGetRawObject(keyPerm, out object permAfterCleanup));
        }
Example #6
0
        public void TestStoresRawObject()
        {
            const string key    = "foo";
            const string detail = "bar";

            var context = new TelemetryContext();

            context.StoreRawObject(key, detail);
            Assert.IsFalse(context.TryGetRawObject("keyDontExst", out object actualDontExist));
            Assert.IsTrue(context.TryGetRawObject(key, out object actual));
            Assert.AreEqual(detail, actual);
        }