public IActionResult SayHello(string name)
        {
            var response = _service.SayHello(new HelloRequest {
                Name = name
            }, null);

            return(Ok(response));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 public Task <HelloReply> GetSayHello(HelloRequest name, ServerCallContext msg)
 {
     return(_greeterService.SayHello(name, msg));
 }