Exemplo n.º 1
0
        public async Task CreateGroup()
        {
            var group = await groupsRepo.CreateGroupAsync("CourseId", "GroupName", Guid.NewGuid().ToString()).ConfigureAwait(false);

            Assert.AreEqual(1, db.Groups.Count(), "Groups count should be equal to 1 after adding new group");

            Assert.AreEqual(group, await groupsRepo.FindGroupByIdAsync(group.Id).ConfigureAwait(false));

            Assert.AreEqual(false, group.IsArchived);
            Assert.AreEqual(false, group.IsDeleted);
            Assert.AreEqual(0, group.Members?.Count ?? 0);
            Assert.AreNotEqual(Guid.Empty, group.InviteHash);
            Assert.That(group.CreateTime, Is.EqualTo(DateTime.Now).Within(5).Seconds);
        }
Exemplo n.º 2
0
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var groupId = (int)context.ActionArguments["groupId"];

            var group = await groupsRepo.FindGroupByIdAsync(groupId).ConfigureAwait(false);

            if (group == null)
            {
                context.Result = NotFound();
                return;
            }

            var isAvailable = await groupAccessesRepo.IsGroupAvailableForUserAsync(group, User).ConfigureAwait(false);

            if (!isAvailable)
            {
                context.Result = Forbid();
                return;
            }

            context.ActionArguments["group"] = group;

            await next().ConfigureAwait(false);
        }