public void TestFileCreation_AddNewBreadcrumbToFile_SuccessfullyAddedBreadcrumb(LogType testedLevel)
        {
            var          currentTime               = DateTimeHelper.TimestampMs();
            const string breadcrumbMessage         = "foo";
            var          breadcrumbFile            = new InMemoryBreadcrumbFile();
            var          breadcrumbsStorageManager = new BacktraceStorageLogManager(Application.temporaryCachePath)
            {
                BreadcrumbFile = breadcrumbFile
            };
            var breadcrumbsManager  = new BacktraceBreadcrumbs(breadcrumbsStorageManager);
            var unityEngineLogLevel = breadcrumbsManager.ConvertLogTypeToLogLevel(testedLevel);
            var logTypeThatUnsupportCurrentTestCase =
                (Enum.GetValues(typeof(UnityEngineLogLevel)) as IEnumerable <UnityEngineLogLevel>)
                .First(n => n == unityEngineLogLevel);

            breadcrumbsManager.EnableBreadcrumbs(ManualBreadcrumbsType, logTypeThatUnsupportCurrentTestCase);
            var added = breadcrumbsManager.Log(breadcrumbMessage, testedLevel);

            Assert.IsTrue(added);
            var data = ConvertToBreadcrumbs(breadcrumbFile);

            Assert.AreEqual(1, data.Count());
            var breadcrumb = data.First();

            Assert.AreEqual(ManualBreadcrumbsType, (BacktraceBreadcrumbType)breadcrumb.Type);
            Assert.AreEqual(unityEngineLogLevel, breadcrumb.Level);
            Assert.AreEqual(breadcrumbMessage, breadcrumb.Message);
            // round timestamp because timestamp value in the final json will reduce decimal part.
            Assert.That(Math.Round(currentTime, 0), Is.LessThanOrEqualTo(Math.Round(breadcrumb.Timestamp, 0)));
        }
Esempio n. 2
0
        public void TestLogLevel_ShouldtFilterLogLevelWithAttributes_BreadcrumbIsAvailable(LogType testedLevel)
        {
            const string message                             = "message";
            const string attributeName                       = "foo";
            const string attributeValue                      = "bar";
            const int    expectedNumberOfLogs                = 1;
            var          inMemoryBreadcrumbStorage           = new BacktraceInMemoryLogManager();
            var          breadcrumbsManager                  = new BacktraceBreadcrumbs(inMemoryBreadcrumbStorage);
            var          unityEngineLogLevel                 = breadcrumbsManager.ConvertLogTypeToLogLevel(testedLevel);
            var          logTypeThatUnsupportCurrentTestCase =
                (Enum.GetValues(typeof(UnityEngineLogLevel)) as IEnumerable <UnityEngineLogLevel>)
                .First(n => n == unityEngineLogLevel);

            breadcrumbsManager.EnableBreadcrumbs(ManualBreadcrumbsType, logTypeThatUnsupportCurrentTestCase);
            var result = breadcrumbsManager.Log(message, testedLevel, new Dictionary <string, string>()
            {
                { attributeName, attributeValue }
            });

            Assert.IsTrue(result);
            Assert.AreEqual(expectedNumberOfLogs, inMemoryBreadcrumbStorage.Breadcrumbs.Count);
            var breadcrumb = inMemoryBreadcrumbStorage.Breadcrumbs.ElementAt(0);

            Assert.IsTrue(breadcrumb.Attributes.ContainsKey(attributeName));
            Assert.AreEqual(attributeValue, breadcrumb.Attributes[attributeName]);
        }
Esempio n. 3
0
        public void TestLogLogs_ShouldEnableThem_EventsAreSet()
        {
            var inMemoryBreadcrumbStorage = new BacktraceInMemoryLogManager();
            var breadcrumbsManager        = new BacktraceBreadcrumbs(inMemoryBreadcrumbStorage);
            UnityEngineLogLevel level     = UnityEngineLogLevel.Debug | UnityEngineLogLevel.Error | UnityEngineLogLevel.Fatal | UnityEngineLogLevel.Info | UnityEngineLogLevel.Warning;

            breadcrumbsManager.EnableBreadcrumbs(BacktraceBreadcrumbType.Log, level);

            Assert.IsTrue(breadcrumbsManager.EventHandler.HasRegisteredEvents);
            breadcrumbsManager.UnregisterEvents();
        }
Esempio n. 4
0
        public void WarningLogLevel_ShouldFilterWarningLogLevel_BreadcrumbsWasntSave()
        {
            const string message = "message";
            const int    expectedNumberOfLogs                = 0;
            var          inMemoryBreadcrumbStorage           = new BacktraceInMemoryLogManager();
            var          breadcrumbsManager                  = new BacktraceBreadcrumbs(inMemoryBreadcrumbStorage);
            var          logTypeThatUnsupportCurrentTestCase = UnityEngineLogLevel.Error;

            breadcrumbsManager.EnableBreadcrumbs(ManualBreadcrumbsType, logTypeThatUnsupportCurrentTestCase);
            var result = breadcrumbsManager.Warning(message);

            Assert.IsFalse(result);
            Assert.AreEqual(expectedNumberOfLogs, inMemoryBreadcrumbStorage.Breadcrumbs.Count);
        }
Esempio n. 5
0
        public void WarningLogLevel_ShouldntFilterWarningLogLevel_BreadcrumbIsAvailable()
        {
            const string message = "message";
            const int    expectedNumberOfLogs      = 1;
            var          inMemoryBreadcrumbStorage = new BacktraceInMemoryLogManager();
            var          breadcrumbsManager        = new BacktraceBreadcrumbs(inMemoryBreadcrumbStorage);
            var          supportedLogLevel         = UnityEngineLogLevel.Warning;

            breadcrumbsManager.EnableBreadcrumbs(ManualBreadcrumbsType, supportedLogLevel);

            var result = breadcrumbsManager.Warning(message);

            Assert.IsTrue(result);
            Assert.AreEqual(expectedNumberOfLogs, inMemoryBreadcrumbStorage.Breadcrumbs.Count);
        }
Esempio n. 6
0
        public void TestManualLogs_ShouldFilterAllManualLogs_BreadcrumbsWasntSaved(LogType testedLevel)
        {
            const string message = "message";
            const int    expectedNumberOfLogs      = 0;
            var          inMemoryBreadcrumbStorage = new BacktraceInMemoryLogManager();
            var          breadcrumbsManager        = new BacktraceBreadcrumbs(inMemoryBreadcrumbStorage);
            //anything else than Manual
            var breadcrumbType        = BacktraceBreadcrumbType.Configuration;
            UnityEngineLogLevel level = UnityEngineLogLevel.Debug | UnityEngineLogLevel.Error | UnityEngineLogLevel.Fatal | UnityEngineLogLevel.Info | UnityEngineLogLevel.Warning;

            breadcrumbsManager.EnableBreadcrumbs(breadcrumbType, level);
            var result = breadcrumbsManager.Log(message, testedLevel);

            Assert.IsFalse(result);
            Assert.AreEqual(expectedNumberOfLogs, inMemoryBreadcrumbStorage.Breadcrumbs.Count);
        }
Esempio n. 7
0
        public void TestLogLevel_ShouldFilterLogLevel_BreadcrumbIsNotAvailable(LogType testedLevel)
        {
            const string message = "message";
            const int    expectedNumberOfLogs      = 0;
            var          inMemoryBreadcrumbStorage = new BacktraceInMemoryLogManager();
            var          breadcrumbsManager        = new BacktraceBreadcrumbs(inMemoryBreadcrumbStorage);

            var logTypeThatUnsupportCurrentTestCase =
                (Enum.GetValues(typeof(UnityEngineLogLevel)) as IEnumerable <UnityEngineLogLevel>)
                .First(n => n != breadcrumbsManager.ConvertLogTypeToLogLevel(testedLevel));

            breadcrumbsManager.EnableBreadcrumbs(ManualBreadcrumbsType, logTypeThatUnsupportCurrentTestCase);

            var result = breadcrumbsManager.Log(message, testedLevel);

            Assert.IsFalse(result);
            Assert.AreEqual(expectedNumberOfLogs, inMemoryBreadcrumbStorage.Breadcrumbs.Count);
        }
        public void TestFileLimit_ShouldCleanupTheSpace_SpaceWasCleaned()
        {
            const string breadcrumbMessage         = "foo";
            const int    minimalSize               = 10 * 1000;
            var          breadcrumbFile            = new InMemoryBreadcrumbFile();
            var          breadcrumbsStorageManager = new BacktraceStorageLogManager(Application.temporaryCachePath)
            {
                BreadcrumbFile  = breadcrumbFile,
                BreadcrumbsSize = minimalSize
            };
            var breadcrumbsManager  = new BacktraceBreadcrumbs(breadcrumbsStorageManager);
            var unityEngineLogLevel = UnityEngineLogLevel.Debug;
            var breadcrumbStart     = breadcrumbsManager.BreadcrumbId();

            breadcrumbsManager.EnableBreadcrumbs(ManualBreadcrumbsType, unityEngineLogLevel);
            int numberOfAddedBreadcrumbs = 1;

            breadcrumbsManager.Log(breadcrumbMessage, LogType.Assert);
            var breadcrumbSize = breadcrumbFile.Size - 2;

            while (breadcrumbFile.Size + breadcrumbSize < minimalSize != false)
            {
                breadcrumbsManager.Log(breadcrumbMessage, LogType.Assert);
                numberOfAddedBreadcrumbs++;
            }
            var sizeBeforeCleanup = breadcrumbFile.Size;
            var numberOfBreadcurmbsBeforeCleanUp = numberOfAddedBreadcrumbs;

            breadcrumbsManager.Log(breadcrumbMessage, LogType.Assert);
            numberOfAddedBreadcrumbs++;

            Assert.That(breadcrumbFile.Size, Is.LessThan(sizeBeforeCleanup));
            var data = ConvertToBreadcrumbs(breadcrumbFile);

            Assert.IsNotEmpty(data);
            Assert.AreEqual(breadcrumbStart + numberOfAddedBreadcrumbs, breadcrumbsStorageManager.BreadcrumbId());
            Assert.That(breadcrumbsStorageManager.Length(), Is.LessThan(numberOfBreadcurmbsBeforeCleanUp));
        }
        public void TestBreadcrumbs_BasicBreadcrumbsTestForAllEvents_ShouldStoreEvents()
        {
            const int expectedNumberOfBreadcrumbs = 3;

            string[] messages = new string[expectedNumberOfBreadcrumbs] {
                "CustomUserBreadcrumb1",
                "PlayerStarted",
                "unhandled exception custom message from breadcrumbs test case"
            };

            var breadcrumb1Attributes = new Dictionary <string, string>()
            {
                { "name", "CustomUserBreadcrumb1Value" }
            };

            var breadcrumbFile            = new InMemoryBreadcrumbFile();
            var breadcrumbsStorageManager = new BacktraceStorageLogManager(Application.temporaryCachePath)
            {
                BreadcrumbFile = breadcrumbFile
            };
            var breadcrumbsManager   = new BacktraceBreadcrumbs(breadcrumbsStorageManager);
            var expectedBreadcrumbId = breadcrumbsManager.BreadcrumbId();
            var unityEngineLogLevel  = UnityEngineLogLevel.Debug | UnityEngineLogLevel.Warning | UnityEngineLogLevel.Info | UnityEngineLogLevel.Error | UnityEngineLogLevel.Fatal;

            breadcrumbsManager.EnableBreadcrumbs(BacktraceBreadcrumbType.Manual | BacktraceBreadcrumbType.System, unityEngineLogLevel);
            breadcrumbsManager.Warning(messages[0], breadcrumb1Attributes);
            breadcrumbsManager.Info(messages[1]);
            breadcrumbsManager.Exception(messages[2]);

            Assert.AreEqual(expectedNumberOfBreadcrumbs, breadcrumbsStorageManager.Length());
            Assert.AreEqual(expectedNumberOfBreadcrumbs + expectedBreadcrumbId, breadcrumbsStorageManager.BreadcrumbId());
            var breadcrumbs = ConvertToBreadcrumbs(breadcrumbFile);

            for (int i = 0; i < expectedNumberOfBreadcrumbs; i++)
            {
                Assert.AreEqual(messages[i], breadcrumbs.ElementAt(i).Message);
            }
        }
Esempio n. 10
0
        public void TestLogLevel_ShouldtFilterLogLevel_BreadcrumbIsAvailable(LogType testedLevel)
        {
            const string message = "message";
            const int    expectedNumberOfLogs                = 1;
            var          inMemoryBreadcrumbStorage           = new BacktraceInMemoryLogManager();
            var          breadcrumbsManager                  = new BacktraceBreadcrumbs(inMemoryBreadcrumbStorage);
            var          unityEngineLogLevel                 = breadcrumbsManager.ConvertLogTypeToLogLevel(testedLevel);
            var          logTypeThatUnsupportCurrentTestCase =
                (Enum.GetValues(typeof(UnityEngineLogLevel)) as IEnumerable <UnityEngineLogLevel>)
                .First(n => n == unityEngineLogLevel);

            breadcrumbsManager.EnableBreadcrumbs(ManualBreadcrumbsType, logTypeThatUnsupportCurrentTestCase);
            var result = breadcrumbsManager.Log(message, testedLevel);

            Assert.IsTrue(result);
            Assert.AreEqual(expectedNumberOfLogs, inMemoryBreadcrumbStorage.Breadcrumbs.Count);
            var breadcrumb = inMemoryBreadcrumbStorage.Breadcrumbs.ElementAt(0);

            Assert.AreEqual(message, breadcrumb.Message);
            Assert.AreEqual(unityEngineLogLevel, breadcrumb.Level);
            Assert.AreEqual(BreadcrumbLevel.Manual, breadcrumb.Type);
            Assert.IsNull(breadcrumb.Attributes);
        }
Esempio n. 11
0
        public void DebugLogLevel_ShouldntFilterDebugLogLevelWithAttributes_BreadcrumbIsAvailable()
        {
            const string message                   = "message";
            const string attributeName             = "foo";
            const string attributeValue            = "bar";
            const int    expectedNumberOfLogs      = 1;
            var          inMemoryBreadcrumbStorage = new BacktraceInMemoryLogManager();
            var          breadcrumbsManager        = new BacktraceBreadcrumbs(inMemoryBreadcrumbStorage);
            var          supportedLogLevel         = UnityEngineLogLevel.Debug;

            breadcrumbsManager.EnableBreadcrumbs(ManualBreadcrumbsType, supportedLogLevel);
            var result = breadcrumbsManager.Debug(message, new Dictionary <string, string>()
            {
                { attributeName, attributeValue }
            });

            Assert.IsTrue(result);
            Assert.AreEqual(expectedNumberOfLogs, inMemoryBreadcrumbStorage.Breadcrumbs.Count);
            var breadcrumbAttributes = inMemoryBreadcrumbStorage.Breadcrumbs.ElementAt(0).Attributes;

            Assert.IsTrue(breadcrumbAttributes.ContainsKey(attributeName));
            Assert.AreEqual(attributeValue, breadcrumbAttributes[attributeName]);
        }