コード例 #1
0
        public async Task <IActionResult> CheckWord([FromBody] CheckWordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            return(this.Json(await this.ghostService.CheckWordAsync(request)));
        }
コード例 #2
0
        public async Task CheckWord_Transaction_Not_Found()
        {
            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider
            .Setup(x => x.GetService(typeof(ICheckWord)))
            .Returns(new CheckWord(ghostRepository));


            var serviceScope = new Mock <IServiceScope>();

            serviceScope.Setup(x => x.ServiceProvider).Returns(serviceProvider.Object);

            var serviceScopeFactory = new Mock <IServiceScopeFactory>();

            serviceScopeFactory
            .Setup(x => x.CreateScope())
            .Returns(serviceScope.Object);

            serviceProvider
            .Setup(x => x.GetService(typeof(IServiceScopeFactory)))
            .Returns(serviceScopeFactory.Object);

            var request = new CheckWordRequest
            {
                Round = 1,
                Turn  = Interface.Enums.Enum.Player.Human,
                Word  = "ac"
            };

            var sut = this.CreateSut();

            // Act
            async Task fn()
            {
                var response = await sut.CheckWordAsync(request);
            }

            // Assert
            await Assert.ThrowsExceptionAsync <TransactionNotFoundException>(fn);

            this.mockServiceProvider.Verify();
            this.mockGhostServiceLogger.VerifyAll();
            this.mockmapper.VerifyAll();
        }
コード例 #3
0
        public async Task GhostController_CheckWordSuccess()
        {
            // Arrange
            var request = new CheckWordRequest();

            this.mockGhostService
            .Setup(s => s.CheckWordAsync(request))
            .ReturnsAsync(new CheckWordResponse())
            .Verifiable();

            var sut = this.CreateSut();

            // Act
            var result = await sut.CheckWord(request);

            // Assert
            Assert.IsInstanceOfType(result, typeof(JsonResult));
            this.mockGhostService.VerifyAll();
        }
コード例 #4
0
        public async Task <CheckWordResponse> CheckWordAsync(CheckWordRequest request)
        {
            if (request == null)
            {
                throw new NullRequestException <CheckWordRequest>();
            }

            // The round is initialize with value = 1
            if (request.Round != request.Word.Length)
            {
                throw new Exception("The word is bigger than the corresponding round");
            }

            // Check if the input are only letters
            CheckInput(request.Word);

            var response = new CheckWordResponse();

            var transaction = (ICheckWord)this.serviceProvider.GetService(typeof(ICheckWord));

            if (transaction == null)
            {
                this.Logger.LogError("Transaction {0} not found", typeof(ICheckWord));
                throw new TransactionNotFoundException(typeof(ICheckWord));
            }

            transaction.StartingWord = request.Word;
            transaction.Round        = request.Round;
            transaction.Turn         = request.Turn;

            if (await transaction.ExecuteAsync())
            {
                response = this.mapper.Map <CheckWordDto, CheckWordResponse>(transaction.Response);
            }

            return(response);
        }
コード例 #5
0
        /// <summary>
        /// Find spelling corrections Find spelling correction suggestions and return result as JSON
        /// </summary>
        /// <exception cref="Cloudmersive.APIClient.NETCore.NLP.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="value">Input string</param>
        /// <returns>Task of ApiResponse (CheckWordResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <CheckWordResponse> > SpellcheckCorrectJsonAsyncWithHttpInfo(CheckWordRequest value)
        {
            // verify the required parameter 'value' is set
            if (value == null)
            {
                throw new ApiException(400, "Missing required parameter 'value' when calling SpellcheckApi->SpellcheckCorrectJson");
            }

            var    localVarPath         = "./nlp-v2/spellcheck/check/word";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json",
                "text/json",
                "application/xml",
                "text/xml",
                "application/x-www-form-urlencoded"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (value != null && value.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(value); // http body (model) parameter
            }
            else
            {
                localVarPostBody = value; // byte array
            }

            // authentication (Apikey) required
            if (!String.IsNullOrEmpty(this.Configuration.GetApiKeyWithPrefix("Apikey")))
            {
                localVarHeaderParams["Apikey"] = this.Configuration.GetApiKeyWithPrefix("Apikey");
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("SpellcheckCorrectJson", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <CheckWordResponse>(localVarStatusCode,
                                                       localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()),
                                                       (CheckWordResponse)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(CheckWordResponse))));
        }
コード例 #6
0
        /// <summary>
        /// Find spelling corrections Find spelling correction suggestions and return result as JSON
        /// </summary>
        /// <exception cref="Cloudmersive.APIClient.NETCore.NLP.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="value">Input string</param>
        /// <returns>Task of CheckWordResponse</returns>
        public async System.Threading.Tasks.Task <CheckWordResponse> SpellcheckCorrectJsonAsync(CheckWordRequest value)
        {
            ApiResponse <CheckWordResponse> localVarResponse = await SpellcheckCorrectJsonAsyncWithHttpInfo(value);

            return(localVarResponse.Data);
        }
コード例 #7
0
        /// <summary>
        /// Find spelling corrections Find spelling correction suggestions and return result as JSON
        /// </summary>
        /// <exception cref="Cloudmersive.APIClient.NETCore.NLP.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="value">Input string</param>
        /// <returns>CheckWordResponse</returns>
        public CheckWordResponse SpellcheckCorrectJson(CheckWordRequest value)
        {
            ApiResponse <CheckWordResponse> localVarResponse = SpellcheckCorrectJsonWithHttpInfo(value);

            return(localVarResponse.Data);
        }