public async Task Member_with_administrator_permission_can_assign_role_to_member() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").AddPermission("Administrator").Build()
                        .CreateRole("role2").Build()
                        .CreateMember().AssignRole(1).Build()
                        .CreateMember().Build()
                        .Build().Build();

            await sut.SendAsync(new AssignRoleToMemberCommand(group.Member(1).UserId, group.GroupId, group.Member(2).UserId, group.Role(2).RoleId));

            var roles = await sut.QueryAsync(new GetMemberRolesQuery(group.Member(1).UserId, group.GroupId, group.Member(2).UserId));
            roles.Should().SatisfyRespectively(
                x =>
            {
                x.RoleId.Should().Be(group.Role(2).RoleId);
                x.Priority.Should().Be(0);
                x.Name.Should().Be("role2");
            },
                x =>
            {
                x.RoleId.Should().NotBeEmpty();
                x.Priority.Should().Be(-1);
                x.Name.Should().Be("@everyone");
            }
                );
        });
        public async Task Owner_can_assign_role_to_member() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").Build()
                        .CreateMember().Build()
                        .Build().Build();

            await sut.AssignRole(group.OwnerId, group.GroupId, group.Member(1).UserId, group.Role(1).RoleId);

            var roles = await sut.QueryAsync(new GetMemberRolesQuery(group.OwnerId, group.GroupId, group.Member(1).UserId));
            roles.Should().SatisfyRespectively(
                x =>
            {
                x.RoleId.Should().Be(group.Role(1).RoleId);
                x.Priority.Should().Be(0);
                x.Name.Should().Be("role1");
            },
                x =>
            {
                x.RoleId.Should().NotBeEmpty();
                x.Priority.Should().Be(-1);
                x.Name.Should().Be("@everyone");
            }
                );
        });
Example #3
0
        public async Task Owner_cannot_leave_group() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1").Build();

            Func <Task> action = async() => await sut.SendAsync(new LeaveGroupCommand(group.OwnerId, group.GroupId));

            await action.Should().ThrowAsync <OwnerCannotLeaveGroupException>();
        });
Example #4
0
        public async Task Fails_when_role_do_not_exists() => await Run(async sut =>
        {
            var group   = await GroupBuilder.For(sut).CreateGroup("group1").Build();
            var command = new RemoveRoleCommand(group.OwnerId, group.GroupId, Guid.NewGuid());

            Func <Task> action = async() => await sut.SendAsync(command);

            await action.Should().ThrowAsync <RoleNotFoundException>();
        });
Example #5
0
        public async Task Fails_when_member_do_not_have_correct_permission() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1").AsOwner()
                        .CreateMember().Build().Build().Build();

            Func <Task> action = async() => await sut.SendAsync(new AddRoleCommand(group.Member(1).UserId, group.GroupId, Guid.NewGuid(), "role1"));

            await action.Should().ThrowAsync <InsufficientPermissionsException>();
        });
Example #6
0
        public async Task Fails_when_kicked_member_is_missing() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .Build();

            Func <Task> action = async() => await sut.SendAsync(new KickMemberCommand(group.OwnerId, group.GroupId, Guid.NewGuid()));

            await action.Should().ThrowAsync <MemberNotFoundException>();
        });
Example #7
0
        public async Task Owner_cannot_kick_himself() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .Build();

            Func <Task> action = async() => await sut.SendAsync(new KickMemberCommand(group.OwnerId, group.GroupId, group.OwnerId));

            await action.Should().ThrowAsync <InsufficientPermissionsException>();
        });
        public async Task Fails_when_role_is_missing() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1").AsOwner().CreateMember().Build().Build().Build();

            Func <Task> action = async() => await sut.SendAsync(new AssignRoleToMemberCommand(group.OwnerId, group.GroupId, group.Member(1).UserId, Guid.NewGuid()));

            await action.Should().ThrowAsync <RoleNotFoundException>();
        });
Example #9
0
        public async Task Fails_when_member_is_missing() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1").AsOwner().CreateRole("role1").Build().Build().Build();

            Func <Task> action = async() => await sut.SendAsync(new RemoveRoleFromMemberCommand(group.OwnerId, group.GroupId, Guid.NewGuid(), group.Role(1).RoleId));

            await action.Should().ThrowAsync <MemberNotFoundException>();
        });
Example #10
0
        public async Task Fails_when_channel_name_is_empty(string emptyName) => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1")
                        .Build();

            Func <Task> action = () => sut.SendAsync(new CreateChannelCommand(group.OwnerId, group.GroupId, Guid.NewGuid(), emptyName));

            await action.Should().ThrowAsync <InvalidChannelNameException>();
        });
Example #11
0
        public async Task Fails_when_user_is_missing_in_group() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1")
                        .Build();

            Func <Task> action = () => sut.SendAsync(new CreateChannelCommand(Guid.NewGuid(), group.GroupId, Guid.NewGuid(), "channel1"));

            await action.Should().ThrowAsync <MemberNotFoundException>();
        });
Example #12
0
        public async Task Fails_when_role_name_is_invalid(string roleName) => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1").AsOwner().CreateRole("role1").Build().Build().Build();

            var command = new AddRoleCommand(group.OwnerId, group.GroupId, group.Role(1).RoleId, roleName);

            Func <Task> action = async() => await sut.SendAsync(command);

            await action.Should().ThrowAsync <InvalidRoleNameException>();
        });
Example #13
0
        public async Task Fails_when_role_is_missing() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1").AsOwner().Build().Build();

            var command = new MoveDownRoleInHierarchyCommand(group.OwnerId, group.GroupId, Guid.NewGuid());

            Func <Task> action = async() => await sut.SendAsync(command);

            await action.Should().ThrowAsync <RoleNotFoundException>();
        });
Example #14
0
        public async Task Everyone_role_cannot_be_removed() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .Build();
            var everyoneRole = (await sut.QueryAsync(new GetRolesQuery(group.OwnerId, group.GroupId))).First();


            Func <Task> action = () => sut.SendAsync(new RemoveRoleCommand(group.OwnerId, group.GroupId, everyoneRole.RoleId));

            await action.Should().ThrowAsync <EveryoneRoleCannotBeRemovedException>();
        });
Example #15
0
        public async Task Owner_can_kick_member() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner().CreateMember().Build().Build()
                        .Build();

            await sut.SendAsync(new KickMemberCommand(group.OwnerId, group.GroupId, group.Member(1).UserId));

            var members = await sut.QueryAsync(new GetMembersQuery(group.OwnerId, group.GroupId, false, group.Member(1).UserId));
            members.Should().BeNullOrEmpty();
        });
Example #16
0
        public async Task Fails_when_user_is_missing() => await Run(
            async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .Build();
            var command = new RemoveGroupCommand(Guid.NewGuid(), group.GroupId);

            Func <Task> action = () => sut.SendAsync(command);

            await action.Should().ThrowAsync <MemberNotFoundException>();
        }
            );
Example #17
0
        public async Task Fails_when_group_is_missing() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1")
                        .AsOwner().CreateChannel("channel1").Build()
                        .Build().Build();

            Func <Task> action = () => sut.SendAsync(
                new RemoveChannelCommand(group.OwnerId, Guid.NewGuid(), group.Channel(1).ChannelId));

            await action.Should().ThrowAsync <GroupNotFoundException>();
        });
Example #18
0
        public async Task Member_with_correct_permissions_cannot_kick_owner(string correctPermission) => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").AddPermission(correctPermission).Build()
                        .CreateMember().AssignRole(1).Build()
                        .Build().Build();

            Func <Task> action = async() => await sut.SendAsync(new KickMemberCommand(group.Member(1).UserId, group.GroupId, group.OwnerId));

            await action.Should().ThrowAsync <InsufficientPermissionsException>();
        });
Example #19
0
        public async Task Member_with_correct_permission_cannot_remove_role_with_same_priority_as_his_highest_one(string correctPermission) => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").AddPermission(correctPermission).Build()
                        .CreateMember().AssignRole(1).Build()
                        .Build().Build();

            Func <Task> action = async() => await sut.SendAsync(new RemoveRoleCommand(group.Member(1).UserId, group.GroupId, group.Role(1).RoleId));

            await action.Should().ThrowAsync <InsufficientPermissionsException>();
        });
        public async Task Fails_when_permission_is_invalid() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").Build()
                        .CreateChannel("channel1").Build()
                        .Build()
                        .Build();

            Func <Task> action = () => sut.SendAsync(new DenyPermissionForRoleCommand(@group.OwnerId, @group.GroupId, @group.Channel(1).ChannelId, @group.Role(1).RoleId, "InvalidPermission"));

            await action.Should().ThrowAsync <PermissionNotFoundException>();
        });
        //[InlineData("ChangeNickname")]
        //[InlineData("ManageNicknames")]
        public async Task Fails_when_permission_cannot_be_overriden(string deniedPermission) => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").Build()
                        .CreateChannel("channel1").Build()
                        .Build()
                        .Build();

            Func <Task> action = () => sut.SendAsync(new DenyPermissionForRoleCommand(@group.OwnerId, @group.GroupId, @group.Channel(1).ChannelId, @group.Role(1).RoleId, deniedPermission));

            await action.Should().ThrowAsync <InvalidPermissionOverride>();
        });
Example #22
0
        public async Task Owner_can_create_channel() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1")
                        .AsOwner()
                        .CreateChannel("channel1").Build()
                        .Build().Build();

            await sut.SendAsync(new RemoveChannelCommand(group.OwnerId, group.GroupId, group.Channel(1).ChannelId));

            var channels = await sut.QueryAsync(new GetGroupChannelsQuery(group.OwnerId, group.GroupId));
            channels.Should().BeNullOrEmpty();
        });
Example #23
0
        public async Task Member_without_valid_permission_cannot_create_channel() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").Build()
                        .CreateMember().AssignRole(1).Build()
                        .Build().Build();

            Func <Task> action = () => sut.SendAsync(new CreateChannelCommand(group.Member(1).UserId, group.GroupId, Guid.NewGuid(), "channel1"));

            await action.Should().ThrowAsync <InsufficientPermissionsException>();
        });
Example #24
0
        public async Task Member_without_correct_permissions_cannot_move_down_role() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").Build()
                        .CreateRole("role2").Build()
                        .CreateMember().Build()
                        .Build().Build();

            Func <Task> action = async() => await sut.SendAsync(new MoveDownRoleInHierarchyCommand(group.Member(1).UserId, group.GroupId, group.Role(1).RoleId));

            await action.Should().ThrowAsync <InsufficientPermissionsException>();
        });
        public async Task Fails_when_role_is_missing_in_given_group() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").Build()
                        .CreateChannel("channel1").Build()
                        .Build()
                        .Build();

            Func <Task> action = () => sut.SendAsync(new DenyPermissionForRoleCommand(@group.OwnerId, @group.GroupId, @group.Channel(1).ChannelId, Guid.NewGuid(), "SendMessages"));

            await action.Should().ThrowAsync <RoleNotFoundException>();
        });
Example #26
0
        public async Task Member_with_correct_permissions_can_kick_member(string correctPermission) => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").AddPermission(correctPermission).Build()
                        .CreateMember().AssignRole(1).Build()
                        .CreateMember().Build()
                        .Build().Build();

            await sut.SendAsync(new KickMemberCommand(group.Member(1).UserId, group.GroupId, group.Member(2).UserId));

            var members = await sut.QueryAsync(new GetMembersQuery(group.OwnerId, group.GroupId, false, group.Member(2).UserId));
            members.Should().BeNullOrEmpty();
        });
Example #27
0
        public async Task Fails_when_member_to_whom_override_is_applied_is_missing_in_given_group() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").Build()
                        .CreateChannel("channel1").Build()
                        .CreateMember().AssignRole(1).Build()
                        .Build()
                        .Build();

            Func <Task> action = () => sut.SendAsync(new AllowPermissionForMemberCommand(@group.OwnerId, @group.GroupId, @group.Channel(1).ChannelId, Guid.NewGuid(), "SendMessages"));

            await action.Should().ThrowAsync <MemberNotFoundException>();
        });
Example #28
0
        public async Task Fails_when_member_has_no_valid_permission() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").Build()
                        .CreateChannel("channel1").Build()
                        .CreateMember().AssignRole(1).Build()
                        .Build()
                        .Build();

            Func <Task> action = () => sut.SendAsync(new AllowPermissionForMemberCommand(@group.Member(1).UserId, @group.GroupId, @group.Channel(1).ChannelId, @group.Member(1).UserId, "ReadMessages"));

            await action.Should().ThrowAsync <InsufficientPermissionsException>();
        });
        public async Task Fails_when_member_with_manage_roles_permission_tries_to_override_manage_roles_permissions() => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut).CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").AddPermission("ManageRoles").Build()
                        .CreateChannel("channel1").Build()
                        .CreateMember().AssignRole(1).Build()
                        .Build()
                        .Build();

            Func <Task> action = () => sut.SendAsync(new DenyPermissionForRoleCommand(@group.Member(1).UserId, @group.GroupId, @group.Channel(1).ChannelId, @group.Role(1).RoleId, "ManageRoles"));

            await action.Should().ThrowAsync <InsufficientPermissionsException>();
        });
Example #30
0
        public async Task Member_with_valid_permissions_can_remove_channel(string validPermission) => await Run(async sut =>
        {
            var group = await GroupBuilder.For(sut)
                        .CreateGroup("group1")
                        .AsOwner()
                        .CreateRole("role1").AddPermission(validPermission).Build()
                        .CreateMember().AssignRole(1).Build()
                        .CreateChannel("channel1").Build()
                        .Build().Build();

            await sut.SendAsync(new RemoveChannelCommand(group.Member(1).UserId, group.GroupId, group.Channel(1).ChannelId));

            var channels = await sut.QueryAsync(new GetGroupChannelsQuery(group.OwnerId, group.GroupId));
            channels.Should().BeNullOrEmpty();
        });