Using Xunit
Using Xunit
Using Xunit
using System.Net.Http;
using System.Net.Http.Json;
using Microsoft.AspNetCore.Mvc.Testing;
using BackendAerolinea.Models;
using BackendAerolinea;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.Net;
namespace TestingAvion;
[Fact]
public async Task getAvion_ShouldReturnExistingAirplane()
{
// Arrange
var builder = WebApplication.CreateBuilder(new string[0]);
var connectionString = "Server=DESKTOP-9A9H02P\\
SQLEXPRESS;Database=Aerolineadb;Trusted_Connection=true;TrustServerCertificate=true
";
builder.Services.AddDbContext<DataContext>(options =>
{
builder.Services.AddDbContext<DataContext>(options =>
{
options.UseSqlServer(connectionString); // Configura la conexión a
SQL Server
});
});
var app = builder.Build();
var context = app.Services.GetRequiredService<DataContext>();
await context.Database.EnsureCreatedAsync();
var client = app.Services.GetRequiredService<HttpClient>(); // Obtén un
HttpClient para realizar solicitudes.
//Act
var response = await client.GetAsync("/Avion");
// Assert
response.EnsureSuccessStatusCode();
}
}
_________________________________________________________________________
using Xunit;
using Microsoft.AspNetCore.Mvc.Testing;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using BackendAerolinea;
namespace BackendAerolinea.Tests
{
public class AvionTests : IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
public AvionTests()
{
[Fact]
public async Task TestGetAvionEndpoint()
{
// Arrange
var client = _factory.CreateClient();
// Act
var response = await client.GetAsync("/Avion");
// Assert
response.EnsureSuccessStatusCode();
// Add more assertions based on the expected behavior
}