예제 #1
0
        public async Task <IActionResult> RetrieveEmailAddresses([FromQuery] int?mailingGroupId = null)
        {
            Logger.Trace($"Executing '{nameof(RetrieveEmailAddresses)}'.");

            var userId = HttpContext.GetUserId();

            if (userId == null)
            {
                return(Unauthorized());
            }

            var request = new RetrieveEmailAddressesRequest(mailingGroupId);

            request.SetUserId(userId.Value);

            try
            {
                var result = await _mediator.Send(request);

                return(result.GetResult());
            }
            catch (Exception ex)
            {
                Logger.Error(ex, $"Unexpected error thrown while executing '{nameof(RetrieveEmailAddressesHandler)}'.");
                throw;
            }
        }
예제 #2
0
        public async Task Should_ReturnOK_When_RetrievingUserEmailAddressesFilterByMailingGroupId(int userId, int mailingGroupId, int counts)
        {
            var cancellationToken = new CancellationToken();

            var databaseContext = Create.MockedDbContextFor<DatabaseContext>();
            databaseContext.Set<MailingGroup>().Add(new MailingGroup()
            {
                Id = 1,
                SystemUserId = 1,
            });
            databaseContext.Set<MailingGroup>().Add(new MailingGroup()
            {
                Id = 2,
                SystemUserId = 1,
            });

            databaseContext.Set<EmailAddress>().Add(new EmailAddress()
            {
                Id = 1,
                MailingGroupId = 1,
            });
            databaseContext.Set<EmailAddress>().Add(new EmailAddress()
            {
                Id = 2,
                MailingGroupId = 1,
            });
            databaseContext.Set<EmailAddress>().Add(new EmailAddress()
            {
                Id = 3,
                MailingGroupId = 2,
            });
            databaseContext.Set<EmailAddress>().Add(new EmailAddress()
            {
                Id = 4,
                MailingGroupId = 2,
            });
            databaseContext.Set<EmailAddress>().Add(new EmailAddress()
            {
                Id = 5,
                MailingGroupId = 2,
            });

            databaseContext.SaveChanges();

            var request = new RetrieveEmailAddressesRequest(mailingGroupId);
            request.SetUserId(userId);

            var result = await new RetrieveEmailAddressesHandler(databaseContext).Handle(request, cancellationToken);

            Assert.Multiple(() =>
            {
                Assert.IsTrue(result.Success);
                Assert.AreEqual(result.StatusCode, HttpStatusCode.OK);
                Assert.AreEqual(result.EmailAddresses.Count(), counts);
            });
        }