public async Task RejectFriendshipAsync_RejectYourFriendshipRequest_ReturnOne()
        {
            // Arrange
            var friendship = new Friendship
            {
                FromUserId = user2.Id,
                ToUserId   = user1.Id,
                State      = FriendshipState.Requested,
                Id         = Guid.NewGuid(),
            };

            var mockRepository = new Mock <IFriendshipRepository>();

            mockRepository.Setup(repository => repository.GetByIdAsync(friendship.Id))
            .ReturnsAsync(friendship);
            mockRepository.Setup(repository => repository.UpdateAsync(
                                     It.Is <Friendship>(x => x.FromUserId == user2.Id && x.ToUserId == user1.Id &&
                                                        x.Id == friendship.Id && x.State == FriendshipState.Rejected)))
            .ReturnsAsync(1);

            var friendshipService = new FriendshipService(mockRepository.Object, mockUserService.Object);

            // Act
            var result = await friendshipService.RejectFriendshipAsync(friendship.Id);

            // Assert
            Assert.AreEqual(result, 1);
        }
        public async Task GetReceivedFriendshipsAsync_HaveReceivedRequestedFriendship_ReturnListOfFriendship()
        {
            // Arrange
            var friendship1 = new Friendship
            {
                FromUserId = user2.Id,
                ToUserId   = user1.Id,
                State      = FriendshipState.Requested,
                Id         = Guid.NewGuid(),
            };
            var friendship2 = new Friendship
            {
                FromUserId = user3.Id,
                ToUserId   = user1.Id,
                State      = FriendshipState.Requested,
                Id         = Guid.NewGuid(),
            };

            var mockRepository = new Mock <IFriendshipRepository>();

            mockRepository.Setup(repository => repository.GetByToUserAndStateAsync(user1.Id, FriendshipState.Requested))
            .ReturnsAsync(new List <Friendship> {
                friendship1, friendship2
            });

            var friendshipService = new FriendshipService(mockRepository.Object, mockUserService.Object);

            // Act
            var result = await friendshipService.GetReceivedFriendshipsAsync();

            // Assert
            Assert.AreEqual(result.Count(), 2);
        }
 public MessengerController(MessengerService messengerService, UserService userService, FriendshipService friendshipService, IMapper mapper)
 {
     this.messengerService  = messengerService;
     this.userService       = userService;
     this.friendshipService = friendshipService;
     this.mapper            = mapper;
 }
        public async Task CreateFriendshipAsync_CreateFriendshipWithYourSelf_ThrowException()
        {
            // Arrange
            var mockRepository    = new Mock <IFriendshipRepository>();
            var friendshipService = new FriendshipService(mockRepository.Object, mockUserService.Object);

            // Act and Assert
            Assert.ThrowsAsync(typeof(BadRequestExceptions),
                               () => friendshipService.CreateFriendshipAsync(user1.Id));

            // Act
            Exception expectedExcetpion = null;

            try
            {
                var result = await friendshipService.CreateFriendshipAsync(user1.Id);
            }
            catch (Exception ex)
            {
                expectedExcetpion = ex;
            }

            // Assert
            Assert.IsNotNull(expectedExcetpion);
            Assert.IsInstanceOf <BadRequestExceptions>(expectedExcetpion);
            Assert.AreEqual(expectedExcetpion.Message, "you can't send Friendship request to yourself");
        }
        public async Task CancelFriendshipAsync_CancelOtherUserFriendshipRequest_ThrowException()
        {
            // Arrange
            var friendship = new Friendship
            {
                FromUserId = user2.Id,
                ToUserId   = user1.Id,
                State      = FriendshipState.Requested,
                Id         = Guid.NewGuid(),
            };

            var mockRepository = new Mock <IFriendshipRepository>();

            mockRepository.Setup(repository => repository.GetByIdAsync(friendship.Id))
            .ReturnsAsync(friendship);

            var friendshipService = new FriendshipService(mockRepository.Object, mockUserService.Object);

            // Act
            Exception expectedExcetpion = null;

            try
            {
                var result = await friendshipService.CancelFriendshipAsync(friendship.Id);
            }
            catch (Exception ex)
            {
                expectedExcetpion = ex;
            }

            // Assert
            Assert.IsNotNull(expectedExcetpion);
            Assert.IsInstanceOf <BadRequestExceptions>(expectedExcetpion);
            Assert.AreEqual(expectedExcetpion.Message, "you can't cancel Friendship was sent by other users");
        }
        public async Task UnfriendAsync_UnfriendUserRequestedByHe_ReturnOne()
        {
            // Arrange
            var friendship = new Friendship
            {
                FromUserId = user2.Id,
                ToUserId   = user1.Id,
                State      = FriendshipState.Accepted,
                Id         = Guid.NewGuid(),
            };

            var mockRepository = new Mock <IFriendshipRepository>();

            mockRepository.Setup(repository => repository.GetByFromUserAndToUserAsync(user2.Id, user1.Id))
            .ReturnsAsync(friendship);

            mockRepository.Setup(repository => repository.DeleteAsync(friendship.Id))
            .ReturnsAsync(1);

            var friendshipService = new FriendshipService(mockRepository.Object, mockUserService.Object);

            // Act
            var result = await friendshipService.UnfriendAsync(user2.Id);

            // Assert
            Assert.AreEqual(result, 1);
        }
        public async Task UnfriendAsync_FriendshipStateIsNotAcepted_ThrowException()
        {
            // Arrange
            // Arrange
            var friendship = new Friendship
            {
                FromUserId = user2.Id,
                ToUserId   = user1.Id,
                State      = FriendshipState.Requested,
                Id         = Guid.NewGuid(),
            };
            var mockRepository    = new Mock <IFriendshipRepository>();
            var friendshipService = new FriendshipService(mockRepository.Object, mockUserService.Object);

            mockRepository.Setup(repository => repository.GetByFromUserAndToUserAsync(user2.Id, user1.Id))
            .ReturnsAsync(friendship);

            // Act
            Exception expectedExcetpion = null;

            try
            {
                var result = await friendshipService.UnfriendAsync(user2.Id);
            }
            catch (Exception ex)
            {
                expectedExcetpion = ex;
            }

            // Assert
            Assert.IsNotNull(expectedExcetpion);
            Assert.IsInstanceOf <BadRequestExceptions>(expectedExcetpion);
            Assert.AreEqual(expectedExcetpion.Message, "your Friendship with this user state is not Accepted");
        }
Beispiel #8
0
        public StartUp(
            ConversationService conversationService,
            FriendshipService friendshipService,
            AuthService authService,
            HomeService homeService,
            KahlaLocation kahlaLocation,
            BotLogger botLogger,
            IEnumerable <BotBase> bots,
            VersionService versionService,
            SettingsService settingsService,
            AES aes)
        {
            var bot = BotConfigurer.SelectBot(bots, settingsService, botLogger);

            bot.BotLogger           = botLogger;
            bot.AES                 = aes;
            bot.ConversationService = conversationService;
            bot.FriendshipService   = friendshipService;
            bot.HomeService         = homeService;
            bot.KahlaLocation       = kahlaLocation;
            bot.AuthService         = authService;
            bot.VersionService      = versionService;
            bot.SettingsService     = settingsService;
            _bot = bot;
        }
Beispiel #9
0
 public BotHost(
     BotCommander <T> botCommander,
     BotLogger botLogger,
     SettingsService settingsService,
     KahlaLocation kahlaLocation,
     FriendshipService friendshipService,
     HomeService homeService,
     VersionService versionService,
     AuthService authService,
     EventSyncer <T> eventSyncer,
     ProfileContainer profileContainer,
     BotFactory <T> botFactory)
 {
     _botCommander      = botCommander.InjectHost(this);
     _botLogger         = botLogger;
     _settingsService   = settingsService;
     _kahlaLocation     = kahlaLocation;
     _friendshipService = friendshipService;
     _homeService       = homeService;
     _versionService    = versionService;
     _authService       = authService;
     _eventSyncer       = eventSyncer;
     _profileContainer  = profileContainer;
     _botFactory        = botFactory;
 }
        public async Task CreateFriendshipAsync_CreateFriendshipWithSomeoneWhoRejectedYouRecently_ThrowException()
        {
            // Arrange
            var friendship = new Friendship
            {
                FromUserId = user1.Id,
                ToUserId   = user2.Id,
                State      = FriendshipState.Rejected,
            };
            var mockRepository = new Mock <IFriendshipRepository>();

            mockRepository.Setup(repository => repository.GetByFromUserAndToUserAsync(user1.Id, user2.Id))
            .ReturnsAsync(friendship);
            var friendshipService = new FriendshipService(mockRepository.Object, mockUserService.Object);

            // Act
            Exception expectedExcetpion = null;

            try
            {
                var result = await friendshipService.CreateFriendshipAsync(user2.Id);
            }
            catch (Exception ex)
            {
                expectedExcetpion = ex;
            }

            // Assert
            Assert.IsNotNull(expectedExcetpion);
            Assert.IsInstanceOf <BadRequestExceptions>(expectedExcetpion);
            Assert.AreEqual(expectedExcetpion.Message, "your previous Friendship request rejected by this user");
        }
 public FriendshipCallbackQueryHandler(ITelegramBotClient bot, IDictionary <long, ITelegramBotClient> bots, RaidBattlesContext db,
                                       FriendshipService friendshipService)
 {
     myBot  = bot;
     myBots = bots;
     myDB   = db;
     myFriendshipService = friendshipService;
 }
 public FriendshipsController()
 {
     db = new SocialNetworkContext();
     _friendshipService = new FriendshipService(
         new ProfileEntityFrameworkRepository(db),
         new FriendshipEntityFrameworkRepository(db)
         );
 }
        /// <inheritdoc />
        public async Task Handle(FriendshipRequestAcceptedDomainEvent notification, CancellationToken cancellationToken)
        {
            var friendshipService = new FriendshipService(_userRepository, _friendshipRepository);

            await friendshipService.CreateFriendshipAsync(notification.FriendshipRequest);

            await _unitOfWork.SaveChangesAsync(cancellationToken);
        }
Beispiel #14
0
        public void TestInit()
        {
            dbContext = new ApplicationDbContext(Mocks.GetApplicationDbContextOptions());
            Initializer.InitializeDbForTests(dbContext);
            var httpContext = Mocks.GetMockIHttpContextAccessor(dbContext.Users.FirstOrDefault(u => u.UserName == "Varunastra"));

            service = new FriendshipService(httpContext, dbContext,
                                            new Mock <ILogger <FriendshipService> >().Object, new Mock <ConnectionService>().Object);
        }
Beispiel #15
0
        public async Task <IHttpActionResult> AcceptedFollowersToFriend(string followerId)
        {
            UnitOfWork        uow     = new UnitOfWork(new ApplicationDbContext());
            FriendshipService service = new FriendshipService(uow);
            var userId = User.Identity.GetUserId();

            service.AcceptedFriends(userId, followerId);
            uow.Commit();
            return(Ok());
        }
Beispiel #16
0
        public async Task <IHttpActionResult> ChangeAllowSeeTree(string friendId, bool canSeeTree)
        {
            UnitOfWork        uow     = new UnitOfWork(new ApplicationDbContext());
            FriendshipService service = new FriendshipService(uow);
            var userId = User.Identity.GetUserId();

            service.ChangeAllowSeeTree(userId, friendId, canSeeTree);
            uow.Commit();
            return(Ok());
        }
Beispiel #17
0
        public IHttpActionResult Delete(int id)
        {
            var           friendshipService = new FriendshipService();
            FriendshipDTO friendshipDTO     = friendshipService.RemoveFriendship(id);

            if (friendshipDTO == null)
            {
                return(BadRequest("This account does not exist in DB"));
            }
            return(Ok(friendshipDTO));
        }
Beispiel #18
0
        public IHttpActionResult AddFriend(int userId, int friendId)
        {
            var friendshipService = new FriendshipService();
            var sports            = friendshipService.AddFriend(userId, friendId);

            if (sports == null)
            {
                return(NotFound());
            }

            return(Ok(sports));
        }
        public void AddRemoveFriend()
        {
            SignUpAccountService signUpAccountService = new SignUpAccountService();
            AccountService       accountService       = new AccountService();
            FriendshipService    frService            = new FriendshipService();

            AdressDTO address = new AdressDTO();

            address.latitude  = 50;
            address.longitude = 30;
            address.address   = "Beautiful city";

            SignUpAccountDTO account = new SignUpAccountDTO();

            account.FirstName = "Ion";
            account.LastName  = "Popescu";
            account.UserName  = "******";
            account.Email     = "*****@*****.**";
            account.Adress    = address;
            account.Password  = "******";

            SignUpAccountDTO account1 = new SignUpAccountDTO();

            account1.FirstName = "Dfsadsa";
            account1.LastName  = "Ddsadsad";
            account1.UserName  = "******";
            account1.Email     = "*****@*****.**";
            account1.Adress    = address;
            account1.Password  = "******";



            AccountSimpleDTO acc  = signUpAccountService.addAccount(account);
            AccountSimpleDTO acc1 = signUpAccountService.addAccount(account1);

            frService.AddFriend(acc.Id, acc1.Id);

            var friends = frService.GetAllFriendships(acc.Id);

            FriendshipDTO friendship = friends.Where(fr => (fr.UserOne.Id == acc1.Id | fr.UserTwo.Id == acc1.Id)).FirstOrDefault();

            frService.RemoveFriendship(friendship.Id);

            var friends1 = frService.GetAllFriendships(acc.Id);

            FriendshipDTO friendship1 = friends1.Where(fr => (fr.UserOne.Id == acc1.Id | fr.UserTwo.Id == acc1.Id)).FirstOrDefault();

            accountService.deleteAccount(acc.Id);
            accountService.deleteAccount(acc1.Id);

            Assert.IsNotNull(friendship);
            Assert.IsNull(friendship1);
        }
Beispiel #20
0
        public IHttpActionResult Post(FriendshipDTO friendship)
        {
            var           friendshipService = new FriendshipService();
            FriendshipDTO friendshipDTO     = friendshipService.AddFriendship(friendship);

            if (friendshipDTO == null)
            {
                return(NotFound());
            }

            return(Ok(friendshipDTO));
        }
Beispiel #21
0
        public IHttpActionResult GetFriendDetail(int userId, int friendId)
        {
            var friendshipService = new FriendshipService();

            FriendDTO frDTO = friendshipService.GetDetailFriend(userId, friendId);

            if (frDTO == null)
            {
                return(BadRequest("This user does not exist"));
            }
            return(Ok(frDTO));
        }
        public async Task GetFriendsAsync_HaveNotFriendship_ReturnEmpty()
        {
            // Arrange
            var mockRepository    = new Mock <IFriendshipRepository>();
            var friendshipService = new FriendshipService(mockRepository.Object, mockUserService.Object);

            // Act
            var result = await friendshipService.GetFriendsAsync();

            // Assert
            Assert.IsEmpty(result);
        }
Beispiel #23
0
 public EventSyncer(
     ConversationService conversationService,
     FriendshipService friendshipService,
     BotLogger botLogger,
     BotFactory <T> botFactory,
     AES aes)
 {
     _conversationService = conversationService;
     _friendshipService   = friendshipService;
     _botLogger           = botLogger;
     _botFactory          = botFactory;
     _aes = aes;
 }
Beispiel #24
0
        public async Task <IHttpActionResult> GetUserTree(string friendId)
        {
            UnitOfWork        uow     = new UnitOfWork(new ApplicationDbContext());
            FriendshipService service = new FriendshipService(uow);
            var userId      = User.Identity.GetUserId();
            var membersList = service.GetAllMembersInTreeFriend(userId, friendId);

            if (membersList != null)
            {
                var members = membersList.Select(x => new AllMembersViewModel()
                {
                    Parents = x.Childs.Select(p => new ParentsViewModel()
                    {
                        ParentId = p.MemberId
                    }).ToList(),
                    Photo  = x.Photo,
                    Childs = x.Parents.Select(c => new ChildsViewModel()
                    {
                        ChieldId = c.MemberId
                    }).ToList(),
                    Id         = x.Id,
                    FirstName  = x.FirstName,
                    LastName   = x.LastName,
                    SecondName = x.SecondName,
                    Marriages  = x.Marriages.Select(m => new MarriageViewModel()
                    {
                        MarriageId = m.MemberId,
                        IsMarriade = m.IsMarriade
                    }).ToList(),
                    Diseaseses = x.Diseaseses.Select(d => new HaveDiseaseViewModel()
                    {
                        DiseaseId      = d.GenDiseasesId,
                        About          = d.GenDiseases.About,
                        MenInherited   = d.GenDiseases.MenInherited,
                        WomenInherited = d.GenDiseases.WomenInherited,
                        Dominante      = d.Dominant,
                        NameDisease    = d.GenDiseases.Name
                    }).ToList(),
                    DateOfBirth = x.DateOfBirth,
                    DateOfDeth  = x.DateOfDeth,
                    Sex         = x.Sex,
                    OtherInfo   = x.OtherInfo,
                    Address     = x.Address
                });
                return(await Task.FromResult(Ok(members)));
            }
            else
            {
                return(Ok());
            }
        }
 public VoteCallbackQueryHandler(TelemetryClient telemetryClient, RaidBattlesContext db, IDictionary <long, ITelegramBotClient> bots,
                                 ITelegramBotClient bot, RaidService raidService, IUrlHelper urlHelper, IClock clock, IOptions <BotConfiguration> options,
                                 FriendshipService friendshipService, TimeZoneNotifyService timeZoneNotifyService)
 {
     myTelemetryClient = telemetryClient;
     myDb                    = db;
     myBots                  = bots;
     myBot                   = bot;
     myRaidService           = raidService;
     myUrlHelper             = urlHelper;
     myClock                 = clock;
     myFriendshipService     = friendshipService;
     myTimeZoneNotifyService = timeZoneNotifyService;
     myVoteTimeout           = options.Value.VoteTimeout;
     myBlackList             = options.Value.BlackList ?? new HashSet <long>(0);
 }
        public async Task CreateFriendshipAsync_CreateNewFriendship_ReturnOne()
        {
            // Arrange
            var mockRepository = new Mock <IFriendshipRepository>();

            mockRepository.Setup(repository => repository.InsertAsync(
                                     It.Is <Friendship>(x => x.FromUserId == user1.Id && x.ToUserId == user2.Id &&
                                                        x.State == FriendshipState.Requested)))
            .ReturnsAsync(1);
            var friendshipService = new FriendshipService(mockRepository.Object, mockUserService.Object);

            // Act
            var result = await friendshipService.CreateFriendshipAsync(user2.Id);

            // Assert
            Assert.AreEqual(result, 1);
        }
Beispiel #27
0
 public BotListener(
     HomeService homeService,
     BotLogger botLogger,
     KahlaLocation kahlaLocation,
     AuthService authService,
     ConversationService conversationService,
     FriendshipService friendshipService,
     AES aes)
 {
     _homeService         = homeService;
     _botLogger           = botLogger;
     _kahlaLocation       = kahlaLocation;
     _authService         = authService;
     _conversationService = conversationService;
     _friendshipService   = friendshipService;
     _aes = aes;
 }
Beispiel #28
0
        public async Task <IHttpActionResult> GetUserByName(string name)
        {
            UnitOfWork        uow     = new UnitOfWork(new ApplicationDbContext());
            FriendshipService service = new FriendshipService(uow);
            var userId = User.Identity.GetUserId();
            var users  = service.GetUserByName(name, userId);

            var folowers = users.Select(x => new FollowerViewModel()
            {
                UserId     = x.Id,
                Photo      = x.Photo,
                FirstName  = x.FirstName,
                LastName   = x.LastName,
                SecondName = x.SecondName
            }).ToList();


            return(await Task.FromResult(Ok(folowers)));
        }
        /// <inheritdoc />
        public async Task <Result> Handle(RemoveFriendshipCommand request, CancellationToken cancellationToken)
        {
            if (request.UserId != _userIdentifierProvider.UserId)
            {
                return(Result.Failure(DomainErrors.User.InvalidPermissions));
            }

            var friendshipService = new FriendshipService(_userRepository, _friendshipRepository);

            Result result = await friendshipService.RemoveFriendshipAsync(request.UserId, request.FriendId);

            if (result.IsFailure)
            {
                return(Result.Failure(result.Error));
            }

            await _unitOfWork.SaveChangesAsync(cancellationToken);

            return(Result.Success());
        }
Beispiel #30
0
        public async Task <IHttpActionResult> GetAllFriends()
        {
            UnitOfWork        uow     = new UnitOfWork(new ApplicationDbContext());
            FriendshipService service = new FriendshipService(uow);
            var userId      = User.Identity.GetUserId();
            var friendships = service.GetAllFriendByUser(userId);
            var allUsers    = new ApplicationDbContext().Users.ToList();
            var friends     = friendships.Select(x => new FriendsViewModel()
            {
                UserId      = x.UserId,
                CanSeeTree  = x.CanSeeTree,
                Photo       = x.User.Photo,
                FirstName   = x.User.FirstName,
                LastName    = x.User.LastName,
                SecondName  = x.User.SecondName,
                DateOfBirth = x.User.DateOfBith,
                Email       = allUsers.First(y => y.Id == x.UserId).Email
            });

            return(await Task.FromResult(Ok(friends)));
        }