XUnit - ITsvetkoFF/Kv-013 GitHub Wiki
xUnit.net unit testing tool for the .NET Framework.xUnit.net includes support for two different major types of unit tests: facts and theories. When describing the difference between facts and theories, we like to say: Facts are tests which are always true. They test invariant conditions. Theories are tests which are only true for a particular set of data.
[Fact]
public void GetReturnsProductWithSameId()
{
// Arrange
var mockRepository = new Mock<IProductRepository>();
mockRepository.Setup(x => x.GetById(42)) //replace method from controller to avoid integration testing
.Returns(new Product { Id = 42 });
var controller = new Products2Controller(mockRepository.Object);`
// Act
IHttpActionResult actionResult = controller.Get(42);
var contentResult = actionResult as OkNegotiatedContentResult<Product>;
// Assert
Assert.IsNotNull(contentResult);
Assert.IsNotNull(contentResult.Content);
Assert.AreEqual(42, contentResult.Content.Id);
}
route testing example: http://www.strathweb.com/2012/08/testing-routes-in-asp-net-web-api/
mock using examples: https://github.com/Moq/moq4/wiki/Quickstart
examples of all methods(get, post,put,delete): http://dotnetliberty.com/index.php/2015/12/14/asp-net-5-web-api-unit-testing/