Skip to content

Commit

Permalink
Merge pull request #238 from walter-lopes/feature/bdd
Browse files Browse the repository at this point in the history
Primeiro teste BDD escrito para o Sharebook
  • Loading branch information
danielaloisio authored Mar 21, 2019
2 parents 1722cfc + 56e2ea5 commit 6040f99
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ShareBook/ShareBook.Api/ShareBook.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="2.2.0" />
<PackageReference Include="AutoMapper" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="2.10.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Rollbar" Version="2.2.3" />
Expand Down
32 changes: 32 additions & 0 deletions ShareBook/ShareBook.Tests.BDD/Base/BaseIntegrationTest.cs
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();
}
}
}
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
}
}
}
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 ShareBook/ShareBook.Tests.BDD/Features/RegisterUserFeature.cs
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);
}
}
}
32 changes: 32 additions & 0 deletions ShareBook/ShareBook.Tests.BDD/Services/UserService.cs
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;
}


}
}
}
46 changes: 46 additions & 0 deletions ShareBook/ShareBook.Tests.BDD/ShareBook.Tests.BDD.csproj
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>
33 changes: 33 additions & 0 deletions ShareBook/ShareBook.Tests.BDD/appsettings.json
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",
}
}
7 changes: 7 additions & 0 deletions ShareBook/ShareBook.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down

0 comments on commit 6040f99

Please sign in to comment.