public void DeleteFriend()
        {
            // Arrange
            friendRepository.Setup(x => x.GetFriendById(1)).Returns(getFriend);
            friendRepository.Setup(c => c.DeleteObject(It.IsAny <Friend>(), It.IsAny <bool>())).Returns(true);
            var httpConfiguration = new HttpConfiguration();

            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                                                  new HttpRouteValueDictionary {
                { "controller", "friend" }
            });
            var controller = new FriendController(friendRepository.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Delete, "http://localhost:1175/api/Friend/DeleteFriend/{friendId}")
                {
                    Properties =
                    {
                        { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                        { HttpPropertyKeys.HttpRouteDataKey,     httpRouteData     }
                    }
                }
            };

            // Act
            var response = controller.DeleteFriendById(1);

            // Assert
            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
示例#2
0
        public void DeleteFriendById_WhenDeletedWithExistingId_ReturnsOkResult()
        {
            var okResult = _controller.DeleteFriendById(1);

            var result = Assert.IsType <OkObjectResult>(okResult);

            Assert.Equal(200, result.StatusCode);
        }