11using System ;
22using System . Diagnostics ;
33using System . Linq ;
4- using System . Text ;
54
65namespace TestStack . BDDfy
76{
87 public class StoryAttributeMetadataScanner : IStoryMetadataScanner
98 {
10- // ReSharper disable InconsistentNaming
11- private const string I_want_prefix = "I want" ;
12- private const string So_that_prefix = "So that" ;
13- private const string As_a_prefix = "As a" ;
14- private const string In_order_to_prefix = "In order to" ;
15- // ReSharper restore InconsistentNaming
16-
179 public virtual StoryMetadata Scan ( object testObject , Type explicitStoryType = null )
1810 {
1911 return GetStoryMetadata ( testObject , explicitStoryType ) ?? GetStoryMetadataFromScenario ( testObject ) ;
@@ -26,7 +18,7 @@ static StoryMetadata GetStoryMetadataFromScenario(object testObject)
2618 if ( storyAttribute == null )
2719 return null ;
2820
29- return CreateStoryMetadata ( scenarioType , storyAttribute ) ;
21+ return new StoryMetadata ( scenarioType , storyAttribute ) ;
3022 }
3123
3224 StoryMetadata GetStoryMetadata ( object testObject , Type explicityStoryType )
@@ -39,45 +31,7 @@ StoryMetadata GetStoryMetadata(object testObject, Type explicityStoryType)
3931 if ( storyAttribute == null )
4032 return null ;
4133
42- return CreateStoryMetadata ( candidateStoryType , storyAttribute ) ;
43- }
44-
45- static StoryMetadata CreateStoryMetadata ( Type storyType , StoryAttribute storyAttribute )
46- {
47- var title = storyAttribute . Title ;
48- if ( string . IsNullOrEmpty ( title ) )
49- title = NetToString . Convert ( storyType . Name ) ;
50-
51- string narrative1 , narrative2 , narrative3 ;
52-
53- if ( ! string . IsNullOrWhiteSpace ( storyAttribute . InOrderTo ) )
54- {
55- narrative1 = CleanseProperty ( storyAttribute . InOrderTo , In_order_to_prefix ) ;
56- narrative2 = CleanseProperty ( storyAttribute . AsA , As_a_prefix ) ;
57- narrative3 = CleanseProperty ( storyAttribute . IWant , I_want_prefix ) ;
58- }
59- else
60- {
61- narrative1 = CleanseProperty ( storyAttribute . AsA , As_a_prefix ) ;
62- narrative2 = CleanseProperty ( storyAttribute . IWant , I_want_prefix ) ;
63- narrative3 = CleanseProperty ( storyAttribute . SoThat , So_that_prefix ) ;
64- }
65-
66- return new StoryMetadata ( storyType , narrative1 , narrative2 , narrative3 , title ) ;
67- }
68-
69- static string CleanseProperty ( string text , string prefix )
70- {
71- var property = new StringBuilder ( ) ;
72-
73- if ( string . IsNullOrWhiteSpace ( text ) )
74- return null ;
75-
76- if ( ! text . StartsWith ( prefix , StringComparison . OrdinalIgnoreCase ) )
77- property . AppendFormat ( "{0} " , prefix ) ;
78-
79- property . Append ( text ) ;
80- return property . ToString ( ) ;
34+ return new StoryMetadata ( candidateStoryType , storyAttribute ) ;
8135 }
8236
8337 protected virtual Type GetCandidateStory ( object testObject , Type explicitStoryType )
@@ -99,9 +53,9 @@ protected virtual Type GetCandidateStory(object testObject, Type explicitStoryTy
9953 return firstFrame . GetMethod ( ) . DeclaringType ;
10054 }
10155
102- static StoryAttribute GetStoryAttribute ( Type candidateStoryType )
56+ static StoryNarrativeAttribute GetStoryAttribute ( Type candidateStoryType )
10357 {
104- return ( StoryAttribute ) candidateStoryType . GetCustomAttributes ( typeof ( StoryAttribute ) , true ) . FirstOrDefault ( ) ;
58+ return ( StoryNarrativeAttribute ) candidateStoryType . GetCustomAttributes ( typeof ( StoryNarrativeAttribute ) , true ) . FirstOrDefault ( ) ;
10559 }
10660 }
10761}
0 commit comments