public void HandleUnhandledEvents_LargeNumberOfUnhandledEvents()
        {
            //Prepare
            //Create a brand new singleton, ensure it initializes and has an empty list of eventhandlers
            DiagnosticEventCollectorSingleton.DestroySingleton();

            DiagnosticEventCollectorSingleton.Instance.m_UnhandledEvents = new List <DiagnosticEvent>();
            DiagnosticEventCollectorSingleton.Instance.m_UnhandledEvents.Add(createGenericDiagnosticEvent(0, opCreate, 0));
            DiagnosticEventCollectorSingleton.Instance.m_UnhandledEvents.Add(createGenericDiagnosticEvent(1, opCreate, 1));
            DiagnosticEventCollectorSingleton.Instance.m_UnhandledEvents.Add(createGenericDiagnosticEvent(1, opRefcount, 2));
            DiagnosticEventCollectorSingleton.Instance.m_UnhandledEvents.Add(createGenericDiagnosticEvent(1, opRefcount, 3));
            DiagnosticEventCollectorSingleton.Instance.m_UnhandledEvents.Add(createGenericDiagnosticEvent(1, opRefcount, 4));
            DiagnosticEventCollectorSingleton.Instance.m_UnhandledEvents.Add(createGenericDiagnosticEvent(1, opRefcount, 5));

            DiagnosticEventCollectorSingleton.Instance.m_CreatedEvents = new Dictionary <int, DiagnosticEvent>();
            DiagnosticEventCollectorSingleton.Instance.m_CreatedEvents.Add(0, createGenericDiagnosticEvent(0, opCreate, 0));
            DiagnosticEventCollectorSingleton.Instance.m_CreatedEvents.Add(1, createGenericDiagnosticEvent(1, opCreate, 1));

            DiagnosticEventCollectorSingleton.Instance.RegisterEventHandler(TrackingHandler);

            //This is ensuring that the events are handled in the proper order
            LogAssert.Expect(UnityEngine.LogType.Log, "0");
            LogAssert.Expect(UnityEngine.LogType.Log, "0");
            LogAssert.Expect(UnityEngine.LogType.Log, "1");
            LogAssert.Expect(UnityEngine.LogType.Log, "1");
            LogAssert.Expect(UnityEngine.LogType.Log, "2");
            LogAssert.Expect(UnityEngine.LogType.Log, "3");
            LogAssert.Expect(UnityEngine.LogType.Log, "4");
            LogAssert.Expect(UnityEngine.LogType.Log, "5");

            Assert.AreEqual(0, DiagnosticEventCollectorSingleton.Instance.m_UnhandledEvents.Count, "Unhandled event queue should be completely emptied after HandleUnhandledEvents is called.");
            Assert.AreEqual(2, DiagnosticEventCollectorSingleton.Instance.m_CreatedEvents.Count, "Number of events in CreatedEvents should not be affected. ");
            //cleanup
            DiagnosticEventCollectorSingleton.DestroySingleton();
        }
 public void Dispose()
 {
     m_ResourceManager?.UnregisterDiagnosticCallback(OnResourceManagerDiagnosticEvent);
     if (DiagnosticEventCollectorSingleton.Exists)
     {
         DiagnosticEventCollectorSingleton.DestroySingleton();
     }
 }
        public void RegisterEventHandler_ReturnsFalseOnNonexistentSingletonAndCreateEqualsFalse()
        {
            //Prepare
            DiagnosticEventCollectorSingleton.DestroySingleton();

            //Act/Assert
            Assert.AreEqual(false, DiagnosticEventCollectorSingleton.Exists, "Singleton exists when it should not have been initialized.");
            Assert.AreEqual(false, DiagnosticEventCollectorSingleton.RegisterEventHandler(DummyHandler, true, false), "RegisterEventHandler returning true when Exists and create should both be false. ");

            //Cleanup
            DiagnosticEventCollectorSingleton.DestroySingleton();
        }
        public void RegisterEventHandler_ReturnsTrueOnNonexistentSingletonAndCreateEqualsTrue()
        {
            //Prepare
            DiagnosticEventCollectorSingleton.DestroySingleton();


            //Act/Assert
            Assert.AreEqual(false, DiagnosticEventCollectorSingleton.Exists, "Singleton exists when it should not have been initialized.");
            Assert.AreEqual(true, DiagnosticEventCollectorSingleton.RegisterEventHandler(DummyHandler, true, true), "RegisterEventHandler returning false, not registering handler when registration was expected. ");

            //Cleanup
            DiagnosticEventCollectorSingleton.DestroySingleton();
        }
        public void RegisterEventHandler_ReturnsFalseOnUnregisterOnNonexistentHandler()
        {
            //Prepare
            //Create a brand new singleton, ensure it initializes
            DiagnosticEventCollectorSingleton.DestroySingleton();

            var handlerCount = DiagnosticEventCollectorSingleton.Instance.s_EventHandlers.Count;

            //Act/Assert
            Assert.AreEqual(false, DiagnosticEventCollectorSingleton.RegisterEventHandler(DummyHandler, false, false), "Event handler returned registered a handler despite register being false.");
            Assert.AreEqual(handlerCount, DiagnosticEventCollectorSingleton.Instance.s_EventHandlers.Count, "Event handler was registered when no registration should've occurred. ");

            //cleanup
            DiagnosticEventCollectorSingleton.DestroySingleton();
        }
        public void RegisterEventHandler_ProperlyRegistersHandlerOnRegisterCreate()
        {
            //Prepare
            //Create a brand new singleton, ensure it initializes
            DiagnosticEventCollectorSingleton.DestroySingleton();

            var handlerCount = DiagnosticEventCollectorSingleton.Instance.s_EventHandlers.Count;

            //Act/Assert
            Assert.AreEqual(true, DiagnosticEventCollectorSingleton.RegisterEventHandler(DummyHandler, true, true), "Handler was not registered despite create and exist both being true.");
            Assert.AreEqual(handlerCount + 1, DiagnosticEventCollectorSingleton.Instance.s_EventHandlers.Count, "Event Handler was not properly assigned in s_EventHandlers.");

            //cleanup
            DiagnosticEventCollectorSingleton.DestroySingleton();
        }
        public void RegisterEventHandler_TwoRegisterEmptyRemoval()
        {
            //Prepare
            //Create a brand new singleton, ensure it initializes and has an empty list of eventhandlers
            DiagnosticEventCollectorSingleton.DestroySingleton();

            var handlerCount = DiagnosticEventCollectorSingleton.Instance.s_EventHandlers.Count;

            //Act/Assert
            Assert.AreEqual(true, DiagnosticEventCollectorSingleton.RegisterEventHandler(DummyHandler, true, false), "Handler was not registered despite Exists being true.");
            Assert.AreEqual(handlerCount + 1, DiagnosticEventCollectorSingleton.Instance.s_EventHandlers.Count, "DummyHandler was not properly assigned in s_EventHandlers.");
            Assert.AreEqual(true, DiagnosticEventCollectorSingleton.RegisterEventHandler(DummyHandler2, true, false), "Handler was not registered despite Exists being true");
            Assert.AreEqual(handlerCount + 2, DiagnosticEventCollectorSingleton.Instance.s_EventHandlers.Count, "DummyHandler2 was not properly assigned in s_EventHandlers.");

            //Remove each delegate
            Assert.AreEqual(false, DiagnosticEventCollectorSingleton.RegisterEventHandler(DummyHandler, false, false), "DummyHandler was not unregistered despite register being false.");
            Assert.AreEqual(handlerCount + 1, DiagnosticEventCollectorSingleton.Instance.s_EventHandlers.Count, "DummyHandler was not properly removed from s_EventHandlers.");
            Assert.AreEqual(false, DiagnosticEventCollectorSingleton.RegisterEventHandler(DummyHandler, false, false), "Registration occurred despite register being false.");
            Assert.AreEqual(handlerCount + 1, DiagnosticEventCollectorSingleton.Instance.s_EventHandlers.Count, "DummyHandler2 was removed when no removal should've occurred.");

            //cleanup
            DiagnosticEventCollectorSingleton.DestroySingleton();
        }