From 67f18d96ab158c1c8f6a047e77127ebafffec515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentina=20Cupa=C4=87?= Date: Sat, 18 Jun 2022 18:07:22 +0200 Subject: [PATCH] #26 REST API - BankAccountController --- .../Controllers/WeatherForecastController.cs | 6 +-- src/Optivem.Kata.Banking.Web/Program.cs | 1 + .../Optivem.Kata.Banking.Test.csproj | 2 + .../System/BankAccountControllerSystemTest.cs | 51 ++++++++++++++++++- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/Optivem.Kata.Banking.Web/Controllers/WeatherForecastController.cs b/src/Optivem.Kata.Banking.Web/Controllers/WeatherForecastController.cs index bf47123..01f69d4 100644 --- a/src/Optivem.Kata.Banking.Web/Controllers/WeatherForecastController.cs +++ b/src/Optivem.Kata.Banking.Web/Controllers/WeatherForecastController.cs @@ -3,13 +3,13 @@ namespace Optivem.Kata.Banking.Web.Controllers { [ApiController] - [Route("[controller]")] + [Route("weather")] public class WeatherForecastController : ControllerBase { private static readonly string[] Summaries = new[] { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; private readonly ILogger _logger; diff --git a/src/Optivem.Kata.Banking.Web/Program.cs b/src/Optivem.Kata.Banking.Web/Program.cs index 48863a6..793082a 100644 --- a/src/Optivem.Kata.Banking.Web/Program.cs +++ b/src/Optivem.Kata.Banking.Web/Program.cs @@ -23,3 +23,4 @@ app.MapControllers(); app.Run(); +public partial class Program { } \ No newline at end of file diff --git a/test/Optivem.Kata.Banking.Test/Optivem.Kata.Banking.Test.csproj b/test/Optivem.Kata.Banking.Test/Optivem.Kata.Banking.Test.csproj index c5d7e55..73887e8 100644 --- a/test/Optivem.Kata.Banking.Test/Optivem.Kata.Banking.Test.csproj +++ b/test/Optivem.Kata.Banking.Test/Optivem.Kata.Banking.Test.csproj @@ -15,6 +15,7 @@ + @@ -34,6 +35,7 @@ + diff --git a/test/Optivem.Kata.Banking.Test/System/BankAccountControllerSystemTest.cs b/test/Optivem.Kata.Banking.Test/System/BankAccountControllerSystemTest.cs index 37c0595..4c8073b 100644 --- a/test/Optivem.Kata.Banking.Test/System/BankAccountControllerSystemTest.cs +++ b/test/Optivem.Kata.Banking.Test/System/BankAccountControllerSystemTest.cs @@ -1,14 +1,61 @@ -using System; +using Microsoft.AspNetCore.Mvc.Testing; +using Newtonsoft.Json; +using Optivem.Kata.Banking.Test.Common.Builders.RequestBuilders; +using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text; using System.Threading.Tasks; +using Xunit; namespace Optivem.Kata.Banking.Test.System { - public class BankAccountControllerSystemTest + public class BankAccountControllerSystemTest : IDisposable { + private readonly HttpClient _client; + public BankAccountControllerSystemTest() + { + var application = new WebApplicationFactory() + .WithWebHostBuilder(builder => + { + // TODO: VC: Configure + }); + + _client = application.CreateClient(); + } + + public void Dispose() + { + _client.Dispose(); + } + + + [Fact] + public async Task Nothing() + { + var response = await _client.GetAsync("weather"); + + response.EnsureSuccessStatusCode(); + + } + + [Fact(Skip = "TODO: In progress")] + public async Task Should_open_bank_account_given_valid_request() + { + var url = "bank-accounts"; + + var request = OpenAccountRequestBuilder.OpenAccount() + .Build(); + + var json = JsonConvert.SerializeObject(request); + var body = new StringContent(json, Encoding.UTF8, "application/json"); + + var response = await _client.PostAsync(url, body); + + response.EnsureSuccessStatusCode(); + } } }