Beispiel #1
0
        private async Task SeedTraderFollowers()
        {
            var trader = new TraderDto {
                IqOptionAccountDto = new IqOptionAccountDto {
                    IqOptionUserId   = 31773196,
                    Password         = "******",
                    IqOptionUserName = "******"
                }
            };

            if (_context.IqOptionUsers.Find(trader.IqOptionAccountDto.Id) == null)
            {
                trader.IqOptionAccountDto.User =
                    await _userManager.FindByEmailAsync(trader.IqOptionAccountDto.IqOptionUserName);

                _context.IqOptionUsers.Add(trader.IqOptionAccountDto);
            }


            var follower = new FollowerDto {
                IqOptionAccountDto = new IqOptionAccountDto {
                    IqOptionUserId   = 21853876,
                    Password         = "******",
                    IqOptionUserName = "******"
                }
            };

            if (_context.IqOptionUsers.Find(follower.IqOptionAccountDto.Id) == null)
            {
                follower.IqOptionAccountDto.User =
                    await _userManager.FindByEmailAsync(follower.IqOptionAccountDto.IqOptionUserName);

                _context.IqOptionUsers.Add(follower.IqOptionAccountDto);
            }
        }
Beispiel #2
0
        public async Task GetFollowsByUserIdAsync_Should_Pass()
        {
            // Arrange
            FollowerDto followerDto1 = new FollowerDto
            {
                UserId         = 1,
                FollowerUserId = 2
            };
            FollowerDto followerDto2 = new FollowerDto
            {
                UserId         = 3,
                FollowerUserId = 2
            };
            FollowerDto followerDto3 = new FollowerDto
            {
                UserId         = 4,
                FollowerUserId = 2
            };
            await FollowerService.FollowUserAsync(followerDto1);

            await FollowerService.FollowUserAsync(followerDto2);

            await FollowerService.FollowUserAsync(followerDto3);

            // Act
            List <Follower> follows = (await FollowerRepository.FindManyByExpressionAsync(follower => follower.FollowerUserId.Equals(2))).ToList();

            // Assert
            Assert.IsTrue(follows.All(follower => follower.UserId.Equals(1) || follower.UserId.Equals(3) || follower.UserId.Equals(4)));
        }
Beispiel #3
0
        public async Task <ServiceResponseDto> FollowUserAsync(FollowerDto followerDto)
        {
            ServiceResponseDto followResultDto = new ServiceResponseDto();
            Follower           follower        = DtoToEntityConverter.Convert <Follower, FollowerDto>(followerDto);

            if (!await _applicationUserRepository.ExistsAsync(user => user.Id.Equals(followerDto.UserId)))
            {
                followResultDto.Message = "The user does not exist.";
                return(followResultDto);
            }

            if (!await _applicationUserRepository.ExistsAsync(user => user.Id.Equals(followerDto.FollowerUserId)))
            {
                followResultDto.Message = "The follower user does not exist.";
                return(followResultDto);
            }

            string username = (await _applicationUserRepository.FindSingleByExpressionAsync(user => user.Id.Equals(followerDto.UserId))).UserName;

            if (await _followerRepository.ExistsAsync(follow => follow.UserId.Equals(followerDto.UserId) && follow.FollowerUserId.Equals(followerDto.FollowerUserId)))
            {
                followResultDto.Message = $"You already follow {username}";
                return(followResultDto);
            }

            if (await _followerRepository.CreateAsync(follower))
            {
                followResultDto.Success = true;
                followResultDto.Message = $"Successfully followed {username}";
                return(followResultDto);
            }

            followResultDto.Message = "Something happened try again later..";
            return(followResultDto);
        }
Beispiel #4
0
        public async Task <FollowerDto> Create(FollowerDto dto)
        {
            // Obtenemos la entidad follower para un usuario y un follower
            var follower = await _context.Followers.FindAsync(dto.UserId, dto.FollowerId);

            // Comprobamos si ya un usuario ya sigue a otro usuario
            if (follower != null)
            {
                throw new NotFoundException("Ya sigues a este usuario");
            }

            // Comprobamos si se pretende seguir un usuario a si mismo
            if (dto.UserId == dto.FollowerId)
            {
                throw new NotFoundException("No puedes seguirte a ti mismo");
            }

            // Mapeamos el dto a la entidad, la añadimos al contexto, guardamos y devolvemos el dto de followers
            var model = _mapper.Map <Follower>(dto);

            _context.Followers.Add(model);
            await _context.SaveChangesAsync();

            return(_mapper.Map <FollowerDto>(model));
        }
        private void AssertFollower(FollowerDto follower)
        {
            Assert.That(follower.Name, Is.Not.Null.Or.Empty);
            Assert.That(follower.Portrait, Is.Not.Null.Or.Empty);
            Assert.That(follower.RealName, Is.Not.Null.Or.Empty);
            Assert.That(follower.Slug, Is.Not.Null.Or.Empty);

            Assert.IsNotEmpty(follower.Skills);
            foreach (var skill in follower.Skills)
            {
                AssertSkill(skill);
            }
        }
Beispiel #6
0
        public async Task <IActionResult> UnFollowAsync([FromBody] UnFollowViewModel unFollowViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ModelState.DefaultInvalidModelStateWithErrorMessages()));
            }

            int                userId            = Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier));
            FollowerDto        follower          = unFollowViewModel.GetFollowerDto(userId);
            ServiceResponseDto unFollowResultDto = await _followerService.UnFollowUserAsync(follower);

            await _tempDataService.UpdateTempDataAsync(TempData, userId);

            return(Json(unFollowResultDto));
        }
Beispiel #7
0
        public async Task UnFollowUserAsync_Should_Fail_Because_User_Is_Not_Currently_Followed()
        {
            // Arrange
            FollowerDto followerDto = new FollowerDto
            {
                UserId         = 1,
                FollowerUserId = 2
            };

            // Act
            ServiceResponseDto responseDto = await FollowerService.UnFollowUserAsync(followerDto);

            // Assert
            Assert.IsFalse(responseDto.Success);
        }
Beispiel #8
0
        public async Task FollowUserAsync_Should_Fail_User_Does_Not_Exist()
        {
            // Arrange
            FollowerDto followerDto = new FollowerDto
            {
                UserId         = 1,
                FollowerUserId = 6
            };

            // Act
            ServiceResponseDto responseDto = await FollowerService.FollowUserAsync(followerDto);

            // Assert
            Assert.IsFalse(responseDto.Success);
        }
Beispiel #9
0
        public async Task FollowUserAsync_Should_Pass()
        {
            // Arrange
            FollowerDto followerDto = new FollowerDto
            {
                UserId         = 1,
                FollowerUserId = 2
            };

            // Act
            ServiceResponseDto responseDto = await FollowerService.FollowUserAsync(followerDto);

            // Assert
            Assert.IsTrue(responseDto.Success);
        }
Beispiel #10
0
        public IActionResult UnFollow([FromBody] FollowerDto tweetDto)
        {
            // map dto to entity
            var follower = _mapper.Map <Contacts>(tweetDto);

            try
            {
                // save
                _tweetsService.UnFollow(follower);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Beispiel #11
0
        public FollowerDto GetFollowerFollowing(int userProfileId)
        {
            var followers  = _baseRepository.Fetch <Follower>(x => x.ToUserId == userProfileId).ToList();
            var followings = _baseRepository.Fetch <Follower>(x => x.FromUserId == userProfileId).ToList();

            var currentUserProfile = _userService.GetCurrentUser();
            var isFollowed         =
                _baseRepository.Get <Follower>(x => x.FromUserId == currentUserProfile.UserProfile.Id &&
                                               x.ToUserId == userProfileId) != null;

            var result = new FollowerDto
            {
                Followers  = followers.Count(),
                Followings = followings.Count(),
                IsCurrentUserProfileFollowed = isFollowed
            };

            return(result);
        }
        public IHttpActionResult Attend(FollowerDto dto)
        {
            var userId = User.Identity.GetUserId();

            if (_context.Followings.Any(f => f.FollowerId == userId && f.FolloweeId == dto.FolloweeId))
            {
                return(BadRequest("You are already following."));
            }

            var following = new Following
            {
                FolloweeId = dto.FolloweeId,
                FollowerId = userId
            };

            _context.Followings.Add(following);
            _context.SaveChanges();

            return(Ok());
        }
Beispiel #13
0
        public async Task GetMutualFollowersByUserIdAsync_Should_Pass()
        {
            // Arrange
            FollowerDto followerDto1 = new FollowerDto
            {
                UserId         = 1,
                FollowerUserId = 2
            };
            FollowerDto followerDto2 = new FollowerDto
            {
                UserId         = 2,
                FollowerUserId = 1
            };
            FollowerDto followerDto3 = new FollowerDto
            {
                UserId         = 4,
                FollowerUserId = 1
            };
            FollowerDto followerDto4 = new FollowerDto
            {
                UserId         = 1,
                FollowerUserId = 4
            };
            await FollowerService.FollowUserAsync(followerDto1);

            await FollowerService.FollowUserAsync(followerDto2);

            await FollowerService.FollowUserAsync(followerDto3);

            await FollowerService.FollowUserAsync(followerDto4);

            // Act
            List <Follower> follows       = (await FollowerRepository.FindManyByExpressionAsync(follower => follower.FollowerUserId.Equals(1))).ToList();
            List <Follower> followers     = (await FollowerRepository.FindManyByExpressionAsync(follower => follower.UserId.Equals(1))).ToList();
            List <bool>     mutualFollows = followers.Select(follower => follows.Any(following => following.UserId.Equals(follower.FollowerUserId))).ToList();

            // Assert
            Assert.AreEqual(mutualFollows.Count, 2);
        }
Beispiel #14
0
        public async Task <ServiceResponseDto> UnFollowUserAsync(FollowerDto followerDto)
        {
            ServiceResponseDto unFollowResultDto = new ServiceResponseDto();
            Follower           follower          = DtoToEntityConverter.Convert <Follower, FollowerDto>(followerDto);

            if (!await _applicationUserRepository.ExistsAsync(user => user.Id.Equals(followerDto.UserId)))
            {
                unFollowResultDto.Message = "The user does not exist.";
                return(unFollowResultDto);
            }

            if (!await _applicationUserRepository.ExistsAsync(user => user.Id.Equals(followerDto.FollowerUserId)))
            {
                unFollowResultDto.Message = "The follower user does not exist.";
                return(unFollowResultDto);
            }

            string username = (await _applicationUserRepository.FindSingleByExpressionAsync(user => user.Id.Equals(followerDto.UserId))).UserName;

            if (!await _followerRepository.ExistsAsync(follow => follow.UserId.Equals(followerDto.UserId) && follow.FollowerUserId.Equals(followerDto.FollowerUserId)))
            {
                unFollowResultDto.Message = $"you do not have {username} followed";
                return(unFollowResultDto);
            }

            Follower actualFollower = await _followerRepository.FindSingleByExpressionAsync(follwr => follwr.UserId.Equals(follower.UserId) && follwr.FollowerUserId.Equals(follower.FollowerUserId));

            if (await _followerRepository.DeleteAsync(actualFollower))
            {
                unFollowResultDto.Success = true;
                unFollowResultDto.Message = $"Successfully unfollowed {username}";
                return(unFollowResultDto);
            }

            unFollowResultDto.Message = "Something happened try again later..";
            return(unFollowResultDto);
        }
        public async Task InitializeAsync()
        {
            ApplicationDbFactory = new ApplicationDbFactory("InMemoryDatabase");
            await ApplicationDbFactory.Create().Database.EnsureDeletedAsync();

            await ApplicationDbFactory.Create().Database.EnsureCreatedAsync();

            ApplicationDbFactory.Create().ResetValueGenerators();

            MemeRepository            = new MemeRepository(ApplicationDbFactory.Create(), MemeValidator);
            SharedMemeRepository      = new SharedMemeRepository(ApplicationDbFactory.Create(), SharedMemeValidator);
            ApplicationUserRepository = new UserRepository(ApplicationDbFactory.Create(), ApplicationUserValidator);
            FollowerRepository        = new FollowerRepository(ApplicationDbFactory.Create(), FollowerValidator);
            CredentialRepository      = new CredentialRepository(ApplicationDbFactory.Create(), CredentialValidator);
            CredentialTypeRepository  = new CredentialTypeRepository(ApplicationDbFactory.Create(), CredentialTypeValidator);
            RoleRepository            = new RoleRepository(ApplicationDbFactory.Create(), RoleValidator);
            UserRoleRepository        = new UserRoleRepository(ApplicationDbFactory.Create(), UserRoleValidator);
            RolePermissionRepository  = new RolePermissionRepository(ApplicationDbFactory.Create(), RolePermissionValidator);
            PermissionRepository      = new PermissionRepository(ApplicationDbFactory.Create(), PermissionValidator);
            CommentRepository         = new CommentRepository(ApplicationDbFactory.Create(), CommentValidator);
            HttpContextAccessor       = new HttpContextAccessor(); // NOTE: Don't actually use it, when using Startup it will inject the HttpContext. (here it will always be null)

            UserManager        = new UserManager(ApplicationUserRepository, CredentialTypeRepository, CredentialRepository, RoleRepository, UserRoleRepository, RolePermissionRepository, PermissionRepository, HttpContextAccessor, Hasher, SaltGenerator);
            UserService        = new UserService(UserManager, ApplicationUserRepository, FollowerRepository);
            FollowerService    = new FollowerService(FollowerRepository, ApplicationUserRepository);
            MemeSharingService = new MemeSharingService(SharedMemeRepository, ApplicationUserRepository);

            // NOTE: A CredentialType is required for a user to be able to login or register.
            await CredentialTypeRepository.CreateAsync(new CredentialType
            {
                Code     = "Email",
                Name     = "Email",
                Position = 1
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            FollowerDto followerDto1 = new FollowerDto
            {
                UserId         = 1,
                FollowerUserId = 2
            };
            FollowerDto followerDto2 = new FollowerDto
            {
                UserId         = 2,
                FollowerUserId = 1
            };
            await FollowerService.FollowUserAsync(followerDto1);

            await FollowerService.FollowUserAsync(followerDto2);

            Meme meme1 = new Meme
            {
                Id       = "a0Q558q",
                ImageUrl = "https://images-cdn.9gag.com/photo/a0Q558q_700b.jpg",
                VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0Q558q_460sv.mp4",
                PageUrl  = "http://9gag.com/gag/a0Q558q",
                Title    = "Old but Gold"
            };
            await MemeRepository.CreateAsync(meme1);

            Meme meme2 = new Meme
            {
                Id       = "a0QQZoL",
                ImageUrl = "https://images-cdn.9gag.com/photo/a0QQZoL_700b.jpg",
                VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0QQZoL_460sv.mp4",
                PageUrl  = "http://9gag.com/gag/a0QQZoL",
                Title    = "Austin was listed for a heart transplant, and the doctor said he would deliver the news a heart was available dressed as Chewbacca."
            };
            await MemeRepository.CreateAsync(meme2);
        }
Beispiel #16
0
 public async Task <ActionResult <FollowerDto> > Create([FromBody] FollowerDto dto)
 {
     return(Ok(await _repository.Create(dto)));
 }
Beispiel #17
0
 public void Post(FollowerDto follower)
 {
     Service.AddFollowedUser(DynamoSession.User.UserName, follower.UserName);
 }
 public ActionResult <FollowerDto> Create([FromBody] FollowerDto dto)
 {
     return(Ok(_repository.Create(dto)));
 }