예제 #1
0
        public async Task <IActionResult> CreateMailingGroup([FromBody] CreateMailingGroupRequest request)
        {
            Logger.Trace($"Executing '{nameof(CreateMailingGroup)}'.");

            var userId = HttpContext.GetUserId();

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

            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(CreateMailingGroupHandler)}'.");
                throw;
            }
        }
예제 #2
0
        public async Task Should_ReturnConflict_When_PassAlreadyAddedGroupNameForUser(string name, int userId)
        {
            var cancellationToken = new CancellationToken();

            var databaseContext = Create.MockedDbContextFor <DatabaseContext>();

            databaseContext.Set <MailingGroup>().Add(new MailingGroup()
            {
                Id           = 1,
                Name         = "MailingGroupName1",
                SystemUserId = 1
            });
            databaseContext.Set <MailingGroup>().Add(new MailingGroup()
            {
                Id           = 2,
                Name         = "MailingGroupName2",
                SystemUserId = 1
            });
            databaseContext.Set <MailingGroup>().Add(new MailingGroup()
            {
                Id           = 3,
                Name         = "MailingGroupName3",
                SystemUserId = 1
            });
            databaseContext.Set <MailingGroup>().Add(new MailingGroup()
            {
                Id           = 4,
                Name         = "MailingGroupName1",
                SystemUserId = 2
            });
            databaseContext.Set <MailingGroup>().Add(new MailingGroup()
            {
                Id           = 5,
                Name         = "MailingGroupName2",
                SystemUserId = 2
            });
            databaseContext.Set <MailingGroup>().Add(new MailingGroup()
            {
                Id           = 6,
                Name         = "MailingGroupName3",
                SystemUserId = 2
            });

            databaseContext.SaveChanges();

            var request = new CreateMailingGroupRequest(name);

            request.SetUserId(userId);

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

            Assert.Multiple(() =>
            {
                Assert.IsFalse(result.Success);
                Assert.AreEqual(result.StatusCode, HttpStatusCode.Conflict);
            });
        }