public IEnumerator Polling_HappensOncePerFrame()
        {
            using (var executor = new UnityTestInstructionExecutor(logErrors: false))
            {
                var pollCount = 0;

                Responsibly
                .WaitForCondition("Never", () =>
                {
                    ++pollCount;
                    return(false);
                })
                .ExpectWithinSeconds(1)
                .ToYieldInstruction(executor);

                Assert.AreEqual(1, pollCount, "Should poll once synchronously");

                yield return(null);

                Assert.AreEqual(2, pollCount, "Should poll once per frame");

                yield return(null);

                Assert.AreEqual(3, pollCount, "Should poll once per frame");
            }
        }
 public IEnumerator AssertIgnore_DoesNotCauseTestFailure()
 {
     using (var executor = new UnityTestInstructionExecutor())
     {
         yield return(Responsibly
                      .Do("Assert.Ignore", () => Assert.Ignore("Should not fail"))
                      .ToYieldInstruction(executor));
     }
 }
Example #3
0
        public IEnumerator SetUp()
        {
            this.TestInstructionExecutor = new UnityTestInstructionExecutor();
            this.mockInput       = new MockInput();
            PlayerInput.Instance = this.mockInput;

            yield return(EditorSceneManager.LoadSceneAsyncInPlayMode(
                             this.scenePath,
                             new LoadSceneParameters(LoadSceneMode.Additive)));
        }
 public void Errors_AreNotLogged_WhenLogErrorsIsFalse()
 {
     using (var executor = new UnityTestInstructionExecutor(logErrors: false))
     {
         var instruction = Responsibly
                           .Do("Throw exception", () => throw new Exception())
                           .ToYieldInstruction(executor, throwOnError: false);
         Assert.IsTrue(instruction.CompletedWithError);
         // Should not fail the test with logged errors
     }
 }
 public void Errors_AreLogged_WhenLogErrorsIsTrue()
 {
     using (var executor = new UnityTestInstructionExecutor(logErrors: true))
     {
         var message = "Should be in log";
         Responsibly
         .Do("Throw exception", () => throw new Exception(message))
         .ToYieldInstruction(executor, throwOnError: false);                         // Should complete synchronously
         LogAssert.Expect(LogType.Error, new Regex(message));
     }
 }
        public void UnhandledErrorLog_IsLoggedAsWarning_WhenLogErrorsIsTrue()
        {
            using (var executor = new UnityTestInstructionExecutor(logErrors: true))
            {
                var expected = "expected message";
                Responsibly
                .Do("Throw exception", () => Debug.LogError(expected))
                .ToYieldInstruction(executor, throwOnError: false);                     // Should complete synchronously

                LogAssert.Expect(LogType.Warning, new Regex(expected));                 // The one from us
            }
        }
        public void LoggingError_CausesFailureSynchronously()
        {
            using (var executor = new UnityTestInstructionExecutor(logErrors: false))
            {
                var yieldInstruction = Responsibly
                                       .WaitForCondition("Never", () => false)
                                       .ExpectWithinSeconds(1)
                                       .ToYieldInstruction(executor);

                Debug.LogError("Should fail the instruction");

                Assert.IsTrue(yieldInstruction.CompletedWithError);
            }
        }
        public void GlobalContext_IsIncludedInErrors()
        {
            var globalContextProvider = Substitute.For <IGlobalContextProvider>();

            globalContextProvider.BuildGlobalContext(Arg.Do(
                                                         (StateStringBuilder builder) => builder.AddDetails("Global details")));
            using (var executor = new UnityTestInstructionExecutor(globalContextProvider: globalContextProvider))
            {
                Responsibly
                .Do("Throw exception", () => throw new Exception())
                .ToYieldInstruction(executor, throwOnError: false);                         // Should complete synchronously
                LogAssert.Expect(LogType.Error, new Regex("Global details"));
            }
        }
        public void LoggingError_DoesNotFail_WhenUsingExpectLog()
        {
            using (var executor = new UnityTestInstructionExecutor(logErrors: false))
            {
                var yieldInstruction = Responsibly
                                       .WaitForCondition("Never", () => false)
                                       .ExpectWithinSeconds(1)
                                       .ToYieldInstruction(executor);

                var message = "Should not fail the instruction";
                executor.ExpectLog(LogType.Error, new Regex(message));
                Debug.LogError(message);

                Assert.IsFalse(yieldInstruction.WasCanceled);
                Assert.IsFalse(yieldInstruction.CompletedSuccessfully);
                Assert.IsFalse(yieldInstruction.CompletedWithError);
            }
        }
        public IEnumerator Polling_IsStopped_WhenDisposed()
        {
            var pollCount = 0;

            using (var executor = new UnityTestInstructionExecutor(logErrors: false))
            {
                Responsibly
                .WaitForCondition("Never", () =>
                {
                    ++pollCount;
                    return(false);
                })
                .ExpectWithinSeconds(1)
                .ToYieldInstruction(executor);
            }

            Assert.AreEqual(1, pollCount, "Should poll once synchronously");

            yield return(null);

            Assert.AreEqual(1, pollCount, "Should not poll after being disposed");
        }