public IActionResult SayHello(string name) { var response = _service.SayHello(new HelloRequest { Name = name }, null); return(Ok(response)); }
public async Task SayHelloTest() { // arrange var service = new GreeterService(NullLoggerFactory.Instance); // act var response = await service.SayHello(new HelloRequest { Name = "test" }, TestServerCallContext.Create()); // Assert Assert.AreEqual("Hello test", response.Message); }
public async Task Given_RandomName_When_CallingSayHello_Return_GreetingMessage() { // Arrange var loggerMock = new Moq.Mock <ILogger <GreeterService> >(); var contextMock = new Moq.Mock <ServerCallContext>(); var service = new GreeterService(loggerMock.Object); var request = new HelloRequest() { Name = _fixture.Create <string>() }; // Act var result = await service.SayHello(request, contextMock.Object); // Assert Assert.Equal($"Hello {request.Name}", result.Message); }
public async Task Given_EmptyName_When_CallingSayHello_Return_Error() { // Arrange var loggerMock = new Moq.Mock <ILogger <GreeterService> >(); var contextMock = new Moq.Mock <ServerCallContext>(); var service = new GreeterService(loggerMock.Object); var request = new HelloRequest() { Name = string.Empty }; // Act var exception = await Assert.ThrowsAsync <RpcException>(async() => { await service.SayHello(request, contextMock.Object); }); // Assert Assert.Equal(StatusCode.InvalidArgument, exception.StatusCode); }
public Task <HelloReply> GetSayHello(HelloRequest name, ServerCallContext msg) { return(_greeterService.SayHello(name, msg)); }