public async stt::Task GetVideoRequestObjectAsync() { moq::Mock <VideoService.VideoServiceClient> mockGrpcClient = new moq::Mock <VideoService.VideoServiceClient>(moq::MockBehavior.Strict); GetVideoRequest request = new GetVideoRequest { ResourceNameAsVideoName = gagvr::VideoName.FromCustomerVideo("[CUSTOMER]", "[VIDEO]"), }; gagvr::Video expectedResponse = new gagvr::Video { ResourceNameAsVideoName = gagvr::VideoName.FromCustomerVideo("[CUSTOMER]", "[VIDEO]"), Id = "id74b70bb8", ChannelId = "channel_id856ceb72", DurationMillis = 4964327688054496886L, Title = "title17dbd3d5", }; mockGrpcClient.Setup(x => x.GetVideoAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <gagvr::Video>(stt::Task.FromResult(expectedResponse), null, null, null, null)); VideoServiceClient client = new VideoServiceClientImpl(mockGrpcClient.Object, null); gagvr::Video responseCallSettings = await client.GetVideoAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); Assert.AreEqual(expectedResponse, responseCallSettings); gagvr::Video responseCancellationToken = await client.GetVideoAsync(request, st::CancellationToken.None); Assert.AreEqual(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task GetVideoAsync2() { Mock <VideoService.VideoServiceClient> mockGrpcClient = new Mock <VideoService.VideoServiceClient>(MockBehavior.Strict); GetVideoRequest request = new GetVideoRequest { ResourceName = new VideoName("[CUSTOMER]", "[VIDEO]").ToString(), }; Video expectedResponse = new Video { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetVideoAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Video>(Task.FromResult(expectedResponse), null, null, null, null)); VideoServiceClient client = new VideoServiceClientImpl(mockGrpcClient.Object, null); Video response = await client.GetVideoAsync(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }