Exemplo n.º 1
0
        public async Task RegisterEndpoint_NullResponse()
        {
            // Arrange
            RegisterEndpointRequest request = new RegisterEndpointRequest();

            _mock.Setup(x => x.Register("application display name")).ReturnsAsync(null);

            // Act
            var response = await _controller.RegisterEndpoint(request);

            // Assert
            //N/A
        }
Exemplo n.º 2
0
        public async Task RegisterEndpoint_Success()
        {
            // Arrange
            var request = new RegisterEndpointRequest {
                DisplayName = "application display name"
            };

            _mock.Setup(x => x.Register(request.DisplayName)).ReturnsAsync(new RegisterEndpointResponse());

            // Act
            var response = await _controller.RegisterEndpoint(request);

            // Assert
            Assert.IsNotNull(response);
        }
Exemplo n.º 3
0
        public async Task <RegisterEndpointResponse> RegisterEndpoint(RegisterEndpointRequest request)
        {
            if (request == null)
            {
                throw new HttpResponseException(new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Content    = new StringContent(Constants.HttpResponse_400)
                });
            }

            try
            {
                //Do register and get data to response
                var app = await _applicationService.Register(request.DisplayName);

                if (app == null)
                {
                    throw new HttpResponseException(new HttpResponseMessage
                    {
                        StatusCode = HttpStatusCode.Forbidden,
                        Content    = new StringContent(Constants.HttpResponse_403)
                    });
                }

                return(app);
            }
            catch (Exception)
            {
                throw new HttpResponseException(new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.InternalServerError,
                    Content    = new StringContent(Constants.HttpResponse_500)
                });
            }
        }