예제 #1
0
#pragma warning restore xUnit1004 // Test methods should not be skipped
        public async Task GetPerson()
        {
            //Arrange
            var model = GetTestPerson();

            //Act
            var response = await Controller.GetFindPerson(model);

            //Assert
            Assert.NotNull(response);
            Assert.IsAssignableFrom <JsonResult>(response);
            //Assert.NotNull(response.SerializerSettings);
            //Assert.NotNull(response.Value);
            //Assert.IsAssignableFrom<string>(response.Value);
            //Assert.False(string.IsNullOrWhiteSpace(response.Value.ToString()), "Response string is empty null or whitespace.");
        }
예제 #2
0
        /// <summary>
        /// Searches the specified person.
        /// </summary>
        /// <param name="serach">The search criteria.</param>
        /// <param name="searchWaitMs">The search wait in ms.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">person</exception>
        public async Task <PersonSearch> SearchAsync(Search search, int searchWaitMs, CancellationToken cancellationToken)
        {
            if (search == null)
            {
                throw new ArgumentNullException(nameof(search));
            }

            var log = logger.With("search", search);

            var stopwatch = new Stopwatch();

            try
            {
                stopwatch.Start();

                var person = Mapper.Map <Models.Domain.Api.Request.Person>(search);
                log.DebugEvent("Search", "Mapped PersonSearchRequest entity to Person domain model after {ms}ms", stopwatch.ElapsedMilliseconds);

                #region Execute Find Person request

                var result = await FindPersonController.GetFindPerson(person);

                await Task.Delay(searchWaitMs);

                log.With("Person", person)
                .InformationEvent("Search", "Executed Find Person request after {ms}ms", stopwatch.ElapsedMilliseconds);

                var jObject = JObject.Parse(result.Content);

                log.ForContext("Content", jObject);

                #endregion Execute Find Person request

                #region Save Response to JSON text file

                var fullPath = Path.Combine(this.ResultOutputPath, $"SearchJob-{person.Name}");
                await this.Export.ToJsonAsync(jObject, fullPath, cancellationToken);

                #endregion Save Response to JSON text file

                #region Create PersonSearchResult Entity

                var personSearch = PersonSearchResultFactory.Create(search, result.StatusCode, jObject);

                log.With("PersonSearchResult", personSearch);

                #endregion Create PersonSearchResult Entity

                #region Log Data Problems

                if (!string.IsNullOrWhiteSpace(personSearch.Warnings))
                {
                    log.WarningEvent("Search", "FindPerson api result returned with warning messages");
                }
                if (!string.IsNullOrWhiteSpace(personSearch.Error))
                {
                    log.ErrorEvent("Search", "FindPerson api result returned with error message");
                }
                if (string.IsNullOrWhiteSpace(personSearch.Data))
                {
                    log.ErrorEvent("Search", "FindPerson api result returned with no person data");;
                }

                #endregion Log Data Problems

                //todo fix all of this
                #region Save Entity to Database

                Repository.Create(personSearch);
                Repository.Save();

                #endregion Save Entity to Database

                stopwatch.Stop();
                log.DebugEvent("Search", "Finished processing person search result after {ms}ms", stopwatch.ElapsedMilliseconds);

                return(personSearch);
            }
            catch (Exception ex)
            {
                //Log and throw
                log.ErrorEvent(ex, "Search", "Processing person failed after {ms}ms", stopwatch.ElapsedMilliseconds);
                throw;
            }
        }