public void TryToInviteTeacherToGroupWithApprovedTeacher_GetException()
        {
            //Arrange
            var publisher   = new Mock <IEventPublisher>();
            var groupFacade = new GroupFacade(_groupRepository, _userRepository, _sanctionRepository,
                                              new GroupSettings(1, 100, 0, 1000), publisher.Object);
            var accountFacade = new AccountFacade(_keysRepository,
                                                  _userRepository, _emailSender.Object, userSettings);
            var userFacade = new UserFacade(_userRepository, _groupRepository, _eventRepository, _publisher.Object);

            var creatorId        = accountFacade.RegUser("Creator", new Credentials("email1", "password"), false);
            var teacherId        = accountFacade.RegUser("Teacher", new Credentials("email2", "password"), true);
            var anotherTeacherId =
                accountFacade.RegUser("Another teacher", new Credentials("email3", "password"), true);

            var createdGroupId = groupFacade.CreateGroup(creatorId, "Some group", new List <string> {
                "c#"
            },
                                                         "Very interesting", 1, 100, false, GroupType.Lecture);
            var createdGroup = groupFacade.GetGroup(createdGroupId, creatorId);

            groupFacade.ApproveTeacher(userFacade.GetUser(teacherId).Id, createdGroupId);

            //Act
            userFacade.Invite(creatorId, anotherTeacherId, createdGroupId, MemberRole.Teacher);
        }
        public async Task <ActionResult> Create(GroupDto group)
        {
            group.Picture = "/Img/default.jpg";
            var newGroupId = await GroupFacade.CreateGroup(Guid.Empty, group, true);

            return(RedirectToAction("Details", new { id = newGroupId }));
        }
        public void TryToInviteUserWithTeacherFlag_IsItPossible()
        {
            //Arrange
            var publisher   = new Mock <IEventPublisher>();
            var groupFacade = new GroupFacade(_groupRepository, _userRepository, _sanctionRepository,
                                              new GroupSettings(1, 100, 0, 1000), publisher.Object);
            var accountFacade = new AccountFacade(_keysRepository,
                                                  _userRepository, _emailSender.Object, userSettings);
            var userFacade = new UserFacade(_userRepository, _groupRepository, _eventRepository, _publisher.Object);

            var creatorId =
                accountFacade.RegUser("Creator", new Credentials("email1", "password"), false);
            var teacherId =
                accountFacade.RegUser("Teacher", new Credentials("email2", "password"), true);

            var createdGroupId = groupFacade.CreateGroup(creatorId, "Some group",
                                                         new List <string> {
                "c#"
            }, "Very interesting", 1, 100, false, GroupType.Lecture);

            //Act
            userFacade.Invite(creatorId, teacherId, createdGroupId, MemberRole.Teacher);
            var invitations = userFacade.GetAllInvitationsForUser(teacherId).ToList();

            //Assert
            Assert.AreEqual(createdGroupId, invitations[0].ToGroup);
        }
        public void TryToAcceptTeacherInvitationWithAlreadyFoundTeacher_GetException()
        {
            //Arrange
            var publisher   = new Mock <IEventPublisher>();
            var groupFacade = new GroupFacade(_groupRepository, _userRepository, _sanctionRepository,
                                              new GroupSettings(1, 100, 0, 1000), publisher.Object);
            var accountFacade = new AccountFacade(_keysRepository, _userRepository, _emailSender.Object,
                                                  userSettings);
            var userFacade = new UserFacade(_userRepository, _groupRepository, _eventRepository, _publisher.Object);

            var creatorId    = accountFacade.RegUser("Creator", new Credentials("email1", "password"), false);
            var teacherId    = accountFacade.RegUser("Teacher", new Credentials("email2", "password"), true);
            var newTeacherId = accountFacade.RegUser("Teacher", new Credentials("email3", "password"), true);

            var createdGroupId = groupFacade.CreateGroup(creatorId, "Some group",
                                                         new List <string> {
                "c#"
            }, "Very interesting", 1, 100, false, GroupType.Lecture);

            userFacade.Invite(creatorId, newTeacherId, createdGroupId, MemberRole.Teacher);
            var invitation = userFacade.GetAllInvitationsForUser(newTeacherId).ToList()[0];

            //Act
            groupFacade.ApproveTeacher(teacherId, createdGroupId);
            userFacade.ChangeInvitationStatus(newTeacherId, invitation.Id, InvitationStatus.Accepted);
        }
        public void AcceptUserInvitation_GetAddedUserToGroup()
        {
            //Arrange
            var publisher   = new Mock <IEventPublisher>();
            var groupFacade = new GroupFacade(_groupRepository, _userRepository, _sanctionRepository,
                                              new GroupSettings(1, 100, 0, 1000), publisher.Object);
            var accountFacade = new AccountFacade(_keysRepository, _userRepository, _emailSender.Object,
                                                  userSettings);
            var userFacade = new UserFacade(_userRepository, _groupRepository, _eventRepository, _publisher.Object);

            var creatorId = accountFacade.RegUser("Creator", new Credentials("email1", "password"), false);
            var invitedId = accountFacade.RegUser("Teacher", new Credentials("email2", "password"), true);

            var createdGroupId = groupFacade.CreateGroup(creatorId, "Some group",
                                                         new List <string> {
                "c#"
            }, "Very interesting", 3, 100, false, GroupType.Lecture);

            userFacade.Invite(creatorId, invitedId, createdGroupId, MemberRole.Member);
            var invitation = userFacade.GetAllInvitationsForUser(invitedId).ToList()[0];

            //Act
            userFacade.ChangeInvitationStatus(invitedId, invitation.Id, InvitationStatus.Accepted);

            //Assert
            var createdGroup = _groupRepository.GetGroupById(createdGroupId);

            Assert.AreEqual(2, createdGroup.Members.Count);
        }
        public async Task <ActionResult> Create(GroupDto group)
        {
            var user = await CharacterFacade.GetCharacterById(Guid.Parse(User.Identity.Name));

            if (user.GroupId != null)
            {
                return(RedirectToAction("NotAuthorized", "Error"));
            }
            group.Picture = "/Img/default.jpg";
            var newGroupId = await GroupFacade.CreateGroup(Guid.Parse(User.Identity.Name), group);

            return(RedirectToAction("Details", new { id = newGroupId }));
        }
        public void TryToGetAllGroupsOfUser_ReturnRightResult()
        {
            //Arrange
            var accountFacade = new AccountFacade(_keysRepository,
                                                  _userRepository, _emailSender.Object, userSettings);
            var userFacade  = new UserFacade(_userRepository, _groupRepository, _eventRepository, _publisher.Object);
            var publisher   = new Mock <IEventPublisher>();
            var groupFacade = new GroupFacade(_groupRepository, _userRepository, _sanctionRepository,
                                              new GroupSettings(2, 10, 0, 100), publisher.Object);

            var testUserId =
                accountFacade.RegUser("Alena", new Credentials("email1", "password"), true);
            var creatorId = accountFacade.RegUser("Galya", new Credentials("email2", "password"), true);

            var createdGroupId1 = groupFacade.CreateGroup(creatorId, "Group1", new List <string> {
                "c#"
            }, "Good group", 5,
                                                          0, false, GroupType.MasterClass);
            var createdGroupId2 = groupFacade.CreateGroup(creatorId, "Group2", new List <string> {
                "c#"
            },
                                                          "The best group!", 7, 0, true, GroupType.Seminar);

            var createdGroup1 = groupFacade.GetGroup(createdGroupId1, creatorId);
            var createdGroup2 = groupFacade.GetGroup(createdGroupId2, creatorId);

            //Act
            groupFacade.AddMember(createdGroup1.GroupInfoView.GroupId, testUserId);
            groupFacade.AddMember(createdGroup2.GroupInfoView.GroupId, testUserId);
            var expected = new List <FullGroupView> {
                createdGroup1, createdGroup2
            };
            var groups = userFacade.GetAllGroupsOfUser(testUserId).ToList();

            //Assert
            Assert.AreEqual(groups.Count, expected.Count);
        }
Esempio n. 8
0
        public void Initialize()
        {
            var keyRepository = new InMemoryKeysRepository();

            _userRepository = new InMemoryUserRepository();
            var sanctionRepository = new InMemorySanctionRepository();

            _groupRepository = new InMemoryGroupRepository();
            var publisher     = new Mock <IEventPublisher>();
            var groupSettings = new GroupSettings(3, 100, 100, 1000);
            var sender        = new Mock <IEmailSender>();
            var groupFacade   = new GroupFacade(_groupRepository, _userRepository, sanctionRepository, groupSettings,
                                                publisher.Object);

            userSettings = new UserSettings("");
            var accountFacade = new AccountFacade(keyRepository, _userRepository,
                                                  sender.Object, userSettings);

            _creatorId   = accountFacade.RegUser("Alena", Credentials.FromRawData("email", "password"), true);
            _testGroupId = groupFacade.CreateGroup(_creatorId, "Some group", new List <string> {
                "c#"
            }, "Interesting",
                                                   3, 100, false, GroupType.Lecture);
        }