Пример #1
0
        public void AddNewFriend_TestIfFriendIsAdded()
        {
            // arrange
            var friendInput = new FriendInputModel
            {
                Name    = "Aaron Jackson",
                Email   = "*****@*****.**",
                Phone   = "800 544 4856",
                Address = "Torrance"
            };

            _friendRepositoryMock.Setup(method => method.AddNewFriend(friendInput)).Returns(
                FizzWare.NBuilder.Builder <FriendDetailsDto>
                .CreateNew().With(x => x.Id = 1).With(x => x.Name = "Aaron Jackson")
                .With(x => x.Email          = "*****@*****.**")
                .With(x => x.Phone          = "800 544 4856")
                .With(x => x.Address        = "Torrance").Build());

            // act
            var newfriend = _friendService.AddNewFriend(friendInput);

            // assert
            Assert.AreEqual("Aaron Jackson", newfriend.Name);
            Assert.IsNotNull(newfriend);
        }
Пример #2
0
        public IActionResult AddNewFriend([FromBody] FriendInputModel friend)
        {
            if (!ModelState.IsValid)
            {
                throw new ModelFormatException();
            }

            return(StatusCode(201, _friendService.AddNewFriend(friend)));
        }
Пример #3
0
        public async Task SaveToDb(FriendRequestVM response)
        {
            if (response.HasAccepted == true)
            {
                await _friendRequestService.AcceptFriendRequest(response);

                await _friendService.AddNewFriend(response);
            }
            else if (response.HasAccepted == false)
            {
                await _friendRequestService.DeclineFriendRequest(response);
            }
        }
        public async Task <IActionResult> AddFriendAsync([FromBody] FriendDto newFriend)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var response = await _service.AddNewFriend(newFriend);

                    return(Ok(response.Object));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
 public async Task <bool> AddNewFriend(FriendBaseRequestModel data)
 {
     return(await _friendService.AddNewFriend(data));
 }