public void CreateFriend() { // Arrange friendRepository.Setup(c => c.Insert(It.IsAny <Friend>())).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.Post, "http://localhost:1175/api/Friend/CreateFriend") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; // Act var response = controller.CreateFriend(postFriend); // Assert Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); }
public void CreateFriend_WhenCreatedCorrectly_ReturnsCreatedResult() { var friend = new FriendInputModel() { FirstName = "Egill", LastName = "Joh", Email = "*****@*****.**", Phone = "659 0407", Address = "Reynimelur 47" }; var createdResult = _controller.CreateFriend(friend); var result = Assert.IsType <CreatedAtRouteResult>(createdResult); Assert.Equal(201, result.StatusCode); }