Пример #1
0
        public async Task CreateNewGroupAsync_ShouldCreate_Succesfully()
        {
            var groupOwner = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };

            await this.dbContext.Users.AddAsync(groupOwner);

            await this.dbContext.SaveChangesAsync();

            var result = await this.groupService.CreateNewGroupAsync("Grupa", "Gosho");

            Assert.True(result);

            var actual = await this.dbContext.Groups.SingleOrDefaultAsync(x => x.Creator.UserName == groupOwner.UserName);

            Assert.NotNull(actual);
        }
Пример #2
0
        public async Task GetGroupOwnerAsync_ShouldReturn_CorrectOwner()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };
            var group = new Group()
            {
                Name    = "Group",
                Creator = user
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Groups.AddAsync(group);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.groupService.GetGroupOwnerAsync(group.Name);

            Assert.Equal(user.UserName, actual);
        }
Пример #3
0
        public async Task JoinGroupAsync_ShouldAdd_UserToGroup()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };
            var group = new Group()
            {
                Name = "GroupWhereUserIsMember"
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Groups.AddAsync(group);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.groupService.JoinGroupAsync(group.Name, user.UserName);

            Assert.True(actual);

            var actualUser  = (await this.dbContext.UserGroups.SingleOrDefaultAsync(x => x.User == user)).User;
            var actualGroup = (await this.dbContext.UserGroups.SingleOrDefaultAsync(x => x.User == user)).Group;

            Assert.Equal(user.UserName, actualUser.UserName);
            Assert.Equal(group.Name, actualGroup.Name);
        }
Пример #4
0
        public async Task IsUserMemberOfGroupAsync_ShouldReturn_True()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };
            var group = new Group()
            {
                Name = "GroupWhereUserIsMember"
            };

            group.Members.Add(new UserGroup()
            {
                ConfirmedMember = true,
                Group           = group,
                User            = user
            });

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Groups.AddAsync(group);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.groupService.IsUserMemberOfGroupAsync(group.Name, user.UserName);

            Assert.True(actual);
        }
Пример #5
0
        public async Task LikePostAsync_ShouldAffect_SinglePost()
        {
            var user = new OurTraceUser()
            {
                UserName = "******",
                BirthDate = DateTime.Now,
                Country = "Bulgaria",
                Email = "*****@*****.**",
                NormalizedEmail = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash = "00000",
                Wall = new Wall()
            };

            var post = new Post()
            {
                Content = "Post content",
                Location = user.Wall,
                User = user,
                VisibilityType = PostVisibilityType.FriendsOnly
            };

            await this.dbContext.Users.AddAsync(user);
            await this.dbContext.Posts.AddAsync(post);
            await this.dbContext.SaveChangesAsync();


            var actual = await this.postService.LikePostAsync(user.UserName, post.Id);
            Assert.True(actual);
            Assert.Equal(1, post.Likes.Count);
        }
Пример #6
0
        public async Task MarkNotificationAsSeenAndReturnItAsync_ShouldModify_SingleNotification()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };

            var notification1 = new Notification()
            {
                Content    = "NotificContent",
                Controller = "Group",
                Action     = "Open",
                User       = user,
                ElementId  = "1",
                Seen       = true
            };
            var notification2 = new Notification()
            {
                Id         = "123",
                Content    = "NotificContent2",
                Controller = "Asd",
                Action     = "Dsa",
                User       = user,
                ElementId  = "181904549804dfasd1d9a0s4",
                Seen       = false
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Notifications.AddAsync(notification1);

            await this.dbContext.Notifications.AddAsync(notification2);

            await this.dbContext.SaveChangesAsync();


            var actual = await this.notificationService.MarkNotificationAsSeenAndReturnItAsync(notification2.Id);

            var databaseActualCount = await this.dbContext.Notifications.CountAsync(x => x.Seen == true);

            Assert.Equal(2, databaseActualCount);
            var actualNotification = new Notification()
            {
                Content    = actual.Content,
                Controller = actual.Controller,
                Action     = actual.Action,
                ElementId  = actual.ElementId,
                Seen       = actual.Seen
            };

            AssertExpectedAndActualNotificationProperties(actualNotification, notification2);
        }
Пример #7
0
        public async Task GetUserNotificationsAsync_ShouldReturn_AllNotifications()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };

            var notification1 = new Notification()
            {
                Content    = "NotificContent",
                Controller = "Group",
                Action     = "Open",
                User       = user,
                ElementId  = "1",
                Seen       = true
            };
            var notification2 = new Notification()
            {
                Content    = "NotificContent2",
                Controller = "Asd",
                Action     = "Dsa",
                User       = user,
                ElementId  = "181904549804dfasd1d9a0s4",
                Seen       = false
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Notifications.AddAsync(notification1);

            await this.dbContext.Notifications.AddAsync(notification2);

            await this.dbContext.SaveChangesAsync();


            var actual1 = await this.notificationService.GetUserNotificationsAsync(user.UserName, 1, false);

            Assert.Equal(1, actual1.Count);
            Assert.Equal(notification1.Content, actual1.FirstOrDefault().Content);

            var actual2 = await this.notificationService.GetUserNotificationsAsync(user.UserName, 2, false);

            Assert.Equal(2, actual2.Count);
            Assert.Equal(notification1.Content, actual2.FirstOrDefault().Content);
            Assert.Equal(notification2.Content, actual2.LastOrDefault().Content);

            var actual3 = await this.notificationService.GetUserNotificationsAsync(user.UserName, 2, true);

            Assert.Equal(2, actual3.Count);
            Assert.Equal(notification2.Content, actual3.FirstOrDefault().Content);
            Assert.Equal(notification1.Content, actual3.LastOrDefault().Content);
        }
Пример #8
0
        public async Task GetNewsfeedViewModelAsync_ShouldReturn_ValidModel()
        {
            var user = new OurTraceUser()
            {
                Id                 = "123",
                UserName           = "******",
                FullName           = "Gosho Goshev",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall               = new Wall()
            };
            var user2 = new OurTraceUser()
            {
                Id                 = "1234",
                UserName           = "******",
                FullName           = "Gosho Goshev",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall               = new Wall()
            };

            var follow = new Follow()
            {
                Sender    = user2,
                Recipient = user
            };
            var following = new Follow()
            {
                Sender    = user,
                Recipient = user2
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Users.AddAsync(user2);

            await this.dbContext.Follows.AddAsync(follow);

            await this.dbContext.Follows.AddAsync(following);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.homeService.GetNewsfeedViewModelAsync(user.Id);

            Assert.Equal(user.FullName, actual.FullName);
            Assert.Equal(1, actual.Followers);
            Assert.Equal(1, actual.Following);
        }
Пример #9
0
        public async Task GetMessagesAsync_ShouldReturn_AllMessages()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };
            var user2 = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };

            var message1 = new Message()
            {
                Sender    = user,
                Recipient = user2,
                Content   = "Zdr pesho"
            };
            var message2 = new Message()
            {
                Sender    = user2,
                Recipient = user,
                Content   = "Zdr gosho, az sam"
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Users.AddAsync(user2);

            await this.dbContext.Messages.AddAsync(message1);

            await this.dbContext.Messages.AddAsync(message2);

            await this.dbContext.SaveChangesAsync();


            var actual = await this.messageService.GetMessagesAsync(user.UserName, user2.UserName);

            Assert.Equal(2, actual.Count);
            Assert.Contains(actual, x => x.Content == message1.Content);
            Assert.Contains(actual, x => x.Content == message2.Content);
            Assert.NotEqual(actual.First(), actual.Last());
        }
Пример #10
0
        public async Task IsUserHaveRoleAsync_ShouldReturn_ValidRoles()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };
            var group = new Group()
            {
                Name = "GroupWhereUserIsMember"
            };

            group.Members.Add(new UserGroup()
            {
                ConfirmedMember = true,
                Group           = group,
                User            = user
            });
            group.Admins.Add(new GroupAdmin()
            {
                AdminType = GroupAdminType.Admin,
                User      = user
            });

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Groups.AddAsync(group);

            await this.dbContext.SaveChangesAsync();

            var actual1 = await this.groupService.IsUserHaveRoleAsync(group.Name, user.UserName, "Admin");

            Assert.True(actual1);

            group.Admins.Clear();
            group.Admins.Add(new GroupAdmin()
            {
                AdminType = GroupAdminType.Moderator,
                User      = user
            });
            await this.dbContext.SaveChangesAsync();

            var actual2 = await this.groupService.IsUserHaveRoleAsync(group.Name, user.UserName, "Moderator");

            Assert.True(actual2);
        }
Пример #11
0
        public async Task SendMessageAsync_ShouldSend_CorrectValues()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };
            var user2 = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Users.AddAsync(user2);

            await this.dbContext.SaveChangesAsync();

            var messageExpected = new Message()
            {
                Sender    = user,
                Recipient = user2,
                Content   = "Zdr pesho"
            };

            await this.messageService.SendMessageAsync(user.UserName, user2.UserName, messageExpected.Content);

            var actualCount = await this.dbContext.Messages.CountAsync();

            var actual = await this.dbContext.Messages
                         .Include(x => x.Sender)
                         .Include(x => x.Recipient)
                         .FirstOrDefaultAsync();

            Assert.Equal(1, actualCount);
            Assert.NotNull(actual);
            Assert.Equal(messageExpected.Content, actual.Content);
            Assert.Equal(messageExpected.Sender.UserName, actual.Sender.UserName);
            Assert.Equal(messageExpected.Recipient.UserName, actual.Recipient.UserName);
        }
Пример #12
0
        public async Task SearchForEverythingAsync_ShouldReturn_CorrectValues()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };
            var post = new Post()
            {
                Content = "Qko bace",
                Tags    = new List <string>()
                {
                    "mnogo", "qki", "tagove", "gosho"
                },
                User     = user,
                Location = user.Wall
            };
            var group = new Group()
            {
                Name    = "Goshovata grupa",
                Creator = user,
            };
            var comment = new Comment()
            {
                Content = "Goshov komentar",
                User    = user,
                Post    = post
            };

            post.Comments.Add(comment);
            user.Posts.Add(post);

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Groups.AddAsync(group);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.searchService.SearchForEverythingAsync("gosho", user.UserName);

            Assert.Equal(1, actual.Comments.Count);
            Assert.Equal(1, actual.Groups.Count);
            Assert.Equal(1, actual.Users.Count);
            Assert.Equal(1, actual.Posts.Count);
        }
Пример #13
0
        public async Task AreFriendsWithAsync_ShouldReturn_CorrectValue()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };
            var user2 = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Users.AddAsync(user2);

            await this.dbContext.SaveChangesAsync();

            var actual1 = await this.relationsService.AreFriendsWithAsync(user.UserName, user2.UserName);

            Assert.False(actual1);

            var friendShip = new Friendship()
            {
                Sender     = user,
                Recipient  = user2,
                AcceptedOn = DateTime.Now
            };

            await this.dbContext.Friendships.AddAsync(friendShip);

            await this.dbContext.SaveChangesAsync();

            var actual2 = await this.relationsService.AreFriendsWithAsync(user.UserName, user2.UserName);

            Assert.True(actual2);
        }
Пример #14
0
        public async Task MarkAllNotificationsAsSeenAsync_ShouldModify_AllNotifications()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };

            var notification1 = new Notification()
            {
                Content    = "NotificContent",
                Controller = "Group",
                Action     = "Open",
                User       = user,
                ElementId  = "1",
                Seen       = true
            };
            var notification2 = new Notification()
            {
                Content    = "NotificContent2",
                Controller = "Asd",
                Action     = "Dsa",
                User       = user,
                ElementId  = "181904549804dfasd1d9a0s4",
                Seen       = false
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Notifications.AddAsync(notification1);

            await this.dbContext.Notifications.AddAsync(notification2);

            await this.dbContext.SaveChangesAsync();


            await this.notificationService.MarkAllNotificationsAsSeenAsync(user.UserName);

            var actual = (await this.dbContext.Notifications.ToListAsync())
                         .Select(x => x.Seen)
                         .ToList();

            Assert.All(actual, x => x = true);
        }
Пример #15
0
        public async Task RevokeFriendshipAsync_ShouldDelete_SingleFriendship()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };
            var user2 = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };

            var friendship = new Friendship()
            {
                Sender     = user,
                Recipient  = user2,
                AcceptedOn = DateTime.Now
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Users.AddAsync(user2);

            await this.dbContext.Friendships.AddAsync(friendship);

            await this.dbContext.SaveChangesAsync();

            await this.relationsService.RevokeFriendshipAsync(user.UserName, user2.UserName);

            var actual = await this.dbContext.Friendships.CountAsync();

            Assert.Equal(0, actual);
        }
Пример #16
0
        public async Task DiscoverGroupsAsync_ShouldReturn_NotJoinedGroup()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };
            var group1 = new Group()
            {
                Name = "GroupWhereUserIsMember"
            };

            group1.Members.Add(new UserGroup()
            {
                ConfirmedMember = true,
                Group           = group1,
                User            = user
            });

            var group2 = new Group()
            {
                Name = "GroupWhereUserIsNotMember"
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Groups.AddAsync(group1);

            await this.dbContext.Groups.AddAsync(group2);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.groupService.DiscoverGroupsAsync("Gosho");

            Assert.True(actual.Count() == 1);

            var actualGroupName = actual.ToList().First().Name;

            Assert.Equal(group2.Name, actualGroupName);
        }
Пример #17
0
        public async Task PrepareGroupForViewAsync_ShouldReturn_ValidView()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };
            var group = new Group()
            {
                Name = "GroupWhereUserIsMember"
            };

            group.Members.Add(new UserGroup()
            {
                ConfirmedMember = true,
                Group           = group,
                User            = user
            });
            group.Admins.Add(new GroupAdmin()
            {
                AdminType = GroupAdminType.Admin,
                Group     = group,
                User      = user
            });
            group.Creator = user;

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Groups.AddAsync(group);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.groupService.PrepareGroupForViewAsync(group.Name, user.UserName);

            Assert.True(actual.IsUserConfirmed);
            Assert.True(actual.IsAdministrator);
            Assert.True(actual.IsOwner);
            Assert.True(actual.Members.Count == 1);
            Assert.Equal(group.Name, actual.Name);
        }
Пример #18
0
        public async Task RevokeFollowingAsync_ShouldDelete_CorrectValue()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };
            var user2 = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };

            var follow = new Follow()
            {
                Sender    = user,
                Recipient = user2
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Users.AddAsync(user2);

            await this.dbContext.Follows.AddAsync(follow);

            await this.dbContext.SaveChangesAsync();

            await this.relationsService.RevokeFollowingAsync(user.UserName, user2.UserName);

            var actual = user.Following.Count;

            Assert.Equal(0, actual);
        }
Пример #19
0
        public async Task AddNotificationToUserAsync_ShouldAdd_Successfully()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.SaveChangesAsync();

            var notificationModel = new NotificationServiceModel()
            {
                Content    = "NotificContent",
                Controller = "Group",
                Action     = "Open",
                Username   = user.UserName,
                ElementId  = "1"
            };

            await this.notificationService.AddNotificationToUserAsync(notificationModel);

            var expectedNotification = new Notification()
            {
                Content    = "NotificContent",
                Controller = "Group",
                Action     = "Open",
                User       = user,
                ElementId  = "1",
                Seen       = false
            };
            var actualNotificatiionsCount = await this.dbContext.Notifications.CountAsync();

            var actualNotificatiion = await this.dbContext.Notifications.FirstOrDefaultAsync();

            Assert.Equal(1, actualNotificatiionsCount);
            AssertExpectedAndActualNotificationProperties(expectedNotification, actualNotificatiion);
        }
Пример #20
0
        public async Task GetLastNPicturesAsync_ShouldReturn_ValidView()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };
            var post = new Post()
            {
                Content  = "post",
                User     = user,
                Location = user.Wall,
                MediaUrl = "expectedExternalMediaUrl"
            };
            var post2 = new Post()
            {
                Content             = "post2",
                User                = user,
                Location            = user.Wall,
                MediaUrl            = "invalidInternalMediaUrl",
                IsImageOnFileSystem = true
            };

            user.Posts.Add(post);
            user.Posts.Add(post2);

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.userService.GetLastNPicturesAsync(user.UserName, 5);

            Assert.Equal(1, actual.InternalIds.Count);
            Assert.Equal(1, actual.ExternalUrls.Count);
        }
Пример #21
0
        public async Task PrepareUserProfileForViewAsync_ShouldReturn_ValidView()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };
            var post = new Post()
            {
                Content  = "post",
                User     = user,
                Location = user.Wall
            };
            var comment = new Comment()
            {
                Content = "Gosho komentira",
                User    = user,
                Post    = post
            };

            post.Comments.Add(comment);
            user.Posts.Add(post);

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.userService.PrepareUserProfileForViewAsync(user.UserName, user.UserName);

            Assert.True(actual.IsHimself);
            Assert.Equal(0, actual.FriendsCount);
            Assert.Equal(user.UserName, actual.Username);
            Assert.Equal(1, actual.Posts.Count);
            Assert.Equal(1, actual.Posts.First().Comments.Count);
        }
Пример #22
0
        public async Task CommentPostAsync_ShouldCreate_SingleComment()
        {
            var user = new OurTraceUser()
            {
                UserName = "******",
                BirthDate = DateTime.Now,
                Country = "Bulgaria",
                Email = "*****@*****.**",
                NormalizedEmail = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash = "00000",
                Wall = new Wall()
            };

            var post = new Post()
            {
                Content = "Post content",
                Location = user.Wall,
                User = user,
                VisibilityType = PostVisibilityType.FriendsOnly
            };

            await this.dbContext.Users.AddAsync(user);
            await this.dbContext.Posts.AddAsync(post);
            await this.dbContext.SaveChangesAsync();

            var comment = new Comment()
            {
                Content = "zadara",
                Post = post,
                User = user,
            };

            var expectedString = "zadara";
            var actualBool = await this.postService.CommentPostAsync(user.UserName, post.Id, expectedString);
            Assert.True(actualBool);

            var actualString = post.Comments.FirstOrDefault().Content;
            Assert.Equal(expectedString, actualString);
        }
Пример #23
0
        public async Task SearchForCommentsAsync_ShouldReturn_CorrectValues()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };
            var post = new Post()
            {
                Content  = "post",
                User     = user,
                Location = user.Wall
            };

            var comment = new Comment()
            {
                Content = "Gosho komentira",
                User    = user,
                Post    = post
            };

            post.Comments.Add(comment);
            user.Posts.Add(post);

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.searchService.SearchForCommentsAsync("komentira", "Gosho");

            Assert.Equal(1, actual.Values.Count);
            Assert.Equal(user.UserName, actual.Values.First().Content);
            Assert.Equal(comment.Content, actual.Values.First().DescriptiveContent);
        }
Пример #24
0
        public async Task AddFriendshipAsync_ShouldAdd_SingleValue()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };
            var user2 = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };


            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Users.AddAsync(user2);

            await this.dbContext.SaveChangesAsync();

            await this.relationsService.AddFriendshipAsync(user.UserName, user2.UserName);

            var actual = await this.dbContext.Friendships.SingleOrDefaultAsync();

            Assert.Equal(user, actual.Sender);
            Assert.Equal(user2, actual.Recipient);
            Assert.Null(actual.AcceptedOn);
        }
Пример #25
0
        public async Task CreateNewPostAsync_ShouldAdd_SingleNewPost()
        {
            var user = new OurTraceUser()
            {
                UserName = "******",
                BirthDate = DateTime.Now,
                Country = "Bulgaria",
                Email = "*****@*****.**",
                NormalizedEmail = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash = "00000",
                Wall = new Wall()
            };
            await this.dbContext.Users.AddAsync(user);
            await this.dbContext.SaveChangesAsync();

            var postInputModel = new CreatePostInputModel()
            {
                Content = "Post content",
                IsGroupPost = false,
                Location = user.Wall.Id,
                VisibilityType = PostVisibilityType.FriendsOnly
            };

            var actual = await this.postService.CreateNewPostAsync(user.UserName, postInputModel, false);
            Assert.True(actual);

            var actualPostCount = await this.dbContext.Posts.CountAsync();
            var actualPost = await this.dbContext.Posts
                .Include(x => x.User)
                .SingleOrDefaultAsync();

            Assert.Equal(1, actualPostCount);
            Assert.NotNull(actualPost);
            Assert.Equal(user.UserName, actualPost.User.UserName);
            Assert.Equal(postInputModel.Content, actualPost.Content);
            Assert.Equal(postInputModel.VisibilityType, actualPost.VisibilityType);
            Assert.Equal(postInputModel.Location, actualPost.LocationId);
        }
Пример #26
0
        public async Task UserExistsAsync_ShouldReturn_ValidResult()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.userService.UserExistsAsync(user.UserName);

            Assert.True(actual);
        }
Пример #27
0
        public async Task GetUserIdFromName_ShouldReturn_ValidId()
        {
            var user = new OurTraceUser()
            {
                Id                 = "ShouldReturnThis",
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.homeService.GetUserIdFromName(user.UserName);

            Assert.Equal(user.Id, actual);
        }
Пример #28
0
        public async Task SearchForPostsAsync_ShouldReturn_CorrectValues()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };
            var post = new Post()
            {
                Content = "Qko bace",
                Tags    = new List <string>()
                {
                    "mnogo", "qki", "tagove"
                },
                User     = user,
                Location = user.Wall
            };

            user.Posts.Add(post);

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.SaveChangesAsync();

            var actual1 = await this.searchService.SearchForPostsAsync("bace", user.UserName);

            Assert.Equal(1, actual1.Values.Count);
            Assert.Equal(user.UserName, actual1.Values.First().Content);

            var actual2 = await this.searchService.SearchForPostsAsync("tagove", user.UserName);

            Assert.Equal(1, actual2.Values.Count);
        }
Пример #29
0
        public async Task AcceptMemberAsync_ShouldAccept_PendingMember()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000"
            };
            var group = new Group()
            {
                Name = "GroupWhereUserIsMember"
            };

            group.Members.Add(new UserGroup()
            {
                ConfirmedMember = false,
                Group           = group,
                User            = user
            });

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.Groups.AddAsync(group);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.groupService.AcceptMemberAsync(group.Name, user.UserName);

            Assert.True(actual);

            var actualUserGroup = (await this.dbContext.UserGroups.SingleOrDefaultAsync(x => x.User == user));

            Assert.True(actualUserGroup.ConfirmedMember);
        }
Пример #30
0
        public async Task SearchForUsersAsync_ShouldReturn_CorrectValues()
        {
            var user = new OurTraceUser()
            {
                UserName           = "******",
                BirthDate          = DateTime.Now,
                Country            = "Bulgaria",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******",
                PasswordHash       = "00000",
                Wall = new Wall()
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.SaveChangesAsync();

            var actual = await this.searchService.SearchForUsersAsync("gos");

            Assert.Equal(1, actual.Values.Count);
            Assert.Equal(user.UserName, actual.Values.First().Content);
        }