public async Task GetAlertPolicyAsync() { Mock <AlertPolicyService.AlertPolicyServiceClient> mockGrpcClient = new Mock <AlertPolicyService.AlertPolicyServiceClient>(MockBehavior.Strict); GetAlertPolicyRequest expectedRequest = new GetAlertPolicyRequest { AlertPolicyName = new AlertPolicyName("[PROJECT]", "[ALERT_POLICY]"), }; AlertPolicy expectedResponse = new AlertPolicy { Name = "name2-1052831874", DisplayName = "displayName1615086568", }; mockGrpcClient.Setup(x => x.GetAlertPolicyAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <AlertPolicy>(Task.FromResult(expectedResponse), null, null, null, null)); AlertPolicyServiceClient client = new AlertPolicyServiceClientImpl(mockGrpcClient.Object, null); AlertPolicyName name = new AlertPolicyName("[PROJECT]", "[ALERT_POLICY]"); AlertPolicy response = await client.GetAlertPolicyAsync(name); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void GetAlertPolicy() { Mock <AlertPolicyService.AlertPolicyServiceClient> mockGrpcClient = new Mock <AlertPolicyService.AlertPolicyServiceClient>(MockBehavior.Strict); GetAlertPolicyRequest expectedRequest = new GetAlertPolicyRequest { AlertPolicyName = new AlertPolicyName("[PROJECT]", "[ALERT_POLICY]"), }; AlertPolicy expectedResponse = new AlertPolicy { Name = "name2-1052831874", DisplayName = "displayName1615086568", }; mockGrpcClient.Setup(x => x.GetAlertPolicy(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); AlertPolicyServiceClient client = new AlertPolicyServiceClientImpl(mockGrpcClient.Object, null); AlertPolicyName name = new AlertPolicyName("[PROJECT]", "[ALERT_POLICY]"); AlertPolicy response = client.GetAlertPolicy(name); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }