Skip to content

Commit

Permalink
feat: se agrega Integration Test para el controlador Fibonacci
Browse files Browse the repository at this point in the history
issue: #8
  • Loading branch information
dhernandezsicfe committed Feb 8, 2019
1 parent 69c39d9 commit 6f1bd5a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
46 changes: 46 additions & 0 deletions tests/FibonacciExcercise.UnitTests/IntegrationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using FibonacciWebApi;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net.Http;
using System.Threading.Tasks;

namespace FibonacciExcercise.IntegrationTest
{
// integration tests frequently involve application infrastructure concerns, such as a database, file system,
// network resources, or web requests and responses
//help: https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/multi-container-microservice-net-applications/test-aspnet-core-services-web-apps


[TestClass]
public class IntegracionTest
{
private readonly TestServer _server;
private readonly HttpClient _client;

public IntegracionTest()
{
// Arrange
_server = new TestServer(new WebHostBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
}

[TestMethod]
public async Task InvocarApiCorrecta()
{
// Act
var response = await _client.GetAsync("/api/fibonacci/2");

//Verifico que encabezado sea Exitoso
Assert.IsTrue(response.IsSuccessStatusCode, "El código de la respuesta debería ser exitoso");


// Verifico que la respuesta sea correcta
var responseString = await response.Content.ReadAsAsync<int>();
Assert.AreEqual(1, responseString);
}
}
}


0 comments on commit 6f1bd5a

Please sign in to comment.