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))); }
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); }
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); }
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); }
public async Task <IActionResult> FollowUser(FollowDto followDto) { await _followerService.FollowUserAsync(followDto.FollowerUserId, followDto.FollowingUserId); return(NoContent()); }
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); }