FakeItEasy를 처음 사용하고 처음 시도했을 때 생소했습니다. 내가 가짜 원하는 인터페이스는이 같은 방법이있다 : I는 인수가 전달되는 방법을보고 싶습니다FakeItEasy Returns 매개 변수를 사용하여 짧게 반환
byte[] ReadFileChunk(string path,int offset,int count,out long size);
을, 그래서 나는 ReturnsLazily을 사용하고 있습니다. 여기 내 시도 :
long resSize;
A.CallTo(() => dataAttributesController
.ReadFileChunk(A<string>.Ignored, A<int>.Ignored, A<int>.Ignored, out resSize))
.ReturnsLazily((string path, int offset, int count) =>
{
return Encoding.UTF8.GetBytes("You requested: " + path + "(" + offset + "," + count + ")");
})
.AssignsOutAndRefParameters(123);
이 컴파일,하지만 실행 때이 예외가 발생하는 정확한
The faked method has the signature (System.String, System.Int32, System.Int32, System.Int64&), but returns lazily was used with (System.String, System.Int32, System.Int32).
을하지만, 내가 out 매개 변수를 추가하는 방법을 알아낼 수 없습니다. 나는이에 ReturnLazily 부분을 변경하는 경우 : 그렇지처럼이 읽기, 나 같은 초보자
error CS1593: Delegate 'System.Func<FakeItEasy.Core.IFakeObjectCall,byte[]>' does not take 4 arguments
error CS1661: Cannot convert lambda expression to delegate type 'System.Func<string,int,int,long,byte[]>' because the parameter types do not match the delegate parameter types
error CS1677: Parameter 4 should not be declared with the 'out' keyword
:
.ReturnsLazily((string path, int offset, int count, out long size) =>
{
size = 0;
return Encoding.UTF8.GetBytes("You requested: " + path + "(" + offset + "," + count + ")");
})
을가 컴파일되지 않습니다, 나는 오류를 이해하지 못하는 4 매개 변수를 좋아하지 않으며 'out'으로 무엇을해야 하는지도 이해하지 못합니다. 누군가이 오류를 읽어야하는 방법을 설명해 주시겠습니까? 작동 예제도 매우 환영받을 것입니다 :-)
고마워요!
--- 편집 ---
이 작동하는 것 같다:
A.CallTo(() => dataAttributesController
.ReadFileChunk(A<string>.Ignored, A<int>.Ignored, A<int>.Ignored, out resSize))
.ReturnsLazily(x =>
Encoding.UTF8.GetBytes("You requested: " + x.Arguments.Get<string>(0) + "(" + x.Arguments.Get<int>(1) + "," + x.Arguments.Get<int>(2) + ")"))
.AssignsOutAndRefParameters((long)123);
약간 덜 읽을 그럼 내가 기대했다, 이것은 어디 ReturnsLazily의 용도 근처에?