public IEnumerator BugFarmScene_MultipleSentryInit_SendEventForTheLatest()
        {
            yield return(SetupSceneCoroutine("1_BugFarm"));

            // We should use the sample Dsn for the nextDsn
            // to avoid static dsn.
            var options = AssetDatabase.LoadAssetAtPath(ScriptableSentryUnityOptions.GetConfigPath(ScriptableSentryUnityOptions.ConfigName),
                                                        typeof(ScriptableSentryUnityOptions)) as ScriptableSentryUnityOptions;

            var sourceEventCapture = new TestEventCapture();
            var sourceDsn          = "https://[email protected]/5439417";

            using var firstDisposable = InitSentrySdk(o =>
            {
                o.Dsn = sourceDsn;
                o.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: sourceEventCapture));
            });

            var nextEventCapture = new TestEventCapture();
            var nextDsn          = options?.Dsn;

            using var secondDisposable = InitSentrySdk(o =>
            {
                o.Dsn = nextDsn;
                o.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: nextEventCapture));
            });
            var testBehaviour = new GameObject("TestHolder").AddComponent <TestMonoBehaviour>();

            testBehaviour.gameObject.SendMessage(nameof(testBehaviour.TestException));

            Assert.NotNull(nextDsn);
            Assert.AreEqual(0, sourceEventCapture.Events.Count, sourceDsn);
            Assert.AreEqual(1, nextEventCapture.Events.Count);
        }
Exemple #2
0
        private static TestEventCapture CreateAndSetupSentryTestService()
        {
            var testEventCapture = new TestEventCapture();

            SentryInitialization.EventCapture = testEventCapture;
            return(testEventCapture);
        }
        public IEnumerator BugFarmScene_EventCaptured_UserNameIsNotEnvironmentUserNameByDefault()
        {
            yield return(SetupSceneCoroutine("1_BugFarm"));

            var testEventCapture = new TestEventCapture();

            using var _ = InitSentrySdk(o =>
            {
                o.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: testEventCapture));
            });
            var testBehaviour = new GameObject("TestHolder").AddComponent <TestMonoBehaviour>();

            testBehaviour.gameObject.SendMessage(nameof(testBehaviour.TestException));

            // assert
            Assert.AreNotEqual(Environment.UserName, testEventCapture.Events.First().User.Username);
        }
        public IEnumerator BugFarmScene_EventCaptured_IncludesApplicationProductNameAtVersionAsRelease()
        {
            yield return(SetupSceneCoroutine("1_BugFarm"));

            // arrange
            var testEventCapture = new TestEventCapture();

            using var _ = InitSentrySdk(o =>
            {
                o.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: testEventCapture));
            });
            var testBehaviour = new GameObject("TestHolder").AddComponent <TestMonoBehaviour>();

            testBehaviour.gameObject.SendMessage(nameof(testBehaviour.TestException));

            // assert
            Assert.AreEqual(Application.productName + "@" + Application.version, testEventCapture.Events.First().Release);
        }
        public IEnumerator BugFarmScene_DebugLogException_IsMarkedUnhandled()
        {
            yield return(SetupSceneCoroutine("1_BugFarm"));

            // arrange
            var testEventCapture = new TestEventCapture();

            using var _ = InitSentrySdk(o =>
            {
                o.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: testEventCapture));
            });
            var testBehaviour = new GameObject("TestHolder").AddComponent <TestMonoBehaviour>();

            // act
            testBehaviour.gameObject.SendMessage(nameof(testBehaviour.DebugLogException));

            // assert
            Assert.NotNull(testEventCapture.Events.SingleOrDefault(sentryEvent =>
                                                                   sentryEvent.SentryExceptions.SingleOrDefault(exception =>
                                                                                                                exception.Mechanism?.Handled is false) is not null));
        }
        public IEnumerator BugFarmScene_EventCaptured_IncludesApplicationInEditorOrProduction()
        {
            yield return(SetupSceneCoroutine("1_BugFarm"));

            // arrange
            var testEventCapture = new TestEventCapture();

            using var _ = InitSentrySdk(o =>
            {
                o.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: testEventCapture));
            });
            var testBehaviour = new GameObject("TestHolder").AddComponent <TestMonoBehaviour>();

            testBehaviour.gameObject.SendMessage(nameof(testBehaviour.TestException));

            var actual = testEventCapture.Events.First();

            Assert.AreEqual(Application.isEditor
                ? "editor"
                : "production",
                            actual.Environment);
        }
        public IEnumerator BugFarmScene_ObjectCreatedWithExceptionLogicAndCalled_OneEventIsCreated()
        {
            yield return(SetupSceneCoroutine("1_BugFarm"));

            // arrange
            var testEventCapture = new TestEventCapture();

            using var _ = InitSentrySdk(o =>
            {
                o.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: testEventCapture));
            });
            var testBehaviour = new GameObject("TestHolder").AddComponent <TestMonoBehaviour>();

            // act

            /*
             * We don't want to call testBehaviour.TestException(); because it won't go via Sentry infra.
             * We don't have it in tests, but in scenes.
             */
            testBehaviour.gameObject.SendMessage(nameof(testBehaviour.TestException));

            // assert
            Assert.AreEqual(1, testEventCapture.Events.Count);
        }