-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from walter-lopes/feature/bdd
Primeiro teste BDD escrito para o Sharebook
- Loading branch information
Showing
9 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Startup>(); | ||
|
||
Server = new TestServer(webHostBuilder); | ||
Client = Server.CreateClient(); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
ShareBook/ShareBook.Tests.BDD/Configurations/ConfiguredLightBddScopeAttribute.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PlainTextReportFormatter>("~\\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 | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
ShareBook/ShareBook.Tests.BDD/Features/RegisterUserFeature.Steps.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "[email protected]", | ||
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); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
ShareBook/ShareBook.Tests.BDD/Features/RegisterUserFeature.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HttpResponseMessage> 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; | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="LightBDD" Version="2.1.0" /> | ||
<PackageReference Include="LightBDD.XUnit2" Version="3.0.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
<PackageReference Include="FluentAssertions" Version="5.4.2" /> | ||
<PackageReference Include="BoDi" Version="1.4.0-alpha1" /> | ||
</ItemGroup> | ||
|
||
|
||
<ItemGroup> | ||
<Folder Include="Steps\" /> | ||
</ItemGroup> | ||
|
||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ShareBook.Api\ShareBook.Api.csproj" /> | ||
</ItemGroup> | ||
|
||
|
||
<ItemGroup> | ||
<Compile Update="Features\RegisterUserFeature.cs"> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Update="Features\RegisterUserFeature.Steps.cs"> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
|
||
<ItemGroup> | ||
<None Update="appsettings.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]", | ||
"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", | ||
} | ||
} |
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