Beispiel #1
0
        public async Task <IActionResult> RetrieveSingleEmailAddress([FromRoute] int emailAddressId)
        {
            Logger.Trace($"Executing '{nameof(RetrieveSingleEmailAddress)}'.");

            var userId = HttpContext.GetUserId();

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

            var request = new RetrieveSingleEmailAddressRequest(emailAddressId);

            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;
            }
        }
        public async Task Should_ReturnOK_When_RetrievingEmailAddress(int emailAddressId, int userId)
        {
            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 = 2,
            });
            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.SaveChanges();

            var request = new RetrieveSingleEmailAddressRequest(emailAddressId);

            request.SetUserId(userId);

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

            Assert.Multiple(() =>
            {
                Assert.IsTrue(result.Success);
                Assert.AreEqual(result.StatusCode, HttpStatusCode.OK);
                Assert.IsNotNull(result.EmailAddress);
                Assert.AreEqual(result.EmailAddress.Id, emailAddressId);
            });
        }