public IEnumerator AssertIgnore_DoesNotCauseTestFailure()
 {
     using (var executor = new UnityTestInstructionExecutor())
     {
         yield return(Responsibly
                      .Do("Assert.Ignore", () => Assert.Ignore("Should not fail"))
                      .ToYieldInstruction(executor));
     }
 }
 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 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 StateString_TruncatesExceptionAt100Chars()
        {
            var message = new string('x', 99) + "^~";
            var state   = Responsibly.Do(
                "Fail",
                () => throw new Exception(message))
                          .CreateState();

            state.ToTask(this.Executor);             // Complete task

            var stateString = state.ToString();

            StateAssert.StringContainsInOrder(stateString)
            .Failed("Fail")
            .Details(@"xxxxxxx\^")
            .Nowhere("~");
        }
        public void StateString_ContainsOnlyFirstLineOfException_WhenMultiline()
        {
            var firstLine  = "First line";
            var secondLine = "Second line";
            var state      = Responsibly.Do(
                "Fail",
                () => throw new Exception($"{firstLine}\n{secondLine}"))
                             .CreateState();

            state.ToTask(this.Executor);             // Complete task

            var stateString = state.ToString();

            StateAssert.StringContainsInOrder(stateString)
            .Failed("Fail")
            .Details(firstLine)
            .Nowhere(secondLine);
        }