示例#1
0
        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();
        }
示例#2
0
        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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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();
        }
示例#6
0
        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);
        }
示例#7
0
        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
        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 static MailingGroupContext BuildClean()
        {
            DbContextOptionsBuilder <MailingGroupContext> dbContextOptionsBuilder =
                new DbContextOptionsBuilder <MailingGroupContext>();

            dbContextOptionsBuilder
            .EnableSensitiveDataLogging()
            .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var databaseContext =
                new MailingGroupContext(dbContextOptionsBuilder.Options);

            databaseContext.Database.EnsureCreated();

            return(databaseContext);
        }
示例#10
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();
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
        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();
        }
 public ShowController(MailingGroupContext context)
 {
     this.db = context;
 }
示例#16
0
 public AppUserBuilder(MailingGroupContext context) : base(context)
 {
 }
示例#17
0
 protected Builder(MailingGroupContext context)
 {
     Context = context;
     Init();
 }
示例#18
0
 public GroupBuilder(MailingGroupContext context) : base(context)
 {
 }
示例#19
0
 public TreeController(MailingGroupContext context, EmployeeDBContext EmployeeDBcontext)
 {
     this.db         = context;
     this.EmployeeDB = EmployeeDBcontext;
 }
示例#20
0
 public Handler(MailingGroupContext context)
 {
     _context = context;
 }
示例#21
0
 public EditController(MailingGroupContext context)
 {
     this.db = context;
 }
示例#22
0
 public ValuesController(MailingGroupContext context)
 {
     this.db = context;
 }
示例#23
0
 public DepartmentsController(MailingGroupContext context, EmployeeDBContext EmployeeDBcontext)
 {
     this.db         = context;
     this.EmployeeDB = EmployeeDBcontext;
 }