This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Binding] | |
public class WeatherHooks | |
{ | |
private readonly IObjectContainer _objectContainer; | |
private const string AppSettingsFile = "appsettings.json"; | |
public WeatherHooks(IObjectContainer objectContainer) | |
{ | |
_objectContainer = objectContainer; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task ClearData( | |
WebApplicationFactory<Program> factory) | |
{ | |
if (factory.Services.GetService(typeof(IWeatherRepository)) | |
is not IWeatherRepository repository) return; | |
var entities = await repository.GetAsync(); | |
foreach (var entity in entities) | |
await repository.RemoveAsync(entity.Id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private WebApplicationFactory<Program> GetWebApplicationFactory() => | |
new WebApplicationFactory<Program>() | |
.WithWebHostBuilder(builder => | |
{ | |
IConfigurationSection? configSection = null; | |
builder.ConfigureAppConfiguration((context, config) => | |
{ | |
config.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), AppSettingsFile)); | |
configSection = context.Configuration.GetSection(nameof(WeatherDatabaseSettings)); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"WeatherDatabaseSettings": { | |
"ConnectionString": "mongodb://localhost:27017", | |
"DatabaseName": "WeathersTestDb", | |
"CollectionName": "Weathers" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": 1, | |
"date": "2022-01-01T06:00:00Z", | |
"temperatureC": 32, | |
"temperatureF": 89, | |
"summary": "Freezing", | |
"eTag": "6e9eff61-a3ed-4339-93fb-24151149b46c" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Binding] | |
public class WeatherWebApiStepDefinitions | |
{ | |
private const string BaseAddress = "http://localhost/"; | |
public WebApplicationFactory<Program> Factory { get; } | |
public IWeatherRepository Repository { get; } | |
public HttpClient Client { get; set; } = null!; | |
private HttpResponseMessage Response { get; set; } = null!; | |
public JsonFilesRepository JsonFilesRepo { get; } | |
private WeatherForecast? Entity { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JsonFilesRepository | |
{ | |
private const string Root = "../../../json/"; | |
public Dictionary<string, string> Files { get; } = new(); | |
public JsonFilesRepository(params string[] files) | |
{ | |
var filesList = files.ToList(); | |
if (!filesList.Any()) | |
foreach (var file in Directory.GetFiles(Root)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ItemGroup> | |
<InternalsVisibleTo Include="SpecFlowWebApi.Specs" /> | |
</ItemGroup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class Program { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IWeatherRepository | |
{ | |
Task<IEnumerable<WeatherForecast>> GetAsync(); | |
Task<WeatherForecast?> GetAsync(int id); | |
Task<WeatherForecast?> AddAsync(WeatherForecast entity); | |
Task<WeatherForecast?> UpdateAsync(WeatherForecast entity); | |
Task<int> RemoveAsync(int id); | |
} |
NewerOlder