protected void ToSnapshot <T>(IAfterExecutionResult result) where T : class { var returnValue = result.ReturnValue as T; var asJson = JsonConvert.SerializeObject(returnValue, Formatting.Indented); Snapshots.Add($"{result.Rule.MethodName}", asJson); }
protected void AssertReturnValue(string forMethod, bool hasReturnValue, IAfterExecutionResult inResult) { _originalImplementation.Message.Should().Be($"Invoked: {forMethod}", because: "the method should have been invoked before the callback. "); inResult.Should().NotBeNull(because: "the callback should have been invoked with the return value result. "); using (var scope = new AssertionScope()) { inResult.HasReturnValue.Should().Be(hasReturnValue, because: "a void method has no return value. "); } inResult.Rule.Should().NotBeNull(because: "the intercept rule should always be passed to the callback. "); inResult.Rule.MethodName.Should().Be(forMethod); }
protected void AssertReturnValueIsVoid(string forMethod, IAfterExecutionResult inResult) { AssertReturnValue(forMethod, false, inResult); inResult.ReturnValue.Should().BeNull(because: "by design, we ensure that a void method will return null; use HasReturnValue as a discriminator. "); }
protected void AssertReturnValue(string forMethod, int isValue, IAfterExecutionResult inResult) { AssertReturnValue(forMethod, hasReturnValue: true, inResult); inResult.ReturnValue.Should().Be(isValue, because: "that is the hard coded value returned from the method. "); }