本文整理汇总了C#中IFoo.Bar方法的典型用法代码示例。如果您正苦于以下问题:C# IFoo.Bar方法的具体用法?C# IFoo.Bar怎么用?C# IFoo.Bar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFoo
的用法示例。
在下文中一共展示了IFoo.Bar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VoidMethodWithInvokes
public void VoidMethodWithInvokes(
IFoo foo,
Action action1,
Action action2)
{
"Given a fake"
.x(() => foo = A.Fake<IFoo>());
"And two delegates"
.x(() =>
{
action1 = A.Fake<Action>();
action2 = A.Fake<Action>();
});
"When a void method is configured to invoke a delegate once then invoke another delegate"
.x(() =>
A.CallTo(() => foo.Bar()).Invokes(action1).DoesNothing().Once()
.Then.Invokes(action2));
"And the method is called 3 times"
.x(() =>
{
foo.Bar();
foo.Bar();
foo.Bar();
});
"Then the first delegate is invoked once, and the second delegate is invoked twice"
.x(() => A.CallTo(() => action1()).MustHaveHappened(Repeated.Exactly.Once)
.Then(A.CallTo(() => action2()).MustHaveHappened(Repeated.Exactly.Twice)));
}
示例2: VoidMethodWithThrows
public void VoidMethodWithThrows(
IFoo foo,
Action action,
Exception exception)
{
"Given a fake"
.x(() => foo = A.Fake<IFoo>());
"And an action"
.x(() => action = A.Fake<Action>());
"When a void method is configured to invoke a delegate twice then throw an exception"
.x(() =>
A.CallTo(() => foo.Bar()).Invokes(action).DoesNothing().Twice()
.Then.Throws<InvalidOperationException>());
"And the method is called 3 times"
.x(() =>
{
foo.Bar();
foo.Bar();
exception = Record.Exception(() => foo.Bar());
});
"Then the delegate is invoked twice"
.x(() => A.CallTo(() => action()).MustHaveHappened(Repeated.Exactly.Twice));
"And the third call throws an exception"
.x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>());
}
示例3: WithNonVoidReturnType
public static void WithNonVoidReturnType(IFoo fake)
{
"Given a fake with a generic method"
.x(() => fake = A.Fake<IFoo>());
"When the fake's generic method is configured to return null for any non-void return type"
.x(() => A.CallTo(fake).Where(call => call.Method.Name == "Bar").WithNonVoidReturnType().Returns(null));
"Then the configured method returns null when called with generic argument String"
.x(() => fake.Bar<string>().Should().BeNull());
"And the configured method returns null when called with generic argument IFoo"
.x(() => fake.Bar<IFoo>().Should().BeNull());
}
示例4: WithReturnType
public static void WithReturnType(
IFoo fake,
string returnValue)
{
"Given a fake with a generic method"
.x(() => fake = A.Fake<IFoo>());
"When the fake's generic method is configured to return a specific value for a given return type"
.x(() => A.CallTo(fake).Where(call => call.Method.Name == "Bar").WithReturnType<string>().Returns(returnValue = "hello world"));
"Then the configured method returns the specified value when called with generic argument String"
.x(() => fake.Bar<string>().Should().Be(returnValue));
"And the configured method returns a dummy when called with generic argument IFoo"
.x(() => fake.Bar<IFoo>().Should().NotBeNull().And.BeAssignableTo<IFoo>());
}
示例5: Callback
public static void Callback(
IFoo fake,
bool wasCalled)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And I configure a method to invoke an action"
.x(() => A.CallTo(() => fake.Bar()).Invokes(x => wasCalled = true));
"When I call the method"
.x(() => fake.Bar());
"Then it invokes the action"
.x(() => wasCalled.Should().BeTrue());
}
示例6: Callback
public static void Callback(
IFoo fake,
bool wasCalled)
{
"establish"
.x(() => fake = A.Fake<IFoo>());
"when configuring callback"
.x(() =>
{
A.CallTo(() => fake.Bar()).Invokes(x => wasCalled = true);
fake.Bar();
});
"it should invoke the callback"
.x(() => wasCalled.Should().BeTrue());
}
示例7: MultistepOrderedAssertionsInOrder
public static void MultistepOrderedAssertionsInOrder(
IFoo fake,
Exception exception,
IOrderableCallAssertion lastAssertion)
{
"Given a Fake"
.x(() => fake = A.Fake<IFoo>());
"And a call on the Fake, passing argument 1"
.x(() => fake.Bar(1));
"And a call on the Fake, passing argument 2"
.x(() => fake.Bar(2));
"And a call on the Fake, passing argument 2"
.x(() => fake.Bar(2));
"And a call on the Fake, passing argument 3"
.x(() => fake.Bar(3));
"When I assert that a call with argument 1 was made exactly once"
.x(() => lastAssertion = A.CallTo(() => fake.Bar(1)).MustHaveHappened(Repeated.Exactly.Once));
"And then a call with argument 2"
.x(() => lastAssertion = lastAssertion.Then(A.CallTo(() => fake.Bar(2)).MustHaveHappened()));
"And then a call with argument 3 exactly once"
.x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => fake.Bar(3)).MustHaveHappened(Repeated.Exactly.Once))));
"Then the assertions should pass"
.x(() => exception.Should().BeNull());
}
示例8: NonCanceledTokenWithConfiguredCall
public void NonCanceledTokenWithConfiguredCall(
IFoo fake,
CancellationToken cancellationToken,
int result)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And a call configured on that fake"
.x(() => A.CallTo(() => fake.Bar(A<CancellationToken>._)).Returns(42));
"And a cancellation token that is not canceled"
.x(() => cancellationToken = new CancellationToken(false));
"When the configured method is called with this cancellation token"
.x(() => result = fake.Bar(cancellationToken));
"Then it doesn't throw and returns the configured value"
.x(() => result.Should().Be(42));
}
示例9: CanceledToken
public void CanceledToken(
IFoo fake,
CancellationToken cancellationToken,
Exception exception)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And a cancellation token that is canceled"
.x(() => cancellationToken = new CancellationToken(true));
"When a method is called with this cancellation token"
.x(() => exception = Record.Exception(() => fake.Bar(cancellationToken)));
"Then it throws an OperationCanceledException"
.x(() => exception.Should().BeAnExceptionAssignableTo<OperationCanceledException>());
}
示例10: NonCanceledToken
public void NonCanceledToken(
IFoo fake,
CancellationToken cancellationToken,
int result)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And a cancellation token that is not canceled"
.x(() => cancellationToken = new CancellationToken(false));
"When a method is called with this cancellation token"
.x(() => result = fake.Bar(cancellationToken));
"Then it doesn't throw and returns the default value"
.x(() => result.Should().Be(0));
}
示例11: InvokesAfterStrictVoid
public static void InvokesAfterStrictVoid(
IFoo fake,
Exception exception)
{
"Given a strict fake"
.x(() => fake = A.Fake<IFoo>(options => options.Strict()));
"And I configure a void method to invoke an action"
.x(() => A.CallTo(() => fake.Bar()).Invokes(() => { }));
"When I call the method"
.x(() => exception = Record.Exception(() => fake.Bar()));
"Then it does not throw an exception"
.x(() => exception.Should().BeNull());
}
示例12: DoesNothingAndThrowsAppliedToSameACallTo
public static void DoesNothingAndThrowsAppliedToSameACallTo(
IFoo fake,
IVoidArgumentValidationConfiguration callToBar,
Exception exception)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And I identify a method to configure"
.x(() => callToBar = A.CallTo(() => fake.Bar()));
"And I configure the method to do nothing"
.x(() => callToBar.DoesNothing());
"When I configure the method to throw an exception"
.x(() => exception = Record.Exception(() => callToBar.Throws<Exception>()));
"Then it throws an invalid operation exception"
.x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>());
}
示例13: OrderedAssertionsOnDifferentObjectsInOrder
public static void OrderedAssertionsOnDifferentObjectsInOrder(IFoo fake1, IFoo fake2, Exception exception)
{
"Given a Fake"
.x(() => fake1 = A.Fake<IFoo>());
"And another Fake of the same type"
.x(() => fake2 = A.Fake<IFoo>());
"And a call on the first Fake, passing argument 1"
.x(() => fake1.Bar(1));
"And a call on the second Fake, passing argument 1"
.x(() => fake2.Bar(1));
"And a call on the first Fake, passing argument 2"
.x(() => fake1.Bar(2));
"When I assert that a call with argument 1 was made on the first Fake, then on the second, and then that a call with argument 2 was made on the first Fake"
.x(() => exception = Record.Exception(() =>
A.CallTo(() => fake1.Bar(1)).MustHaveHappened()
.Then(A.CallTo(() => fake2.Bar(1)).MustHaveHappened())
.Then(A.CallTo(() => fake1.Bar(2)).MustHaveHappened())));
"Then the assertion should pass"
.x(() => exception.Should().BeNull());
}
示例14: Configure
public void Configure(IApplicationBuilder app, IFoo foo)
{
foo.Bar();
}
示例15: Do
public void Do(IFoo foo)
{
foo.Bar();
}