Created
October 11, 2011 03:44
-
-
Save darrencauthon/1277219 to your computer and use it in GitHub Desktop.
Loose Guid support in SpecFlow?
This file contains hidden or 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
Feature: Loose Guids | |
Scenario: Sample loose guid | |
Given the account repository has the following accounts | |
| Id | LastName | | |
| 1 | Galt | | |
| 2 | Roark | | |
When I press the delete account '1' button | |
Then I should have the following accounts | |
| Id | LastName | | |
| 2 | Roark | |
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using TechTalk.SpecFlow; | |
using TechTalk.SpecFlow.Assist; | |
namespace TestSamples | |
{ | |
[Binding] | |
public class TestingSteps | |
{ | |
private List<Account> accounts; | |
[Given(@"the account repository has the following accounts")] | |
public void GivenTheAccountRepositoryHasTheFollowingAccounts(Table table) | |
{ | |
accounts = table.CreateSet<Account>().ToList(); | |
} | |
[When(@"I press the delete account '(.*)' button")] | |
public void WhenIPressTheDeleteAccount1Button(Guid id) | |
{ | |
accounts.RemoveAll(x => x.Id == id); | |
} | |
[Then(@"I should have the following accounts")] | |
public void ThenIShouldHaveTheFollowingAccounts(Table table) | |
{ | |
table.CompareToSet(accounts); | |
} | |
} | |
public class Account | |
{ | |
public Guid Id { get; set; } | |
public string LastName { get; set; } | |
} | |
} |
Nice Darren!
I've heard a lot of people stumbling on this one. Especially if you do CQRS with ES it's probably a common problem
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just note: The Id is a GUID, not an INT. A value like "1" or "2" above are padded with the necessary extra zeros in order to turn them into full guids.