diff --git a/ShareBook/ShareBook.Api/ShareBook.Api.csproj b/ShareBook/ShareBook.Api/ShareBook.Api.csproj index 6ae020fc..49b7f2c6 100644 --- a/ShareBook/ShareBook.Api/ShareBook.Api.csproj +++ b/ShareBook/ShareBook.Api/ShareBook.Api.csproj @@ -8,9 +8,16 @@ + + + + + + + diff --git a/ShareBook/ShareBook.Tests.BDD/Base/BaseIntegrationTest.cs b/ShareBook/ShareBook.Tests.BDD/Base/BaseIntegrationTest.cs new file mode 100644 index 00000000..9d0bb0f8 --- /dev/null +++ b/ShareBook/ShareBook.Tests.BDD/Base/BaseIntegrationTest.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.TestHost; +using Microsoft.Extensions.Configuration; +using ShareBook.Api; +using System.IO; +using System.Net.Http; + +namespace ShareBook.Tests.BDD.Base +{ + public class BaseIntegrationTest + { + public TestServer Server { get; set; } + public HttpClient Client { get; set; } + + public BaseIntegrationTest() + { + + var builder = new ConfigurationBuilder() + .AddJsonFile("appsettings.json"); + var configuration = builder.Build(); + + var webHostBuilder = + new WebHostBuilder() + .UseConfiguration(configuration) + .UseEnvironment("Development") + .UseStartup(); + + Server = new TestServer(webHostBuilder); + Client = Server.CreateClient(); + } + } +} diff --git a/ShareBook/ShareBook.Tests.BDD/Configurations/ConfiguredLightBddScopeAttribute.cs b/ShareBook/ShareBook.Tests.BDD/Configurations/ConfiguredLightBddScopeAttribute.cs new file mode 100644 index 00000000..e6af4971 --- /dev/null +++ b/ShareBook/ShareBook.Tests.BDD/Configurations/ConfiguredLightBddScopeAttribute.cs @@ -0,0 +1,31 @@ +using LightBDD.Core.Configuration; +using LightBDD.Framework.Configuration; +using LightBDD.Framework.Reporting.Formatters; +using LightBDD.XUnit2; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ShareBook.Tests.BDD.Configurations +{ + class ConfiguredLightBddScopeAttribute : LightBddScopeAttribute + { + protected override void OnConfigure(LightBddConfiguration configuration) + { + // some example customization of report writers + configuration + .ReportWritersConfiguration() + .AddFileWriter("~\\Reports\\FeaturesReport.txt"); + } + + protected override void OnSetUp() + { + // additional code that has to be run before any LightBDD tests + } + + protected override void OnTearDown() + { + // additional code that has to be run after all LightBDD tests + } + } +} diff --git a/ShareBook/ShareBook.Tests.BDD/Features/RegisterUserFeature.Steps.cs b/ShareBook/ShareBook.Tests.BDD/Features/RegisterUserFeature.Steps.cs new file mode 100644 index 00000000..d40642fe --- /dev/null +++ b/ShareBook/ShareBook.Tests.BDD/Features/RegisterUserFeature.Steps.cs @@ -0,0 +1,44 @@ +using LightBDD.XUnit2; +using ShareBook.Api.ViewModels; +using ShareBook.Tests.BDD.Services; +using System.Net; +using System.Net.Http; +using Xunit; + +namespace ShareBook.Tests.BDD.Features +{ + public partial class RegisterUserFeature: FeatureFixture + { + private RegisterUserVM viewModel; + private HttpResponseMessage response; + + private void Given_new_user_want_to_join_with_this_datas() + { + viewModel = new RegisterUserVM() + { + Name = "Joaquim", + Password = "Joa.2019!", + Email = "joaquim@gmail.com", + City = "São Paulo", + PostalCode = "04473-150", + Linkedin = "linkedin.com/joaquim", + Neighborhood = "Vila Olimpia", + Street = "Rua teste", + Country = "Brasil", + State = "SP", + Number = "100" + }; + } + + private void When_the_new_user_registers() + { + UserService service = new UserService(); + response = service.RegisterAsync(viewModel).Result; + } + + private void Then_will_receive_a_success_message() + { + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + } +} \ No newline at end of file diff --git a/ShareBook/ShareBook.Tests.BDD/Features/RegisterUserFeature.cs b/ShareBook/ShareBook.Tests.BDD/Features/RegisterUserFeature.cs new file mode 100644 index 00000000..22d8b04e --- /dev/null +++ b/ShareBook/ShareBook.Tests.BDD/Features/RegisterUserFeature.cs @@ -0,0 +1,26 @@ +using LightBDD.Framework; +using LightBDD.Framework.Scenarios; +using LightBDD.XUnit2; +using ShareBook.Tests.BDD.Configurations; +using Xunit; + +[assembly: ConfiguredLightBddScope] +namespace ShareBook.Tests.BDD.Features +{ + [Label("REGISTER-USER")] + [FeatureDescription( + @"New user wants to join in sharebook plataform")] + public partial class RegisterUserFeature + { + [Label("Registration with all data correct.")] + [Scenario] + [Trait("Category", "BDD")] + public void Register_User_Successfully() + { + Runner.RunScenario( + Given_new_user_want_to_join_with_this_datas, + When_the_new_user_registers, + Then_will_receive_a_success_message); + } + } +} \ No newline at end of file diff --git a/ShareBook/ShareBook.Tests.BDD/Services/UserService.cs b/ShareBook/ShareBook.Tests.BDD/Services/UserService.cs new file mode 100644 index 00000000..5029a34b --- /dev/null +++ b/ShareBook/ShareBook.Tests.BDD/Services/UserService.cs @@ -0,0 +1,32 @@ +using Newtonsoft.Json; +using ShareBook.Api.ViewModels; +using ShareBook.Tests.BDD.Base; +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace ShareBook.Tests.BDD.Services +{ + public class UserService : BaseIntegrationTest + { + public async Task RegisterAsync(RegisterUserVM viewModel) + { + try + { + + string entity = JsonConvert.SerializeObject(viewModel); + + var response = await Client.PostAsync("/api/account/register", new StringContent(entity, Encoding.UTF8, "application/json")); + return response.EnsureSuccessStatusCode(); + } + catch (Exception e) + { + throw e; + } + + + } + } +} diff --git a/ShareBook/ShareBook.Tests.BDD/ShareBook.Tests.BDD.csproj b/ShareBook/ShareBook.Tests.BDD/ShareBook.Tests.BDD.csproj new file mode 100644 index 00000000..d2ced4ce --- /dev/null +++ b/ShareBook/ShareBook.Tests.BDD/ShareBook.Tests.BDD.csproj @@ -0,0 +1,46 @@ + + + + netcoreapp2.2 + + false + + + + + + + + + + + + + + + + + + + + + + + + + + Code + + + Code + + + + + + + Always + + + + diff --git a/ShareBook/ShareBook.Tests.BDD/appsettings.json b/ShareBook/ShareBook.Tests.BDD/appsettings.json new file mode 100644 index 00000000..4a3c692a --- /dev/null +++ b/ShareBook/ShareBook.Tests.BDD/appsettings.json @@ -0,0 +1,33 @@ +{ + "ConnectionStrings": { + // Coloque e descomente aqui pra usar um banco local + //"DefaultConnection": "Server=localhost\\sqlexpress;Database=ShareBook;Trusted_Connection=True;MultipleActiveResultSets=true" + //"DefaultConnection": "Server=localhost;Database=ShareBook;Trusted_Connection=True;MultipleActiveResultSets=true" + + // dev.sharebook.com.br + "DefaultConnection": "Data Source=SQL7003.site4now.net;Initial Catalog=DB_A3BA78_sharebookdev;Integrated Security=False;User ID=DB_A3BA78_sharebookdev_admin;Password=teste123@;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" + }, + "EmailSettings": { + "HostName": "mail.sharebook.com.br", + "Username": "contato_dev_stg@sharebook.com.br", + "Password": "123@mudar", + "Port": 465 + }, + "TokenConfigurations": { + "Audience": "ShareBookAudience", + "Issuer": "Sharebook", + "Seconds": 86400 + }, + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + }, + "ServerSettings": { + "DefaultUrl": "http://dev.sharebook.com.br", + "JobExecutorToken": "Jn6MLeT82c2zEnH9ktTDrrutNSZAkK9p", + } +} diff --git a/ShareBook/ShareBook.sln b/ShareBook/ShareBook.sln index efd896ee..a8c67669 100644 --- a/ShareBook/ShareBook.sln +++ b/ShareBook/ShareBook.sln @@ -33,6 +33,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sharebook.Jobs", "Sharebook EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShareBook.Infra.Data", "ShareBook.Repository\ShareBook.Infra.Data.csproj", "{4A07DFF3-3909-4081-8495-714179019A08}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShareBook.Tests.BDD", "ShareBook.Tests.BDD\ShareBook.Tests.BDD.csproj", "{84A85292-2B58-49C6-AC0F-5843D5962FDD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -71,6 +73,10 @@ Global {4A07DFF3-3909-4081-8495-714179019A08}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A07DFF3-3909-4081-8495-714179019A08}.Release|Any CPU.ActiveCfg = Release|Any CPU {4A07DFF3-3909-4081-8495-714179019A08}.Release|Any CPU.Build.0 = Release|Any CPU + {84A85292-2B58-49C6-AC0F-5843D5962FDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84A85292-2B58-49C6-AC0F-5843D5962FDD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84A85292-2B58-49C6-AC0F-5843D5962FDD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84A85292-2B58-49C6-AC0F-5843D5962FDD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -84,6 +90,7 @@ Global {F51F1D75-DC21-4B49-AE98-8E1292311D2B} = {F4693E98-387E-4804-A818-FEC59FEDD41C} {E59DF563-5B90-479E-9E08-FA99442EEE13} = {CC695E9A-927F-4BCA-B43F-1DD488258B6D} {4A07DFF3-3909-4081-8495-714179019A08} = {F4693E98-387E-4804-A818-FEC59FEDD41C} + {84A85292-2B58-49C6-AC0F-5843D5962FDD} = {4DC3351F-0B20-4D5E-8727-3730DF7A9B88} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FF5BA500-51EA-4DD9-8523-8EE368731B63}