Esempio n. 1
0
        public async void GetContactListQueryTest()
        {
            //Arange
            var testHelper = new TestHelper();

            var contactCount = 5;

            for (int i = 0; i < contactCount; i++)
            {
                var contact = Contact.Create($"someone{i}", $"someone{i}@example.com", $"156464654{i}", null, testHelper.contactsContext);

                await testHelper.contactsContext.AddAsync(contact);

                await testHelper.contactsContext.SaveChangesAsync();
            }

            GetContactListQuery        query   = new GetContactListQuery();
            GetContactListQueryHandler handler = new GetContactListQueryHandler(testHelper.contactsContext);

            //Act
            var result = await handler.Handle(query, default);

            //Asert
            result.Should().NotBeNull();
            result.Count.Should().BeGreaterThan(2);
        }
Esempio n. 2
0
    public async Task <QueryResponse <List <ContactResponse> > > Handle(GetContactListQuery request, CancellationToken cancellationToken)
    {
        var credential = await _dataLayer.TblIdentityCredentials
                         .Include(i => i.IdentityInfo)
                         .AsNoTracking()
                         .FirstOrDefaultAsync(i => i.Guid == $"{request.CredentialGuid}", cancellationToken);

        if (credential == null)
        {
            return(new()
            {
                Message = $"Credentials does not exist",
                HttpStatusCode = HttpStatusCode.NotFound
            });
        }

        var entity = await _dataLayer.TblIdentityContacts
                     .Where(i => i.UserCredentialId == credential.Id)
                     .Include(i => i.Ucentities)
                     .AsNoTracking()
                     .AsSplitQuery()
                     .ToListAsync(cancellationToken);

        if (!entity.Any())
        {
            return(new ()
            {
                Message = $"No contacts exists",
                HttpStatusCode = HttpStatusCode.NotFound
            });
        }

        return(new ()
        {
            HttpStatusCode = HttpStatusCode.Accepted,
            Response = entity.Adapt <List <ContactResponse> >()
        });
    }
Esempio n. 3
0
 public async Task <IEnumerable <ContactDto> > Handle(GetContactListQuery request, CancellationToken cancellationToken)
 {
     return(await _context.Contacts.Include(c => c.Zone).OrderByDescending(c => c.Id).ProjectTo <ContactDto>(_mapper.ConfigurationProvider)
            .ToListAsync(cancellationToken));
 }