public async Task FollowShouldCreateUserDiaryEntityInDatabase()
        {
            //arrange

            var diary = new GetShreddedDiary
            {
                Id      = 1,
                User    = null,
                Summary = "Summary",
                Title   = "Title"
            };

            var user = new GetShreddedUser
            {
                Id       = "UserId",
                UserName = "******",
            };

            this.Context.GetShreddedDiaries.Add(diary);

            var usermanager = this.Provider.GetRequiredService <UserManager <GetShreddedUser> >();
            await usermanager.CreateAsync(user);

            this.Context.SaveChanges();

            //act
            var diaryService = GetService();

            var diaryId  = diary.Id;
            var username = user.UserName;
            var userId   = user.Id;
            await diaryService.Follow(username, userId, diaryId);

            //assert

            var result = this.Context.GetShreddedUserDiaries.FirstOrDefault();

            var userDiary = new GetShreddedUserDiary
            {
                GetShreddedUserId  = user.Id,
                GetShreddedDiaryId = diary.Id
            };

            result.Should().BeOfType <GetShreddedUserDiary>().And.Subject.Should().Equals(userDiary);
        }
Beispiel #2
0
        public async Task Follow(string username, string userId, int id)
        {
            var userDiary = new GetShreddedUserDiary()
            {
                GetShreddedDiaryId = id,
                GetShreddedUserId  = userId
            };

            bool followed = IsFollowed(userId, id);

            if (followed)
            {
                throw new InvalidOperationException(string.Join(GlobalConstants.AlreadyFollow, username));
            }

            this.Context.GetShreddedUserDiaries.Add(userDiary);
            await this.Context.SaveChangesAsync();
        }
        public void AddNotificationShouldSendToAllFollowersNotificationForNewPage()
        {
            //arrange
            var notificationUserOne = new GetShreddedUser
            {
                Id       = "OneId",
                UserName = "******"
            };

            var notificationUserTwo = new GetShreddedUser
            {
                Id       = "TwoId",
                UserName = "******"
            };

            var diary = new GetShreddedDiary
            {
                Title     = "One",
                Id        = 1,
                CreatedOn = DateTime.Now,
                Summary   = null,
                Type      = new DiaryType
                {
                    Id   = 1,
                    Name = "Cutting"
                },

                UserId = "1111",
            };

            var userDiaryOne = new GetShreddedUserDiary
            {
                GetShreddedUserId = notificationUserOne.Id,

                GetShreddedDiaryId = diary.Id
            };

            var userDiaryTwo = new GetShreddedUserDiary
            {
                GetShreddedUserId = notificationUserTwo.Id,

                GetShreddedDiaryId = diary.Id
            };

            diary.Followers.Add(userDiaryOne);
            diary.Followers.Add(userDiaryTwo);

            userManager.CreateAsync(notificationUserOne).GetAwaiter().GetResult();
            userManager.CreateAsync(notificationUserTwo).GetAwaiter().GetResult();
            this.Context.GetShreddedDiaries.Add(diary);
            this.Context.GetShreddedUserDiaries.Add(userDiaryOne);
            this.Context.GetShreddedUserDiaries.Add(userDiaryTwo);
            this.Context.SaveChanges();

            //act
            int    diaryId    = diary.Id;
            string diaryTitle = diary.Title;

            this.notificationService.AddNotification(diaryId, null, diaryTitle);

            //assert
            var result = this.Context.GetShreddedUserDiaries.ToList();

            result.Should().NotBeEmpty().And.HaveCount(2);
            result[0].GetShreddedUser.Should().BeEquivalentTo(notificationUserOne);
            result[1].GetShreddedUser.Should().BeEquivalentTo(notificationUserTwo);
        }