I followed the tutorial here but it seems like the start up file does not recognize the appsetting.json file.
So when I run the actual project, the Iconfiguration
have 7 properties.
But when I run the test, it only has one property.
So I was thinking maybe I missed something in the test method to configure the AppSetting.json file..
Here's my test method:
public class StudentServiceRequestsTest
{
private readonly TestServer _server;
private readonly HttpClient _client;
public IndividualServiceRequestsTest()
{
// Arrange
_server = new TestServer(new WebHostBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
}
[Fact]
public async Task GetStudentsByDeptShould()
{
try
{
//Act
var response = await _client.GetAsync("/api/department/200/students");
response.EnsureSuccessStatusCode();
var responseString = await response.Content.ReadAsStringAsync();
//Assert
Assert.Equal("hi", responseString);
}
catch (Exception e)
{
throw;
}
}
Here's my startup class, apprently I added the json file which includes all the keys and secrets required in the Web API.
namespace CIS.API.Student
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; set; }
services.AddSingleton(Configuration);
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
app.UseMvc();
}
}
}
Anyone knows why it would happen?