本文整理汇总了C#中MockContext.Arrange方法的典型用法代码示例。如果您正苦于以下问题:C# MockContext.Arrange方法的具体用法?C# MockContext.Arrange怎么用?C# MockContext.Arrange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockContext
的用法示例。
在下文中一共展示了MockContext.Arrange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Arrange_CallBackFourArguments_InvokesCallback
public void Arrange_CallBackFourArguments_InvokesCallback()
{
var mockContext = new MockContext<IFoo>();
var fooMock = new FooMock(mockContext);
int firstResult = 0;
int secondResult = 0;
int thirdResult = 0;
int fourthResult = 0;
mockContext.Arrange(
f => f.Execute(The<int>.IsAnyValue, The<int>.IsAnyValue, The<int>.IsAnyValue, The<int>.IsAnyValue))
.Callback<int, int, int, int>(
(i1, i2, i3, i4) =>
{
firstResult = i1;
secondResult = i2;
thirdResult = i3;
fourthResult = i4;
});
fooMock.Execute(1, 2, 3, 4);
Assert.AreEqual(1, firstResult);
Assert.AreEqual(2, secondResult);
Assert.AreEqual(3, thirdResult);
Assert.AreEqual(4, fourthResult);
}
示例2: Arrange_CallBackOneArgument_InvokesCallback
public void Arrange_CallBackOneArgument_InvokesCallback()
{
var mockContext = new MockContext<IFoo>();
var fooMock = new FooMock(mockContext);
int callBackResult = 0;
mockContext.Arrange(f => f.Execute(The<int>.IsAnyValue)).Callback<int>(s => callBackResult = s);
fooMock.Execute(1);
Assert.AreEqual(1, callBackResult);
}
示例3: Arrange_CallBackNoArguments_InvokesCallback
public void Arrange_CallBackNoArguments_InvokesCallback()
{
var mockContext = new MockContext<IFoo>();
var fooMock = new FooMock(mockContext);
bool isCalled = false;
mockContext.Arrange(f => f.Execute()).Callback(() => isCalled = true);
fooMock.Execute();
Assert.IsTrue(isCalled);
}
示例4: Cloud_auth_object_returns_project_id
public void Cloud_auth_object_returns_project_id()
{
var mockContext = new MockContext<CloudAuthenticator>();
mockContext.Arrange(f => f.GetProjectId()).Returns("ProjectId");
var cloudAuthMock = new CloudAuthenticatorMock(mockContext);
var result = cloudAuthMock.GetProjectId();
mockContext.Assert(f => f.GetProjectId(), Invoked.Once);
Assert.Equal("ProjectId", result);
}
示例5: Cloud_auth_object_returns_initializer
public void Cloud_auth_object_returns_initializer()
{
var initializer = new BaseClientService.Initializer();
var mockContext = new MockContext<CloudAuthenticator>();
mockContext.Arrange(f => f.GetInitializer()).Returns(initializer);
var cloudAuthMock = new CloudAuthenticatorMock(mockContext);
var result = cloudAuthMock.GetInitializer();
mockContext.Assert(f => f.GetInitializer(), Invoked.Once);
Assert.Equal(initializer, result);
}
示例6: MessageControllerTest
public MessageControllerTest(ITestOutputHelper output)
{
this.output = output;
lookupRepo = new FakeLookupRepository();
logger = new DivineLogger<FakeDataStore>(new FakeDataStore());
cache = new MemoryCache(new MemoryCacheOptions());
msgService = new FakeCommunicationService();
var mockContext = new MockContext<IRepository<Member>>();
membersRepo = new FakeMemberRepository(mockContext);
var repositories = new DivineRepositories(attendanceRepo, lookupRepo, membersRepo, msgRepo);
//divineBot = new TextDivineBot(repositories, msgService);
mockContext.Arrange(x => (x.GetAllAsync())).Returns(Task.FromResult(membersList.AsQueryable()));
messageCtrl = new MessageController(repositories, msgService, cache, logger, null);
}
示例7: Arrange_CallBackTwoArguments_InvokesCallback
public void Arrange_CallBackTwoArguments_InvokesCallback()
{
var mockContext = new MockContext<IFoo>();
var fooMock = new FooMock(mockContext);
int firstResult = 0;
int secondResult = 0;
mockContext.Arrange(f => f.Execute(The<int>.IsAnyValue, The<int>.IsAnyValue)).Callback<int, int>(
(i, i1) =>
{
firstResult = i;
secondResult = i1;
});
fooMock.Execute(1, 2);
Assert.AreEqual(1, firstResult);
Assert.AreEqual(2, secondResult);
}
示例8: Get_ReturnsBadRequest
public async Task Get_ReturnsBadRequest()
{
//Arrange
var mockContext = new MockContext<IRepository<Member>>();
membersRepo = new FakeMemberRepository(mockContext);
var controller = new MembersController(new DivineRepositories(null, lookupRepo, membersRepo, null), logger, null, null);
mockContext.Arrange(x => (x.GetAllAsync())).Throws(() => new NullReferenceException("null Data"));
//Act
var result = await controller.Get();
//Assert
Assert.NotNull(result);
Assert.Equal(result.StatusCode , (int) HttpStatusCode.BadRequest);
Assert.IsType<string>(result.Value);
Assert.Contains("error",result.Value.ToString(), StringComparison.OrdinalIgnoreCase);
}
示例9: Get_ReturnsNoException
public async Task Get_ReturnsNoException()
{
//Arrange
var mockContext = new MockContext<IRepository<Member>>();
membersRepo = new FakeMemberRepository(mockContext);
var controller = new MembersController(new DivineRepositories(null, lookupRepo, membersRepo, null),logger, null, null);
var data = new List<Member> { new Member { Id = 1 } }.AsQueryable();
mockContext.Arrange(x => (x.GetAllAsync())).Returns(Task.FromResult(data));
//ACT
var result = await controller.Get();
//Assert
Assert.NotNull(result);
Assert.IsType<List<Member>>(result.Value);
Assert.Equal(data.Count(), ((List<Member>)result.Value).Count());
}
示例10: Execute_ArrangedReturnValue_ReturnsValueUsingLambda
public void Execute_ArrangedReturnValue_ReturnsValueUsingLambda()
{
var mockContext = new MockContext<IFoo>();
var fooMock = new FooMock(mockContext);
var outerVariable = " works";
mockContext.Arrange(f => f.Execute(The<string>.IsAnyValue)).Returns<string>(
a =>
{
var r = a + outerVariable + "!";
return r;
});
var result = fooMock.Execute("It");
Assert.AreEqual("It works!", result);
}
示例11: Arrange_ReturnsWithFourArguments_InvokesGetResult
public void Arrange_ReturnsWithFourArguments_InvokesGetResult()
{
var mockContext = new MockContext<IFoo>();
var fooMock = new FooMock(mockContext);
mockContext.Arrange(
f =>
f.Execute(
The<string>.IsAnyValue,
The<string>.IsAnyValue,
The<string>.IsAnyValue,
The<string>.IsAnyValue))
.Returns<string, string, string, string>((a, b, c, d) => "This" + a + b + c + d);
fooMock.Execute(1, 2, 3, 4);
var result = fooMock.Execute(" is", " really", " cool", "!");
Assert.AreEqual("This is really cool!", result);
}
示例12: Arrange_ReturnsWithNoArguments_InvokesGetResult
public void Arrange_ReturnsWithNoArguments_InvokesGetResult()
{
var mockContext = new MockContext<IFoo>();
var fooMock = new FooMock(mockContext);
mockContext.Arrange(f => f.Execute()).Returns(() => "This");
var result = fooMock.Execute();
Assert.AreEqual("This", result);
}
示例13: Arrange_ReturnsWithOneArgument_InvokesGetResult
public void Arrange_ReturnsWithOneArgument_InvokesGetResult()
{
var mockContext = new MockContext<IFoo>();
var fooMock = new FooMock(mockContext);
mockContext.Arrange(f => f.Execute(The<string>.IsAnyValue)).Returns<string>(a => "This" + a);
var result = fooMock.Execute(" is");
Assert.AreEqual("This is", result);
}
示例14: Execute_ArrangedRuturnValue_ArrayElementContraintSupport
public void Execute_ArrangedRuturnValue_ArrayElementContraintSupport()
{
var mockContext = new MockContext<IFoo>();
var fooMock = new FooMock(mockContext);
var inputData = new byte[] {1, 2, 3, 4, 5 };
mockContext.Arrange(
f => f.Execute(The<byte[]>.Is(a => a[4] == 5)))
.Returns<byte[]>(a => a);
var result = fooMock.Execute(inputData);
Assert.AreEqual(inputData, result);
}
示例15: PropertySupport_ArrangeGetterReturnValue_IsVerified
public void PropertySupport_ArrangeGetterReturnValue_IsVerified()
{
var mockContext = new MockContext<IProp>();
var propMock = new PropMock(mockContext);
mockContext.Arrange(x => x.ReadOnlyProperty).Returns(() => "result");
var propertyValue = propMock.ReadOnlyProperty;
Assert.AreEqual("result", propertyValue);
}