コード例 #1
0
        public void DeleteFriendshipRemovesRequest()
        {
            User randomUser;
            User randomFriend;

            using (var scope = new UserTestScope())
            {
                randomUser   = scope.RandomUserNotPersisted();
                randomFriend = scope.RandomUserNotPersisted();

                scope.UserAccountDomain.CreateAccount(randomUser).Wait();
                scope.UserAccountDomain.CreateAccount(randomFriend).Wait();
                var details = scope.UserAccountDomain.UpdateFriendship(randomFriend.Username, randomUser, false).Result;
            }
            using (var scope = new UserTestScope())
            {
                Assert.NotEmpty(scope.UserAccountDomain.RetrieveFriends(randomUser).Result);

                var details = scope.UserAccountDomain.UpdateFriendship(randomFriend.Username, randomUser, true).Result;
                Assert.NotNull(details);
                Assert.Equal(randomFriend.Username, details.RecipientUsername);
                Assert.Equal(randomUser.Username, details.SenderUsername);
                Assert.Empty(scope.UserAccountDomain.RetrieveFriends(randomUser).Result);
            }
        }
コード例 #2
0
        public void AddFriendshipNoNewUnfriend(bool unfriend)
        {
            User randomUser;
            User randomFriend;

            using (var scope = new UserTestScope())
            {
                randomUser   = scope.RandomUserNotPersisted();
                randomFriend = scope.RandomUserNotPersisted();

                string password       = randomUser.Password;
                string friendPassword = randomFriend.Password;
                scope.UserAccountDomain.CreateAccount(randomUser).Wait();
                scope.UserAccountDomain.CreateAccount(randomFriend).Wait();

                randomUser.Password   = password; //gets overwritten as the hashed value during acct create
                randomFriend.Password = friendPassword;
            }
            using (var scope = new UserTestScope())
            {
                if (unfriend)
                {
                    Assert.ThrowsAsync <CritterException>(() => scope.UserAccountDomain.UpdateFriendship(randomFriend.Username, randomUser, true));
                }
                else
                {
                    var details = scope.UserAccountDomain.UpdateFriendship(randomFriend.Username, randomUser, unfriend).Result;
                    Assert.NotNull(details);
                    Assert.Equal(randomFriend.Username, details.RecipientUsername);
                    Assert.Equal(randomUser.Username, details.SenderUsername);
                    Assert.False(details.Friendship.Accepted);
                }
            }
        }
コード例 #3
0
        public void UserAccountCreateAndRetrieveWorks()
        {
            using (var scope = new UserTestScope())
            {
                User   randomUser = scope.RandomUserNotPersisted();
                string jwt        = scope.UserAccountDomain.CreateAccount(randomUser).Result;

                var retrievedDbUser = scope.UserAccountDomain.RetrieveUserByEmail(randomUser.EmailAddress).Result;
                Assert.Equal(randomUser.Username, retrievedDbUser.Username);
                Assert.NotEmpty(jwt);
            }
        }
コード例 #4
0
        public void SelfFriendshipFails(bool unfriend)
        {
            User randomUser;

            using (var scope = new UserTestScope())
            {
                randomUser = scope.RandomUserNotPersisted();
                string password = randomUser.Password;

                scope.UserAccountDomain.CreateAccount(randomUser).Wait();
                randomUser.Password = password; //gets overwritten as the hashed value during acct create
            }
            using (var scope = new UserTestScope())
            {
                Assert.ThrowsAsync <CritterException>(() => scope.UserAccountDomain.UpdateFriendship(randomUser.Username, randomUser, unfriend));
            }
        }
コード例 #5
0
        public void DeleteFriendshipRemovesFriend()
        {
            User randomUser;
            User randomFriend;

            using (var scope = new UserTestScope())
            {
                randomUser   = scope.RandomUserNotPersisted();
                randomFriend = scope.RandomUserNotPersisted();

                scope.UserAccountDomain.CreateAccount(randomUser).Wait();
            }
            using (var scope = new UserTestScope())
            {
                scope.UserAccountDomain.CreateAccount(randomFriend).Wait();
            }
            using (var scope = new UserTestScope())
            {
                var details = scope.UserAccountDomain.UpdateFriendship(randomFriend.Username, randomUser, false).Result;
            }

            using (var scope = new UserTestScope())
            {
                Assert.True(scope.UserAccountDomain.UpdateFriendship(randomUser.Username, randomFriend, false).Result.Friendship.Accepted);
            }
            using (var scope = new UserTestScope())
            {
                var friends = scope.UserAccountDomain.RetrieveFriends(randomFriend).Result;
                Assert.True(friends.First(x => x.Friendship.SenderUserId == randomUser.Id).Friendship.Accepted);//db check
            }

            using (var scope = new UserTestScope())
            {
                Assert.NotEmpty(scope.UserAccountDomain.RetrieveFriends(randomUser).Result);

                var details = scope.UserAccountDomain.UpdateFriendship(randomUser.Username, randomFriend, true).Result;
                Assert.NotNull(details);
            }
            using (var scope = new UserTestScope())
            {
                Assert.Empty(scope.UserAccountDomain.RetrieveFriends(randomFriend).Result);
            }
        }
コード例 #6
0
        public void DuplicateCreateFails()
        {
            User randomUser;

            using (var scope = new UserTestScope())
            {
                randomUser = scope.RandomUserNotPersisted();
                string password = randomUser.Password;

                scope.UserAccountDomain.CreateAccount(randomUser).Wait();
                randomUser.Password = password; //gets overwritten as the hashed value during acct create
                string jwt = scope.UserAccountDomain.Login(randomUser).Result;
                Assert.NotEmpty(jwt);
                Assert.True(scope.JWTProvider.ValidateToken(jwt));
            }
            using (var scope = new UserTestScope())
            {
                Assert.ThrowsAsync <CritterException>(() => scope.UserAccountDomain.CreateAccount(randomUser));
            }
        }
コード例 #7
0
        public void UserLoginWorksAndCreatesValidJwt()
        {
            User randomUser;

            using (var scope = new UserTestScope())
            {
                randomUser = scope.RandomUserNotPersisted();
                string password = randomUser.Password;

                scope.UserAccountDomain.CreateAccount(randomUser).Wait();
                randomUser.Password = password; //gets overwritten as the hashed value during acct create
            }

            using (var scope = new UserTestScope())
            {
                string jwt = new UserTestScope().UserAccountDomain.Login(randomUser).Result;

                Assert.NotEmpty(jwt);
                Assert.True(scope.JWTProvider.ValidateToken(jwt));
            }
        }