本文整理汇总了C#中IFoo.Baz方法的典型用法代码示例。如果您正苦于以下问题:C# IFoo.Baz方法的具体用法?C# IFoo.Baz怎么用?C# IFoo.Baz使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFoo
的用法示例。
在下文中一共展示了IFoo.Baz方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultipleCallbacks
public static void MultipleCallbacks(
IFoo fake,
bool firstWasCalled,
bool secondWasCalled,
int returnValue)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And I configure a method to invoke two actions and return a value"
.x(() =>
A.CallTo(() => fake.Baz())
.Invokes(x => firstWasCalled = true)
.Invokes(x => secondWasCalled = true)
.Returns(10));
"When I call the method"
.x(() => returnValue = fake.Baz());
"Then it calls the first callback"
.x(() => firstWasCalled.Should().BeTrue());
"And it calls the first callback"
.x(() => secondWasCalled.Should().BeTrue());
"And it returns the configured value"
.x(() => returnValue.Should().Be(10));
}
示例2: MultipleCallbacks
public static void MultipleCallbacks(
IFoo fake,
bool firstWasCalled,
bool secondWasCalled,
int returnValue)
{
"establish"
.x(() => fake = A.Fake<IFoo>());
"when configuring multiple callback"
.x(() =>
{
A.CallTo(() => fake.Baz())
.Invokes(x => firstWasCalled = true)
.Invokes(x => secondWasCalled = true)
.Returns(10);
returnValue = fake.Baz();
});
"it should call the first callback"
.x(() => firstWasCalled.Should().BeTrue());
"it should call the second callback"
.x(() => secondWasCalled.Should().BeTrue());
"it should return the configured value"
.x(() => returnValue.Should().Be(10));
}
示例3: MultipleReturns
public static void MultipleReturns(
IFoo fake,
IReturnValueArgumentValidationConfiguration<int> configuration,
Exception exception)
{
"establish"
.x(() => fake = A.Fake<IFoo>());
"when configuring multiple returns on the same configuration"
.x(() =>
{
configuration = A.CallTo(() => fake.Baz());
configuration.Returns(42);
exception = Record.Exception(() => configuration.Returns(0));
});
"it should throw an invalid operation exception"
.x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>());
}
示例4: MultipleReturns
public static void MultipleReturns(
IFoo fake,
IReturnValueArgumentValidationConfiguration<int> configuration,
Exception exception)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
"And I configure the return value for the method"
.x(() =>
{
configuration = A.CallTo(() => fake.Baz());
configuration.Returns(42);
});
"When I use the same configuration object to set the return value again"
.x(() => exception = Record.Exception(() => configuration.Returns(0)));
"Then it throws an invalid operation exception"
.x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>());
}
示例5: UnusedNonVoidCallSpec
public static void UnusedNonVoidCallSpec(
IFoo fake,
Exception exception)
{
"Given a strict fake"
.x(() => fake = A.Fake<IFoo>(o => o.Strict()));
"When I specify a call to a void method without configuring its behavior"
.x(() => A.CallTo(() => fake.Baz()));
"And I make a call to that method"
.x(() => exception = Record.Exception(() => fake.Baz()));
"Then it throws an expectation exception"
.x(() => exception.Should().BeAnExceptionOfType<ExpectationException>());
}
示例6: InvokesAfterStrictValueType
public static void InvokesAfterStrictValueType(
IFoo fake,
int result)
{
"Given a strict fake"
.x(() => fake = A.Fake<IFoo>(options => options.Strict()));
"And I configure a value type method to invoke an action"
.x(() => A.CallTo(() => fake.Baz()).Invokes(() => { }));
"When I call the method"
.x(() => result = fake.Baz());
"Then it returns a default instance of the value type"
.x(() => result.Should().Be(0));
}
示例7: DoesNothingAfterStrictValueType
public static void DoesNothingAfterStrictValueType(
IFoo fake,
int result)
{
"Given a strict fake"
.x(() => fake = A.Fake<IFoo>(options => options.Strict()));
"And I configure all methods to do nothing"
.x(() => A.CallTo(fake).DoesNothing());
"When I call a value type method"
.x(() => result = fake.Baz());
"Then it returns a default instance of the value type"
.x(() => result.Should().Be(0));
}
示例8: MultipleThrows
public static void MultipleThrows(
IFoo fake,
IReturnValueArgumentValidationConfiguration<int> configuration,
Exception exception)
{
"establish"
.x(() => fake = A.Fake<IFoo>());
"when configuring a return then a throw on the same configuration"
.x(() =>
{
configuration = A.CallTo(() => fake.Baz());
configuration.Throws(new ArgumentNullException());
exception = Record.Exception(() => configuration.Throws(new ArgumentException()));
});
"it should throw an InvalidOperationException"
.x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>());
}
示例9: ReturnThenCallsBaseMethod
public static void ReturnThenCallsBaseMethod(
IFoo fake,
IReturnValueArgumentValidationConfiguration<int> configuration,
Exception exception)
{
"establish"
.x(() => fake = A.Fake<IFoo>());
"when configuring a return then base method call on the same configuration"
.x(() =>
{
configuration = A.CallTo(() => fake.Baz());
configuration.Returns(42);
exception = Record.Exception(() => configuration.CallsBaseMethod());
});
"it should throw an InvalidOperationException"
.x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>());
}
示例10: NonVoidMethodWithReturns
public void NonVoidMethodWithReturns(
IFoo foo,
int result1,
int result2,
int result3)
{
"Given a fake"
.x(() => foo = A.Fake<IFoo>());
"When a non-void method is configured to return 1 once then return 2"
.x(() =>
A.CallTo(() => foo.Baz()).Returns(1).Once()
.Then.Returns(2));
"And the method is called 3 times"
.x(() =>
{
result1 = foo.Baz();
result2 = foo.Baz();
result3 = foo.Baz();
});
"Then the first call returns 1"
.x(() => result1.Should().Be(1));
"And the second call returns 2"
.x(() => result2.Should().Be(2));
"And the third call returns 2"
.x(() => result3.Should().Be(2));
}