- Specs class is too huge and often became unmanagable
- We can't extract action steps into different classes as they refer to class instance fields so we can't reuse actions steps across specs
[TestFixture]
public class EmailProcessingSagaSpecs
{
[Test]
public void ShouldSkipAttachmentToDeletedProject()
{
@"Given project 1
And requester with email 'sender@company.com'
And sender email is 'sender@company.com'
And profile has rules:
|Rule |
|then attach to project 2 |
|then attach to project 1 |
When the email arrived
Then the message should be attached to project 1"
.Execute(In.Context<EmailProcessingSagaActionSteps>());
}
[ActionSteps]
public class EmailProcessingSagaActionSteps
{
[BeforeScenario]
public void BeforeScenarioInit()
{
ObjectFactory.Initialize(x => { });
}
#region Action Steps
private static EmailProcessingSagaContext Context
{
get { return ObjectFactory.GetInstance<EmailProcessingSagaContext>(); }
}
[Given("project $projectId")]
public void AddProject(int projectId)
{
var projectStorage = Context.Storage.Get<ProjectDTO>();
projectStorage.Add(new ProjectDTO {ProjectID = projectId});
}
Context
public class EmailProcessingSagaContext : PopEmailIntegrationContext
{
private readonly EmailMessage _emailMessage;
private readonly IList<AttachmentDTO> _attachments = new List<AttachmentDTO>();
public EmailProcessingSagaContext()
{
//Self-register Context in object factory in order to ensure single context instance during specs execution
ObjectFactory.Configure(x => x.For<EmailProcessingSagaContext>().Use(this));
_emailMessage = new EmailMessage {FromDisplayName = "John Smith"};
}
public EmailMessage EmailMessage
{
get { return _emailMessage; }
}
public IList<AttachmentDTO> Attachments
{
get { return _attachments; }
}
Комментариев нет:
Отправить комментарий