public void DeleteAddress() { //Arrange var address = Repository.GetFirst <Address>(); //Act Repository.Delete(address); Repository.Save(); //Assert Assert.False(address.IsActive); Assert.NotNull(address.ModifiedDateTime); Assert.True(address.ModifiedDateTime.Value.Date == DateTime.Today); }
/// <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); }
public void UpdateAddress() { //Arrange var address = Repository.GetFirst <Address>(); address.Address1 = $"Updated-{address.Address1}"; address.Address2 = $"Updated-{address.Address2}"; address.City = $"Updated-{address.City}"; address.State = $"Updated-{address.State}"; address.Zip = $"Updated-{address.Zip}"; address.Plus4 = $"Updated-{address.Plus4}"; address.IsCurrent = !address.IsCurrent; address.IsHistorical = !address.IsHistorical; address.Accuracy = $"Updated-{address.Accuracy}"; //Act Repository.Update(address); Repository.Save(); //Assert Assert.NotNull(address.ModifiedDateTime); Assert.True(address.ModifiedDateTime.Value.Date == DateTime.Today); }
/// <summary> /// Builds this instance. /// </summary> /// <param name="repository">The repository.</param> public static void Build(IEntityFrameworkRepository repository) { var personSearch = MockDataFactory.GetPersonSearch(); repository.Create(personSearch); repository.Save(); var person = MockDataFactory.GetPerson(personSearch.Id); repository.Create(person); repository.Save(); var addresses = MockDataFactory.GetAddresses(person.Id); foreach (var address in addresses) { repository.Create(address); repository.Save(); } var associates = MockDataFactory.GetAssociates(person.Id); foreach (var associate in associates) { repository.Create(associate); repository.Save(); } var phones = MockDataFactory.GetPhones(person.Id); foreach (var phone in phones) { repository.Create(phone); repository.Save(); } }
public void CreatePersonWithAddresses() { //Arrange var personSearch = MockDataFactory.GetPersonSearch(); Repository.Create(personSearch); Repository.Save(); //Act var person = MockDataFactory.GetPerson(personSearch.Id); Repository.Create(person); Repository.Save(); var addresses = MockDataFactory.GetAddresses(person.Id); foreach (var address in addresses) { Repository.Create(address); Repository.Save(); } var savedPerson = Repository.GetFirst <Person>(x => x.Id == person.Id); var savedAddresses = Repository.Get <Address>(x => x.PersonId == person.Id); //Assert Assert.Equal(person.Id, savedPerson.Id); Assert.Equal(person.FirstName, savedPerson.FirstName); Assert.Equal(person.LastName, savedPerson.LastName); Assert.Equal(person.Alias, savedPerson.Alias); Assert.Equal(person.AgeRange, savedPerson.AgeRange); Assert.Equal(addresses.Count(), savedAddresses.Count()); Assert.Equal(addresses.Count(), savedPerson.Addresses.Count()); foreach (var savedAddress in savedAddresses) { var anyAddress = addresses.Any(x => x.Id == savedAddress.Id); Assert.True(anyAddress); } }
/// <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; } }