Created
October 31, 2010 04:04
-
-
Save jdomzhang/656107 to your computer and use it in GitHub Desktop.
Sample file for discussion in SpecFlow google group [http://groups.google.com/group/specflow/browse_thread/thread/191919a95970b2a0]
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using TechTalk.SpecFlow; | |
using Rhino.Mocks; | |
using Domain; | |
using NUnit.Framework; | |
namespace SpecFlowGroup1 { | |
[Binding] | |
public class StepDefinition1 { | |
[Given(@"that there are (\d+) records on the database")] | |
public void that_there_are_x_records_on_the_database(int Count) | |
{ | |
var segmentRepo = MockRepository.GenerateMock<ISegmentRepository>(); | |
segmentRepo.Expect(x => x.Get_segments_count()).Return(Count); | |
ScenarioContext.Current.Add("segmentRepo", segmentRepo); | |
} | |
[Given(@"that the file (\w+\.\w+) has (\d+) lines")] | |
public void And_that_file_x_has_x_lines(string Filename, int Lines) | |
{ | |
var lines = ""; | |
for (var i = 0; i < Lines; i++) | |
lines += "01-01-01-001-001,10/23/2010 10:03 AM,30,80,60\n"; | |
var ioWrapper = MockRepository.GenerateMock<ISystemIOWrapper>(); | |
ioWrapper.Expect(x => x.File_contents(Filename)).IgnoreArguments().Return(lines.Substring(0, lines.Length - 2).Split('\n')); | |
ScenarioContext.Current.Add("ioWrapper", ioWrapper); | |
} | |
[When(@"the file is parsed")] | |
public void When_the_file_is_parsed() | |
{ | |
var segmentRepo = (ISegmentRepository)ScenarioContext.Current["segmentRepo"]; | |
var ioWrapper = (ISystemIOWrapper)ScenarioContext.Current["ioWrapper"]; | |
var parser = new NewFileParser(); | |
parser.IO_wrapper = ioWrapper; | |
parser.Segment_repository = segmentRepo; | |
parser.Parse("filePath"); | |
ScenarioContext.Current.Add("parser", parser); | |
} | |
[Then(@"the file must be flagged as valid")] | |
public void Then_the_file_must_be_flagged_as_valid() | |
{ | |
// I do nothing here, but I think I should | |
} | |
[Then(@"the formatter process must be called")] | |
public void Then_the_formatter_process_must_be_called() | |
{ | |
var parser = (NewFileParser)ScenarioContext.Current["parser"]; | |
var segmentRepo = (ISegmentRepository)ScenarioContext.Current["segmentRepo"]; | |
var ioWrapper = (ISystemIOWrapper)ScenarioContext.Current["ioWrapper"]; | |
segmentRepo.VerifyAllExpectations(); | |
ioWrapper.VerifyAllExpectations(); | |
Assert.IsTrue(parser.Is_valid); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment