public void Create_ValidInput_ReturnSearchResult()
        {
            // Arrange
            var search         = new Search();
            var httpStatusCode = (int)HttpStatusCode.OK;
            var jObject        = MockDataFactory.GetExampleJObject();

            // Act
            var result = PersonSearchResultFactory.Create(search, httpStatusCode, jObject);

            // Assert
            Assert.IsType <PersonSearch>(result);
            Assert.NotNull(result);
            Assert.Equal(httpStatusCode, result.HttpStatusCode);
            Assert.Equal(jObject.ToString(), result.Data);
        }
Exemple #2
0
        /// <summary>
        /// Imports the specified j object.
        /// </summary>
        /// <param name="jObject">The j object.</param>
        /// <returns></returns>
        public PersonSearch Import(JObject jObject)
        {
            //todo map this
            var search = new Search();

            #region Create PersonSearchResult Entity

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

            var log = logger.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

            #region Save Entity to Database

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

            #endregion Save Entity to Database

            return(personSearch);
        }
Exemple #3
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;
            }
        }