Here are the examples of the csharp api FakeItEasy.A.CallTo(object, FakeItEasy.EventAction) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
525 Examples
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_1_argument_should_support_ref_parameter()
{
// Arrange
const string ReturnValue = "Result";
string argument = "argument";
string collectedArgument = null;
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfOneWithReference(ref argument)).ReturnsLazily((string s) =>
{
collectedArgument = s;
return ReturnValue;
});
// Act
var result = fake.RequestOfOneWithReference(ref argument);
// replacedert
result.Should().Be(ReturnValue);
collectedArgument.Should().Be(argument);
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_1_argument_should_throw_exception_when_argument_count_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfTwo(A<int>._, A<int>._))
.ReturnsLazily((int i) => { throw new InvalidOperationException("returns lazily action should not be executed"); });
Action act = () => fake.RequestOfTwo(5, 8);
// Act, replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32)", "(System.Int32)");
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_1_argument_should_throw_exception_when_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfOne(A<int>._))
.ReturnsLazily((string s) => { throw new InvalidOperationException("returns lazily action should not be executed"); });
Action act = () => fake.RequestOfOne(5);
// Act, replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32)", "(System.String)");
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_task_of_t_return_type_with_1_argument_should_support_func_of_t_valueProducer()
{
// Arrange
const int Argument1 = 2;
const int ReturnValue = 5;
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfOneTask(Argument1)).ReturnsLazily((int argument) => ReturnValue);
// Act
var result = fake.RequestOfOneTask(Argument1);
// replacedert
result.Result.Should().Be(ReturnValue);
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_2_arguments_should_use_returns_lazily_ReturnsLazily_with_action_having_2_arguments()
{
// Arrange
const int FirstArgument = 5;
const int SecondArgument = 8;
const int ReturnValue = 0;
int? firstCollectedArgument = null;
int? secondCollectedArgument = null;
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfTwo(A<int>._, A<int>._))
.ReturnsLazily((int i, int j) =>
{
firstCollectedArgument = i;
secondCollectedArgument = j;
return ReturnValue;
});
// Act
var result = fake.RequestOfTwo(FirstArgument, SecondArgument);
// replacedert
result.Should().Be(ReturnValue);
firstCollectedArgument.Should().HaveValue().And.Be(FirstArgument);
secondCollectedArgument.Should().HaveValue().And.Be(SecondArgument);
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_2_arguments_should_support_overloads()
{
// Arrange
const string FirstArgument = "first argument";
const string SecondArgument = "second argument";
const string ReturnValue = "Result";
string firstCollectedArgument = null;
string secondCollectedArgument = null;
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfTwo(A<string>._, A<string>._))
.ReturnsLazily((string s, string t) =>
{
firstCollectedArgument = s;
secondCollectedArgument = t;
return ReturnValue;
});
// Act
var result = fake.RequestOfTwo(FirstArgument, SecondArgument);
// replacedert
result.Should().Be(ReturnValue);
firstCollectedArgument.Should().Be(FirstArgument);
secondCollectedArgument.Should().Be(SecondArgument);
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_2_arguments_should_support_out_and_ref()
{
// Arrange
const string ReturnValue = "Result";
string firstArgument = "first argument";
string secondArgument = "second argument";
string firstCollectedArgument = null;
string secondCollectedArgument = null;
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfTwoWithOutputAndReference(out firstArgument, ref secondArgument))
.ReturnsLazily((string s, string t) =>
{
firstCollectedArgument = s;
secondCollectedArgument = t;
return ReturnValue;
});
// Act
var result = fake.RequestOfTwoWithOutputAndReference(out firstArgument, ref secondArgument);
// replacedert
result.Should().Be(ReturnValue);
firstCollectedArgument.Should().Be(firstArgument);
secondCollectedArgument.Should().Be(secondArgument);
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_2_arguments_should_throw_exception_when_argument_count_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfOne(A<int>._))
.ReturnsLazily((int i, int j) => { throw new InvalidOperationException("returns lazily action should not be executed"); });
Action act = () => fake.RequestOfOne(5);
// Act, replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32)", "(System.Int32, System.Int32)");
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_2_arguments_should_throw_exception_when_first_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfTwo(A<int>._, A<int>._))
.ReturnsLazily((string s, int i) => { throw new InvalidOperationException("returns lazily action should not be executed"); });
Action act = () => fake.RequestOfTwo(5, 8);
// Act, replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32)", "(System.String, System.Int32)");
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_2_arguments_should_throw_exception_when_second_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfTwo(A<int>._, A<int>._))
.ReturnsLazily((int i, string s) => { throw new InvalidOperationException("returns lazily action should not be executed"); });
Action act = () => fake.RequestOfTwo(5, 8);
// Act, replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32)", "(System.Int32, System.String)");
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_task_of_t_return_type_with_2_argument_should_support_func_of_t_valueProducer()
{
// Arrange
const int Argument1 = 1;
const int Argument2 = 2;
const int ReturnValue = 5;
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfTwoTask(Argument1, Argument2)).ReturnsLazily((int argument1, int argument2) => ReturnValue);
// Act
var result = fake.RequestOfTwoTask(Argument1, Argument2);
// replacedert
result.Result.Should().Be(ReturnValue);
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_3_arguments_should_use_returns_lazily_ReturnsLazily_with_action_having_3_arguments()
{
// Arrange
const int FirstArgument = 5;
const int SecondArgument = 8;
const int ThirdArgument = 13;
const int ReturnValue = 0;
int? firstCollectedArgument = null;
int? secondCollectedArgument = null;
int? thirdCollectedArgument = null;
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfThree(A<int>._, A<int>._, A<int>._))
.ReturnsLazily((int i, int j, int k) =>
{
firstCollectedArgument = i;
secondCollectedArgument = j;
thirdCollectedArgument = k;
return ReturnValue;
});
// Act
var result = fake.RequestOfThree(FirstArgument, SecondArgument, ThirdArgument);
// replacedert
result.Should().Be(ReturnValue);
firstCollectedArgument.Should().Be(FirstArgument);
secondCollectedArgument.Should().Be(SecondArgument);
thirdCollectedArgument.Should().Be(ThirdArgument);
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_3_arguments_should_support_overloads()
{
// Arrange
const string FirstArgument = "first argument";
const string SecondArgument = "second argument";
const string ThirdArgument = "third argument";
const string ReturnValue = "Result";
string firstCollectedArgument = null;
string secondCollectedArgument = null;
string thirdCollectedArgument = null;
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfThree(A<string>._, A<string>._, A<string>._))
.ReturnsLazily((string s, string t, string u) =>
{
firstCollectedArgument = s;
secondCollectedArgument = t;
thirdCollectedArgument = u;
return ReturnValue;
});
// Act
var result = fake.RequestOfThree(FirstArgument, SecondArgument, ThirdArgument);
// replacedert
result.Should().Be(ReturnValue);
firstCollectedArgument.Should().Be(FirstArgument);
secondCollectedArgument.Should().Be(SecondArgument);
thirdCollectedArgument.Should().Be(ThirdArgument);
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_3_arguments_should_support_out_and_ref()
{
// Arrange
string firstArgument = "first argument";
string secondArgument = "second argument";
const string ThirdArgument = "third argument";
const string ReturnValue = "Result";
string firstCollectedArgument = null;
string secondCollectedArgument = null;
string thirdCollectedArgument = null;
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfThreeWithOutputAndReference(out firstArgument, ref secondArgument, A<string>._))
.ReturnsLazily((string s, string t, string u) =>
{
firstCollectedArgument = s;
secondCollectedArgument = t;
thirdCollectedArgument = u;
return ReturnValue;
});
// Act
var result = fake.RequestOfThreeWithOutputAndReference(out firstArgument, ref secondArgument, ThirdArgument);
// replacedert
result.Should().Be(ReturnValue);
firstCollectedArgument.Should().Be(firstArgument);
secondCollectedArgument.Should().Be(secondArgument);
thirdCollectedArgument.Should().Be(ThirdArgument);
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_3_arguments_should_throw_exception_when_argument_count_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfTwo(A<int>._, A<int>._))
.ReturnsLazily((int i, int j, int k) => { throw new InvalidOperationException("returns lazily action should not be executed"); });
Action act = () => fake.RequestOfTwo(5, 8);
// Act, replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32)", "(System.Int32, System.Int32, System.Int32)");
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_3_arguments_should_throw_exception_when_first_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfThree(A<int>._, A<int>._, A<int>._))
.ReturnsLazily((string s, int i, int j) => { throw new InvalidOperationException("returns lazily action should not be executed"); });
Action act = () => fake.RequestOfThree(5, 8, 13);
// Act, replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32, System.Int32)", "(System.String, System.Int32, System.Int32)");
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_3_arguments_should_throw_exception_when_second_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfThree(A<int>._, A<int>._, A<int>._))
.ReturnsLazily((int i, string s, int j) => { throw new InvalidOperationException("returns lazily action should not be executed"); });
Action act = () => fake.RequestOfThree(5, 8, 13);
// Act, replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32, System.Int32)", "(System.Int32, System.String, System.Int32)");
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_3_arguments_should_throw_exception_when_third_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfThree(A<int>._, A<int>._, A<int>._))
.ReturnsLazily((int i, string s, int j) => { throw new InvalidOperationException("returns lazily action should not be executed"); });
Action act = () => fake.RequestOfThree(5, 8, 13);
// Act, replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32, System.Int32)", "(System.Int32, System.String, System.Int32)");
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_task_of_t_return_type_with_3_argument_should_support_func_of_t_valueProducer()
{
// Arrange
const int Argument1 = 1;
const int Argument2 = 2;
const int Argument3 = 3;
const int ReturnValue = 5;
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfThreeTask(Argument1, Argument2, Argument3)).ReturnsLazily((int argument1, int argument2, int argument3) => ReturnValue);
// Act
var result = fake.RequestOfThreeTask(Argument1, Argument2, Argument3);
// replacedert
result.Result.Should().Be(ReturnValue);
}
19
View Source File : ReturnValueConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void ReturnsLazily_with_4_arguments_should_throw_exception_when_first_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
A.CallTo(() => fake.RequestOfFour(A<int>._, A<int>._, A<int>._, A<int>._))
.ReturnsLazily((string s, int i, int j, int k) => { throw new InvalidOperationException("returns lazily action should not be executed"); });
Action act = () => fake.RequestOfFour(5, 8, 13, 21);
// Act, replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32, System.Int32, System.Int32)", "(System.String, System.Int32, System.Int32, System.Int32)");
}
19
View Source File : DefaultFakeObjectCreatorTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Should_throw_when_no_resolved_constructor_was_successfully_used()
{
// Arrange
var session = A.Fake<IDummyValueCreationSession>();
StubSessionToFailForType<int>(session);
StubSessionWithDummyValue(session, "dummy");
this.StubProxyGeneratorToFail("failed");
// Act
this.fakeObjectCreator.CreateFake(typeof(TypeWithMultipleConstructors), new ProxyOptions(), session, throwOnFailure: true);
// replacedert
var expectedConstructors = new[]
{
new ResolvedConstructor
{
Arguments = new[]
{
new ResolvedArgument
{
ArgumentType = typeof(int),
ResolvedValue = null,
WasResolved = false
},
new ResolvedArgument
{
ArgumentType = typeof(int),
ResolvedValue = null,
WasResolved = false
}
}
},
new ResolvedConstructor
{
ReasonForFailure = "failed",
Arguments = new[]
{
new ResolvedArgument
{
ArgumentType = typeof(string),
ResolvedValue = "dummy",
WasResolved = true
}
}
}
};
A.CallTo(() => this.thrower.ThrowFailedToGenerateProxyWithResolvedConstructors(typeof(TypeWithMultipleConstructors), "failed", this.ConstructorsEquivalentTo(expectedConstructors)))
.MustHaveHappened();
}
19
View Source File : DefaultFakeObjectCreatorTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
private static void StubSessionWithDummyValue<T>(IDummyValueCreationSession session, T dummyValue)
{
object outResult;
A.CallTo(() => session.TryResolveDummyValue(typeof(T), out outResult))
.Returns(true)
.replacedignsOutAndRefParameters(dummyValue);
}
19
View Source File : DefaultFakeObjectCreatorTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
private void StubProxyGeneratorToFail(string failReason)
{
A.CallTo(() => this.proxyGenerator.GenerateProxy(A<Type>._, A<IEnumerable<Type>>._, A<IEnumerable<object>>._, A<IEnumerable<Expression<Func<Attribute>>>>._, A<IFakeCallProcessorProvider>._))
.Returns(new ProxyGeneratorResult(failReason));
}
19
View Source File : ProxyGeneratorSelectorTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Should_delegate_calls_to_default_generator_asking_about_non_delegate_proxy()
{
// Arrange
var fake = new object();
var getHashCode = fake.GetType().GetMethod("GetHashCode");
string reason;
A.CallTo(() => this.defaultProxyGenerator.MethodCanBeInterceptedOnInstance(getHashCode, fake, out reason)).Returns(true).replacedignsOutAndRefParameters("reason");
// Act
string output;
var result = this.selector.MethodCanBeInterceptedOnInstance(getHashCode, fake, out output);
// replacedert
result.Should().BeTrue();
output.Should().Be("reason");
}
19
View Source File : ExpressionArgumentConstraintFactoryTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Should_get_aggregate_constraint_when_multiple_items_are_preplaceded_to_parameters_array()
{
// Arrange
var constraintForFirst = A.CollectionOfFake<IArgumentConstraint>(1);
var noConstraintForSecond = Enumerable.Empty<IArgumentConstraint>();
var constraintForThird = A.CollectionOfFake<IArgumentConstraint>(1);
A.CallTo(() => this.trapper.TrapConstraints(A<Action>._))
.ReturnsNextFromSequence(constraintForFirst, noConstraintForSecond, constraintForThird);
var expression = this.FromExpression(() => this.MethodWithParamArray(A<string>._, "foo", A<string>._));
// Act
var result = this.factory.GetArgumentConstraint(expression);
// replacedert
result.Should().BeOfType<AggregateArgumentConstraint>();
var aggregate = (AggregateArgumentConstraint)result;
aggregate.Constraints.Should().HaveCount(3);
aggregate.Constraints.ElementAt(0).Should().BeSameAs(constraintForFirst.Single());
aggregate.Constraints.ElementAt(1).Should().BeOfType<EqualityArgumentConstraint>().Which.ExpectedValue.Should().Be("foo");
aggregate.Constraints.ElementAt(2).Should().BeSameAs(constraintForThird.Single());
}
19
View Source File : ExpressionArgumentConstraintFactoryTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
private void StubTrapperToReturnNoConstraints()
{
A.CallTo(() => this.trapper.TrapConstraints(A<Action>._))
.Returns(Enumerable.Empty<IArgumentConstraint>());
}
19
View Source File : ExpressionCallMatcherTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
private void StubMethodInfoManagerToReturn(bool returnValue)
{
A.CallTo(() => this.methodInfoManager.WillInvokeSameMethodOnTarget(A<Type>._, A<MethodInfo>._, A<MethodInfo>._))
.Returns(returnValue);
}
19
View Source File : ExpressionCallRuleTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void IsApplicableTo_should_preplaced_call_to_call_matcher()
{
var call = ExpressionHelper.CreateFakeCall<IFoo>(x => x.Bar());
var rule = this.CreateRule();
rule.IsApplicableTo(call);
A.CallTo(() => this.callMatcher.Matches(call)).MustHaveHappened();
}
19
View Source File : ExpressionCallRuleTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Theory]
[InlineData(true)]
[InlineData(false)]
public void IsApplicableTo_should_return_result_from_call_matcher(bool callMatcherResult)
{
var call = ExpressionHelper.CreateFakeCall<IFoo>(x => x.Bar());
A.CallTo(() => this.callMatcher.Matches(call)).Returns(callMatcherResult);
var rule = this.CreateRule();
var result = rule.IsApplicableTo(call);
result.Should().Be(callMatcherResult);
}
19
View Source File : RecordingManagerTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void IsRecording_should_return_true_when_storage_returns_null_from_load()
{
// Arrange
A.CallTo(() => this.callStorage.Load()).Returns(null);
bool recorderIsRecording;
using (var recorder = this.CreateRecorder())
{
// Act
recorderIsRecording = recorder.IsRecording;
}
// replacedert
recorderIsRecording.Should().BeTrue();
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_should_support_omitting_arguments_when_they_are_not_used()
{
// Arrange
bool actionIsInvoked = false;
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.ActionOfOne(A<int>._))
.Invokes(() => actionIsInvoked = true);
// replacedert
fake.ActionOfOne(5);
actionIsInvoked.Should().BeTrue();
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_no_argument_should_use_invokes_with_action_having_no_arguments()
{
// Arrange
bool actionIsInvoked = false;
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.Action())
.Invokes(() => actionIsInvoked = true);
// replacedert
fake.Action();
actionIsInvoked.Should().BeTrue();
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_no_argument_and_no_returns_should_return_default_return_value()
{
// Arrange
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.Request())
.Invokes(() => { });
// replacedert
var result = fake.Request();
result.Should().Be(default(int));
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_no_argument_should_support_return_value()
{
// Arrange
const int ReturnValue = 0;
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.Request())
.Invokes(() => { })
.Returns(ReturnValue);
// replacedert
var result = fake.Request();
result.Should().Be(ReturnValue);
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_2_arguments_should_support_return_value()
{
// Arrange
const int ReturnValue = 0;
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.RequestOfTwo(A<int>._, A<int>._))
.Invokes((int i, int j) => { })
.Returns(ReturnValue);
// replacedert
var result = fake.RequestOfTwo(5, 8);
result.Should().Be(ReturnValue);
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_2_arguments_should_throw_exception_when_first_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.ActionOfTwo(A<int>._, A<int>._))
.Invokes((string s, int i) => { });
// replacedert
Action act = () => fake.ActionOfTwo(5, 8);
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32)", "(System.String, System.Int32)");
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_3_arguments_should_support_return_value()
{
// Arrange
const int ReturnValue = 0;
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.RequestOfThree(A<int>._, A<int>._, A<int>._))
.Invokes((int i, int j, int k) => { })
.Returns(ReturnValue);
// replacedert
var result = fake.RequestOfThree(5, 8, 13);
result.Should().Be(ReturnValue);
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_3_arguments_should_throw_exception_when_argument_count_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.ActionOfTwo(A<int>._, A<int>._))
.Invokes((int i, int j, int k) => { });
// replacedert
Action act = () => fake.ActionOfTwo(5, 8);
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32)", "(System.Int32, System.Int32, System.Int32)");
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_3_arguments_should_throw_exception_when_first_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.ActionOfThree(A<int>._, A<int>._, A<int>._))
.Invokes((string s, int i, int j) => { });
// replacedert
Action act = () => fake.ActionOfThree(5, 8, 13);
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32, System.Int32)", "(System.String, System.Int32, System.Int32)");
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_3_arguments_should_throw_exception_when_second_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.ActionOfThree(A<int>._, A<int>._, A<int>._))
.Invokes((int i, string s, int j) => { });
// replacedert
Action act = () => fake.ActionOfThree(5, 8, 13);
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32, System.Int32)", "(System.Int32, System.String, System.Int32)");
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_3_arguments_should_throw_exception_when_third_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.ActionOfThree(A<int>._, A<int>._, A<int>._))
.Invokes((int i, int j, string s) => { });
// replacedert
Action act = () => fake.ActionOfThree(5, 8, 13);
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32, System.Int32)", "(System.Int32, System.Int32, System.String)");
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_4_arguments_should_use_invokes_with_action_having_4_arguments()
{
// Arrange
const int FirstArgument = 5;
const int SecondArgument = 8;
const int ThirdArgument = 13;
const int FourthArgument = 21;
bool actionIsInvoked = false;
int? firstCollectedArgument = null;
int? secondCollectedArgument = null;
int? thirdCollectedArgument = null;
int? fourthCollectedArgument = null;
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.ActionOfFour(A<int>._, A<int>._, A<int>._, A<int>._))
.Invokes((int i, int j, int k, int l) =>
{
actionIsInvoked = true;
firstCollectedArgument = i;
secondCollectedArgument = j;
thirdCollectedArgument = k;
fourthCollectedArgument = l;
});
// replacedert
fake.ActionOfFour(FirstArgument, SecondArgument, ThirdArgument, FourthArgument);
actionIsInvoked.Should().BeTrue();
firstCollectedArgument.Should().Be(FirstArgument);
secondCollectedArgument.Should().Be(SecondArgument);
thirdCollectedArgument.Should().Be(ThirdArgument);
fourthCollectedArgument.Should().Be(FourthArgument);
}
19
View Source File : CallbackConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Invokes_with_4_arguments_should_support_return_value()
{
// Arrange
const int ReturnValue = 0;
var fake = A.Fake<IInterface>();
// Act
A.CallTo(() => fake.RequestOfFour(A<int>._, A<int>._, A<int>._, A<int>._))
.Invokes((int i, int j, int k, int l) => { })
.Returns(ReturnValue);
// replacedert
var result = fake.RequestOfFour(5, 8, 13, 21);
result.Should().Be(ReturnValue);
}
19
View Source File : ExceptionThrowerConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Throws_with_2_arguments_should_throw_exception_and_provide_arguments_for_consumption()
{
// Arrange
const int FirstArgument = 2;
const int SecondArgument = 5;
int? firstCollectedArgument = null;
int? secondCollectedArgument = null;
var exceptionToThrow = new InvalidOperationException();
var fake = A.Fake<IInterface>();
Action act = () => fake.ActionOfTwo(FirstArgument, SecondArgument);
// Act
A.CallTo(() => fake.ActionOfTwo(FirstArgument, SecondArgument)).Throws((int i, int j) =>
{
firstCollectedArgument = i;
secondCollectedArgument = j;
return exceptionToThrow;
});
// replacedert
var thrownException = Record.Exception(act);
thrownException.Should().Be(exceptionToThrow);
firstCollectedArgument.Should().Be(FirstArgument);
secondCollectedArgument.Should().Be(SecondArgument);
}
19
View Source File : ExceptionThrowerConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Throws_with_2_arguments_should_throw_fake_configuration_exception_when_argument_count_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
Action act = () => fake.ActionOfOne(5);
// Act
A.CallTo(() => fake.ActionOfOne(A<int>._))
.Throws((int i, int j) => { throw new InvalidOperationException("throws action should not be executed"); });
// replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32)", "(System.Int32, System.Int32)");
}
19
View Source File : ExceptionThrowerConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Throws_with_2_arguments_should_throw_fake_configuration_exception_when_first_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
Action act = () => fake.ActionOfTwo(5, 8);
// Act
A.CallTo(() => fake.ActionOfTwo(A<int>._, A<int>._))
.Throws((string s, int i) => { throw new InvalidOperationException("throws action should not be executed"); });
// replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32)", "(System.String, System.Int32)");
}
19
View Source File : ExceptionThrowerConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Throws_with_2_arguments_should_throw_fake_configuration_exception_when_second_argument_type_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
Action act = () => fake.ActionOfTwo(5, 8);
// Act
A.CallTo(() => fake.ActionOfTwo(A<int>._, A<int>._))
.Throws((int i, string s) => { throw new InvalidOperationException("throws action should not be executed"); });
// replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32)", "(System.Int32, System.String)");
}
19
View Source File : ExceptionThrowerConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Throws_with_3_arguments_should_throw_fake_configuration_exception_when_argument_count_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
Action act = () => fake.ActionOfTwo(5, 8);
// Act
A.CallTo(() => fake.ActionOfTwo(A<int>._, A<int>._))
.Throws((int i, int j, int k) => { throw new InvalidOperationException("throws action should not be executed"); });
// replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32)", "(System.Int32, System.Int32, System.Int32)");
}
19
View Source File : ExceptionThrowerConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Throws_with_4_arguments_should_throw_exception_and_provide_arguments_for_consumption()
{
// Arrange
const int FirstArgument = 2;
const int SecondArgument = 5;
const int ThirdArgument = 8;
const int FourthArgument = 13;
int? firstCollectedArgument = null;
int? secondCollectedArgument = null;
int? thirdCollectedArgument = null;
int? fourthCollectedArgument = null;
var exceptionToThrow = new InvalidOperationException();
var fake = A.Fake<IInterface>();
Action act = () => fake.ActionOfFour(FirstArgument, SecondArgument, ThirdArgument, FourthArgument);
// Act
A.CallTo(() => fake.ActionOfFour(FirstArgument, SecondArgument, ThirdArgument, FourthArgument))
.Throws((int i, int j, int k, int l) =>
{
firstCollectedArgument = i;
secondCollectedArgument = j;
thirdCollectedArgument = k;
fourthCollectedArgument = l;
return exceptionToThrow;
});
// replacedert
var thrownException = Record.Exception(act);
thrownException.Should().Be(exceptionToThrow);
firstCollectedArgument.Should().Be(FirstArgument);
secondCollectedArgument.Should().Be(SecondArgument);
thirdCollectedArgument.Should().Be(ThirdArgument);
fourthCollectedArgument.Should().Be(FourthArgument);
}
19
View Source File : ExceptionThrowerConfigurationExtensionsTests.cs
License : MIT License
Project Creator : DynamicsValue
License : MIT License
Project Creator : DynamicsValue
[Fact]
public void Throws_with_4_arguments_should_throw_fake_configuration_exception_when_argument_count_does_not_match()
{
// Arrange
var fake = A.Fake<IInterface>();
Action act = () => fake.ActionOfThree(5, 8, 13);
// Act
A.CallTo(() => fake.ActionOfThree(A<int>._, A<int>._, A<int>._))
.Throws((int i, int j, int k, int l) => { throw new InvalidOperationException("throws action should not be executed"); });
// replacedert
replacedertThatSignatureMismatchExceptionIsThrown(act, "(System.Int32, System.Int32, System.Int32)", "(System.Int32, System.Int32, System.Int32, System.Int32)");
}
See More Examples