public void ExistingContactReturnsEntity() { var contact = ContactEntityObjectMother.Random(); repo.Setup(x => x.GetById(contact.Id)).Returns(contact); var cmd = new GetContactQuery(contact.Id.Value); var handler = new GetContactQueryHandler(uow.Object, eventBus.Object, repo.Object); var model = handler.Handle(cmd, new System.Threading.CancellationToken()).Result; Assert.IsNotNull(model); Assert.AreEqual(contact.Id.Value, model.Id); Assert.AreEqual(contact.Name.FirstName, model.FirstName); Assert.AreEqual(contact.Name.LastName, model.LastName); Assert.AreEqual(contact.EmailAddresses.Count, model.EmailAddresses.Count()); Assert.AreEqual(contact.PhoneNumbers.Count, model.PhoneNumbers.Count()); foreach (var email in contact.EmailAddresses) { Assert.IsTrue(model.EmailAddresses.Contains(email.Value)); } foreach (var phone in contact.PhoneNumbers) { Assert.IsTrue(model.PhoneNumbers.Any(x => x.PhoneType == phone.PhoneType && x.PhoneNumber == phone.PhoneNumber)); } repo.VerifyAll(); }
public async Task ShouldReturnPriorityLevels() { var query = new GetContactQuery(); var result = await SendAsync(query); result.Gender.Should().NotBeEmpty(); }
public async Task ShouldReturnAllListsAndItems() { await AddAsync(new Domain.Entities.Contact { Title = "Mr", FirstName = "Spider", LastName = "Man", Phones = { new Phone { PhoneNumber = "888888888" }, new Phone { PhoneNumber = "+8 888888 " }, }, Emails = { new Email { EmailAddress = "*****@*****.**" }, new Email { EmailAddress = "*****@*****.**" }, } }); await AddAsync(new Domain.Entities.Contact { Title = "Dr", FirstName = "Bat", LastName = "Man", Phones = { new Phone { PhoneNumber = "7717171717" }, new Phone { PhoneNumber = "+1 8871717" }, }, Emails = { new Email { EmailAddress = "*****@*****.**" }, new Email { EmailAddress = "*****@*****.**" }, } }); var query = new GetContactQuery(); var result = await SendAsync(query); result.Contacts.Should().HaveCount(2); }
public static async Task Run( [QueueTrigger("contacts", Connection = "AzureWebJobsStorage")] string contactJson, ILogger log, ExecutionContext context) { var logPrefix = GetLogPrefix(); log.LogInformation($"{logPrefix}: {contactJson}"); var contactFromFile = JsonConvert.DeserializeObject <FileUploadContact>(contactJson); var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", true, true) .AddEnvironmentVariables() .Build(); var sqlConnectionString = config.GetConnectionString("Sql"); var fileUploadContext = new FileUploadContext(sqlConnectionString); var getEmployerQuery = new GetEmployerQuery(fileUploadContext); var employerInSql = await getEmployerQuery.Execute(contactFromFile.CompanyName, contactFromFile.CreatedOnCompany); if (employerInSql == null) { // TODO Employer has to exist } var getContactQuery = new GetContactQuery(fileUploadContext); var contactInSql = await getContactQuery.Execute(contactFromFile.CompanyName, contactFromFile.CreatedOnCompany); var contact = ContactMapper.Map(contactFromFile, contactInSql, employerInSql.Id); if (contactInSql == null) { log.LogInformation($"{logPrefix} Creating Contact: {contactFromFile.Contact}"); var createEmployerCommand = new CreateContactCommand(fileUploadContext); await createEmployerCommand.Execute(contact); log.LogInformation($"{logPrefix} Created Contact: {contactFromFile.Contact}"); } else { var areEqual = contactInSql.Equals(contact); if (!areEqual) { log.LogInformation($"{logPrefix} Updating Contact: {contactFromFile.Contact}"); var updateContactCommand = new UpdateContactCommand(fileUploadContext); await updateContactCommand.Execute(contact); log.LogInformation($"{logPrefix} Updated Contact: {contactFromFile.Contact}"); } } log.LogInformation($"{logPrefix} Processed Contact: {contactFromFile.Contact}"); }
public async Task <IActionResult> GetContact([FromRoute] Guid id) { var query = new GetContactQuery { ContactId = id }; var response = await _mediator.Send(query); var httpResponse = new ContactHttpResponse { ContactId = response.ContactId, Firstname = response.Firstname, Lastname = response.Lastname }; return(Ok(httpResponse)); }
public async Task <QueryResponse <ContactResponse> > Handle(GetContactQuery request, CancellationToken cancellationToken) { var entity = await _dataLayer.TblIdentityContacts .Include(i => i.Ucentities) .AsNoTracking() .AsSplitQuery() .FirstOrDefaultAsync(i => i.Guid == $"{request.Guid}", cancellationToken); if (entity == null) { return(new () { Message = $"Contact with Guid {request.Guid} does not exist", HttpStatusCode = HttpStatusCode.NotFound }); } return(new () { HttpStatusCode = HttpStatusCode.Accepted, Response = entity.Adapt <ContactResponse>() }); }
public async Task <IActionResult> GetContact(GetContactQuery query) { var contact = await queryExecutor.Execute <GetContactQuery, Contact>(query); return(Ok(contact)); }
public async Task <IEnumerable <Contact> > Handle(GetContactQuery request, CancellationToken cancellationToken) { return(await _contactRepository.GetContacts()); }