Example #1
0
        public void Show(User user)
        {
            string friendEmail;

            Console.Write("Для добавления друга введите его E-Mail: ");
            friendEmail = Console.ReadLine();

            try
            {
                var newFriend = friendService.Create(friendEmail, user);
                SuccessMessage.Show($"Новый друг {newFriend.FirstName} {newFriend.LastName} успешно добавлен:");
            }
            catch (UserNotFoundException)
            {
                AlertMessage.Show("Пользователя с таким E-Mail не существует.");
            }
            catch (WrongFriendException)
            {
                AlertMessage.Show("Нельзя добавить в друзья самого себя.");
            }
            catch (Exception)
            {
                AlertMessage.Show("Произошла ошибка при добавлении друга.");
            }
        }
        public void Create_CallsMock_ReturnsFriend()
        {
            _createMock.Setup(x => x.Create(It.IsAny <Friend>()))
            .Returns((Friend f) => f);

            var actualFriend = _friendService.Create(_testingFriend);

            _createMock.Verify(x => x.Create(_testingFriend),
                               Times.Once);

            Assert.AreEqual(_testingFriend, actualFriend);
        }
 public void Create(string login1, string login2)
 {
     if (login1 != null && login2 != null)
     {
         var    accountId1 = accountBaseFunction.GetMyAccount(login1, null, "Name");
         var    accountId2 = accountBaseFunction.GetMyAccount(login2, null, "Name");
         Friend friend     = new Friend();
         friend.FirstAccountId  = accountId1.Id;
         friend.SecondAccountId = accountId2.Id;
         var friendship = friendService.GetFriend(friend.SecondAccountId, friend.FirstAccountId);
         if (friendship != null)
         {
             friend.State     = 1;
             friendship.State = 1;
             friendService.Update(friendship);
         }
         else
         {
             friend.State = 0;
         }
         friendService.Create(friend);
     }
 }