コード例 #1
0
ファイル: CreateTest.cs プロジェクト: Napeithe/MailingGroup
        public async Task ExecuteShouldReturnSuccess()
        {
            //Arrange
            MailingGroupContext context = ContextBuilder.BuildClean();

            MailingGroup mailingGroup = new GroupBuilder(context)
                                        .WithName("New group")
                                        .WithUser(x => x.WithName("userName"))
                                        .WithEmail("first")
                                        .BuildAndSave();

            Command cmd = new Command
            {
                UserId  = mailingGroup.User.Id,
                Email   = "*****@*****.**",
                GroupId = mailingGroup.Id
            };
            //Act
            ApiResult <EmailDto> result = await new Handler(context).Handle(cmd, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeTrue();
            result.StatusCode.Should().Be(200);
            result.Data.Should().NotBeNull();
            result.Data.Id.Should().Be(2);
        }
コード例 #2
0
        public async Task ExecuteShouldReturnFailedWhenGroupIsForOtherUser()
        {
            //Arrange
            MailingGroupContext context = ContextBuilder.BuildClean();

            MailingGroup firstMailingGroup = new GroupBuilder(context)
                .WithName("Old group")
                .WithUser(x => x.WithName("userName"))
                .BuildAndSave();
            MailingGroup secondMailingGroup = new GroupBuilder(context)
                .WithName("Old group")
                .WithUser(x => x.WithName("otherUser"))
                .BuildAndSave();

            Command query = new Command()
            {
                Id = new List<int>{secondMailingGroup.Id},
                UserId = firstMailingGroup.UserId
            };
            //Act
            ApiResult result = await new Handler(context).Handle(query, CancellationToken.None);
            //Assert
            result.IsSuccess.Should().BeFalse();
            result.Message.Should().Be("Mail group not exists");
            result.StatusCode.Should().Be(404);
        }
コード例 #3
0
ファイル: CreateTest.cs プロジェクト: Napeithe/MailingGroup
        public async Task ExecuteShouldReturnFailedEmailIsAlreadyExists()
        {
            //Arrange
            MailingGroupContext context = ContextBuilder.BuildClean();

            MailingGroup mailingGroup = new GroupBuilder(context)
                                        .WithName("New group")
                                        .WithUser(x => x.WithName("userName"))
                                        .WithEmail("first")
                                        .BuildAndSave();

            Command cmd = new Command
            {
                UserId  = mailingGroup.User.Id,
                Email   = "*****@*****.**",
                GroupId = mailingGroup.Id
            };
            //Act
            ApiResult <EmailDto> result = await new Handler(context).Handle(cmd, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeFalse();
            result.Message.Should().Be("Email is already exists");
            result.StatusCode.Should().Be(409);
        }
コード例 #4
0
        public async Task ExecuteShouldReturnSuccessAndRemoveMailingGroupWithEmail()
        {
            //Arrange
            MailingGroupContext context = ContextBuilder.BuildClean();
            MailingGroup firstMailingGroup = new GroupBuilder(context)
                .WithName("Old group")
                .WithUser(x => x.WithName("userName"))
                .WithEmail("first")
                .WithEmail("second")
                .WithEmail("third")
                .BuildAndSave();
            Command query = new Command()
            {
                Id = new List<int> { 1 },
                UserId = firstMailingGroup.UserId
            };
            //Act
            ApiResult result = await new Handler(context).Handle(query, CancellationToken.None);
            //Assert
            result.IsSuccess.Should().BeTrue();
            result.Message.Should().BeNullOrEmpty();
            result.StatusCode.Should().Be(200);

            context.MailingGroups.Should().BeEmpty();
            context.Emails.Should().BeEmpty();
        }
コード例 #5
0
ファイル: UpdateTest.cs プロジェクト: Napeithe/MailingGroup
        public async Task ExecuteShouldReturnFailedResultNameIsRequired()
        {
            //Arrange
            MailingGroupContext mailingGroupContext = ContextBuilder.BuildClean();
            AppUser             user = new AppUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            mailingGroupContext.Add(user);
            mailingGroupContext.SaveChanges();

            Command cmd = new Command
            {
                UserId = user.Id,
                Name   = string.Empty
            };
            //Act
            ApiResult <MailingGroupDto> result = await new Handler(mailingGroupContext).Handle(cmd, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeFalse();
            result.Message.Should().Be("Name is required");
            result.Data.Should().BeNull();
        }
コード例 #6
0
        public async Task ExecuteShouldReturnSuccess()
        {
            //Arrange
            MailingGroupContext mailingGroupContext = ContextBuilder.BuildClean();
            AppUser             user = new AppUserBuilder(mailingGroupContext).WithName("test").BuildAndSave();

            Command cmd = new Command
            {
                UserId = user.Id,
                Name   = "New group"
            };
            //Act
            ApiResult <MailingGroupItemListDto> result = await new Handler(mailingGroupContext).Handle(cmd, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeTrue();
            result.Message.Should().BeNullOrEmpty();

            mailingGroupContext.MailingGroups.Should().HaveCount(1);
            Model.Entity.MailingGroup mailingGroup = mailingGroupContext.MailingGroups.First();
            mailingGroup.Name.Should().Be(cmd.Name);
            mailingGroup.UserId.Should().Be(cmd.UserId);
            mailingGroup.Id.Should().Be(1);

            result.Data.Should().NotBeNull();
            result.Data.Id.Should().Be(mailingGroup.Id);
        }
コード例 #7
0
ファイル: UpdateTest.cs プロジェクト: Napeithe/MailingGroup
        public async Task ExecuteShouldReturnSuccess()
        {
            //Arrange
            MailingGroupContext mailingGroupContext = ContextBuilder.BuildClean();
            AppUser             user = new AppUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            AppUser otherUser = new AppUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            mailingGroupContext.Add(user);
            mailingGroupContext.Add(otherUser);
            Model.Entity.MailingGroup oldGroup = new Model.Entity.MailingGroup
            {
                Name = "Old group",
                User = user
            };
            Model.Entity.MailingGroup groupOtherUser = new Model.Entity.MailingGroup
            {
                Name = "New group",
                User = otherUser
            };
            mailingGroupContext.Add(oldGroup);
            mailingGroupContext.Add(groupOtherUser);
            mailingGroupContext.SaveChanges();

            Command cmd = new Command
            {
                UserId = user.Id,
                Id     = oldGroup.Id,
                Name   = "New group"
            };
            //Act
            ApiResult <MailingGroupDto> result = await new Handler(mailingGroupContext).Handle(cmd, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeTrue();
            result.Message.Should().BeNullOrEmpty();

            mailingGroupContext.MailingGroups.Should().HaveCount(2);
            Model.Entity.MailingGroup mailingGroup = mailingGroupContext.MailingGroups.First();
            mailingGroup.Name.Should().Be(cmd.Name);
            mailingGroup.UserId.Should().Be(cmd.UserId);
            mailingGroup.Id.Should().Be(1);

            result.Data.Should().NotBeNull();
            result.Data.Id.Should().Be(mailingGroup.Id);
        }
コード例 #8
0
ファイル: GetTest.cs プロジェクト: Napeithe/MailingGroup
        public async Task ExecuteShouldReturnFailedWhenGroupIdIsWrong()
        {
            //Arrange
            MailingGroupContext context   = ContextBuilder.BuildClean();
            AppUser             firstUser = new AppUser()
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };
            AppUser secondUser = new AppUser()
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            context.Add(firstUser);
            context.Add(secondUser);

            List <MailingGroup> mailingGroups = new List <MailingGroup>
            {
                new MailingGroup()
                {
                    Name = "first",
                    User = firstUser
                },
                new MailingGroup()
                {
                    Name = "second",
                    User = secondUser
                }
            };

            context.AddRange(mailingGroups);
            context.SaveChanges();
            Query query = new Query()
            {
                Id     = 22,
                UserId = firstUser.Id
            };
            //Act
            ApiResult <MailingGroupDto> result = await new Handler(context).Handle(query, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeFalse();
            result.Message.Should().Be("Mail group not exists");
            result.Data.Should().BeNull();
            result.StatusCode.Should().Be(404);
        }
コード例 #9
0
        public async Task ExecuteShouldReturnFailedResultUserNotFound()
        {
            //Arrange
            MailingGroupContext mailingGroupContext = ContextBuilder.BuildClean();
            Command             cmd = new Command
            {
                UserId = Guid.NewGuid().ToString(),
                Name   = "test"
            };
            //Act
            ApiResult <MailingGroupItemListDto> result = await new Handler(mailingGroupContext).Handle(cmd, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeFalse();
            result.Message.Should().Be("User not found");
            result.Data.Should().BeNull();
        }
コード例 #10
0
ファイル: CreateTest.cs プロジェクト: Napeithe/MailingGroup
        public async Task ExecuteShouldReturnFailedMailingGroupIsNotExist()
        {
            //Arrange
            MailingGroupContext context = ContextBuilder.BuildClean();
            Command             cmd     = new Command
            {
                UserId  = Guid.NewGuid().ToString(),
                Email   = "*****@*****.**",
                GroupId = 23
            };
            //Act
            ApiResult <EmailDto> result = await new Handler(context).Handle(cmd, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeFalse();
            result.Message.Should().Be("Mailing group is not exists");
            result.StatusCode.Should().Be(404);
        }
コード例 #11
0
ファイル: GetTest.cs プロジェクト: Napeithe/MailingGroup
        public async Task ExecuteShouldReturMailingGroupDetailWithEmails()
        {
            //Arrange
            MailingGroupContext context   = ContextBuilder.BuildClean();
            AppUser             firstUser = new AppUser()
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };
            AppUser secondUser = new AppUser()
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            context.Add(firstUser);
            context.Add(secondUser);

            MailingGroup group = new MailingGroup()
            {
                Name = "first",
                User = firstUser,
            };

            group.Emails = GenerateEmails(20, group).ToList();
            context.Add(group);
            context.SaveChanges();
            Query query = new Query()
            {
                Id     = 1,
                UserId = firstUser.Id
            };
            //Act
            ApiResult <MailingGroupDto> result = await new Handler(context).Handle(query, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeTrue();
            result.Message.Should().BeNullOrEmpty();
            MailingGroupDto mailingGroupDto = result.Data;

            mailingGroupDto.Should().NotBeNull();
            mailingGroupDto.Emails.Should().NotBeEmpty();
            result.StatusCode.Should().Be(200);
        }
コード例 #12
0
ファイル: GetAllTest.cs プロジェクト: Napeithe/MailingGroup
        public async Task ExecuteShouldReturnAllUsersMailingGroupWithEmails()
        {
            //Arrange
            var     context   = ContextBuilder.BuildClean();
            AppUser firstUser = new AppUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };
            List <MailingGroup> firstUsersGroup = GenerateGroups(5, firstUser).ToList();

            context.AddRange(firstUsersGroup);
            AppUser secondUser = new AppUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };
            List <MailingGroup> secondUsersGroup = GenerateGroups(4, secondUser).ToList();

            context.AddRange(secondUsersGroup);
            context.SaveChanges();
            context.MailingGroups.Should().HaveCount(9);
            context.Emails.Should().HaveCount(16);
            Query query = new Query
            {
                UserId = firstUser.Id
            };
            //Act
            ApiResult <List <MailingGroupItemListDto> > apiResult = await new Handler(context).Handle(query, CancellationToken.None);

            // Assert
            apiResult.IsSuccess.Should().BeTrue();
            apiResult.Data.Should().NotBeNull()
            .And.NotBeEmpty()
            .And.HaveCount(5);
            MailingGroupItemListDto lastElement = apiResult.Data.Last();

            lastElement.Id.Should().Be(5);
            lastElement.Name.Should().NotBeNullOrEmpty();
            lastElement.NumberOfEmails.Should().Be(4);
        }
コード例 #13
0
ファイル: UpdateTest.cs プロジェクト: Napeithe/MailingGroup
        public async Task ExecuteShouldReturnNameIsTaken()
        {
            //Arrange
            MailingGroupContext mailingGroupContext = ContextBuilder.BuildClean();
            AppUser             user = new AppUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            mailingGroupContext.Add(user);
            Model.Entity.MailingGroup oldGroup = new Model.Entity.MailingGroup
            {
                Name = "Old group",
                User = user
            };
            Model.Entity.MailingGroup otherGroup = new Model.Entity.MailingGroup
            {
                Name = "New group",
                User = user
            };
            mailingGroupContext.Add(oldGroup);
            mailingGroupContext.SaveChanges();
            mailingGroupContext.Add(otherGroup);
            mailingGroupContext.SaveChanges();

            Command cmd = new Command
            {
                UserId = user.Id,
                Id     = oldGroup.Id,
                Name   = "New group"
            };
            //Act
            ApiResult <MailingGroupDto> result = await new Handler(mailingGroupContext).Handle(cmd, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeFalse();
            result.Message.Should().Be("This mailing group name is already exists");
            result.StatusCode.Should().Be(401);
            result.Data.Should().BeNull();
        }
コード例 #14
0
        public async Task ExecuteShouldReturnFailedNameIsAlreadyInUse()
        {
            //Arrange
            MailingGroupContext mailingGroupContext = ContextBuilder.BuildClean();
            MailingGroup        mailingGroup        = new GroupBuilder(mailingGroupContext)
                                                      .WithName("Old group")
                                                      .WithUser(x => x.WithName("userName"))
                                                      .BuildAndSave();

            Command cmd = new Command
            {
                UserId = mailingGroup.UserId,
                Name   = mailingGroup.Name
            };
            //Act
            ApiResult <MailingGroupItemListDto> result = await new Handler(mailingGroupContext).Handle(cmd, CancellationToken.None);

            //Assert
            result.IsSuccess.Should().BeFalse();
            result.Message.Should().Be("This mailing group is already exists");
            result.Data.Should().BeNull();
        }