Feature: Manage Basic Customer Registration
@CustomerRegistration
Scenario: Register Name and Last Name
Given I have entered Name Jessé into the form
And I have entered Last Name Toledo into the form
When I press add
Then the result should be the Full Name registered
@CustomerRegistration
Scenario: Unregistered Name and Last Name
Given I have entered Name <Name> into the form
And I have entered Last Name <LastName> into the form
When I press add
Then the result should be the Full Name unregistered
Examples:
| Name | LastName |
| <null> | Toledo |
| Jessé | <null> |
| <null> | <null> |
CustomerRegistrationStep.cs
[Binding]publicsealedclassCustomerRegistrationStep{privatereadonlyCustomer_customer;privatereadonlyHttpClient_client;privateHttpResponseMessage_response;publicCustomerRegistrationStep(WebApplicationFactory<Startup>webApplicationFactory){_customer=newCustomer();varfactory=webApplicationFactory.WithWebHostBuilder(builder =>{builder.ConfigureAppConfiguration((host,config)=>{config.AddTestConfig(host.HostingEnvironment);});});_client=factory.CreateClient();}[Given(@"I have entered Name (.*) into the form")]publicvoidGivenIHaveEnteredNameIntoTheForm(stringname){_customer.Name=name;}[Given(@"I have entered Last Name (.*) into the form")]publicvoidGivenIHaveEnteredLastNameIntoTheForm(stringlastName){_customer.LastName=lastName;}[When(@"I press add")]publicasyncTaskWhenIPressAdd(){varjson=Utf8Json.JsonSerializer.PrettyPrint(Utf8Json.JsonSerializer.Serialize(_customer));_response=await_client.PostAsync("/api/CustomerRegistration",newStringContent(json,Encoding.UTF8,"application/json")).ConfigureAwait(false);}[Then(@"the result should be the Full Name registered")]publicasyncTaskThenTheResultShouldBeTheFullNameRegistered(){_response.EnsureSuccessStatusCode();varbody=await_response.Content.ReadAsStringAsync().ConfigureAwait(false);varactual=JsonConvert.DeserializeObject<int>(body);actual.Should().NotBe(0);}[Then(@"the result should be the Full Name unregistered")]publicvoidThenTheResultShouldBeTheFullNameUnregistered(){_response.StatusCode.Should().Be(HttpStatusCode.BadRequest);}}
Leave a Reply