22using Microsoft . Extensions . DependencyInjection ;
33using Microsoft . VisualStudio . TestTools . UnitTesting ;
44using MigrationTools . DataContracts ;
5- using MigrationTools . Endpoints ;
6- using MigrationTools . Processors ;
7- using MigrationTools . Tests ;
8- using Microsoft . Extensions . Options ;
9- using MigrationTools . Tools ;
105using MigrationTools . Shadows ;
6+ using MigrationTools . Tools ;
117
128namespace MigrationTools . ProcessorEnrichers . Tests
139{
@@ -21,7 +17,7 @@ public void StringManipulatorTool_ConfigureTest()
2117 var options = new StringManipulatorToolOptions ( ) ;
2218 options . Enabled = true ;
2319 options . MaxStringLength = 10 ;
24- options . Manipulators = new List < RegexStringManipulator >
20+ options . Manipulators = new List < RegexStringManipulator >
2521 {
2622 new RegexStringManipulator
2723 {
@@ -40,10 +36,10 @@ public void StringManipulatorTool_ConfigureTest()
4036 [ TestMethod ( ) , TestCategory ( "L1" ) ]
4137 public void StringManipulatorTool_RegexTest ( )
4238 {
43- var options = new StringManipulatorToolOptions ( ) ;
39+ var options = new StringManipulatorToolOptions ( ) ;
4440 options . Enabled = true ;
45- options . MaxStringLength = 10 ;
46- options . Manipulators = new List < RegexStringManipulator >
41+ options . MaxStringLength = 10 ;
42+ options . Manipulators = new List < RegexStringManipulator >
4743 {
4844 new RegexStringManipulator
4945 {
@@ -56,40 +52,24 @@ public void StringManipulatorTool_RegexTest()
5652
5753 var x = GetStringManipulatorTool ( options ) ;
5854
59- var fieldItem = new FieldItem
60- {
61- FieldType = "String" ,
62- internalObject = null ,
63- ReferenceName = "Custom.Test" ,
64- Name = "Test" ,
65- Value = "Test"
66- } ;
67-
68- x . ProcessorExecutionWithFieldItem ( null , fieldItem ) ;
55+ string value = "Test" ;
56+ string ? newValue = x . ProcessString ( value ) ;
6957
70- Assert . AreEqual ( "Test 2" , fieldItem . Value ) ;
58+ Assert . AreEqual ( "Test 2" , newValue ) ;
7159 }
7260
7361 [ TestMethod ( ) , TestCategory ( "L1" ) ]
7462 public void StringManipulatorTool_LengthShorterThanMaxTest ( )
7563 {
7664 var options = new StringManipulatorToolOptions ( ) ;
7765 options . Enabled = true ;
78- options . MaxStringLength = 10 ;
66+ options . MaxStringLength = 10 ;
7967 var x = GetStringManipulatorTool ( options ) ;
8068
81- var fieldItem = new FieldItem
82- {
83- FieldType = "String" ,
84- internalObject = null ,
85- ReferenceName = "Custom.Test" ,
86- Name = "Test" ,
87- Value = "Test"
88- } ;
89-
90- x . ProcessorExecutionWithFieldItem ( null , fieldItem ) ;
69+ string value = "Test" ;
70+ string ? newValue = x . ProcessString ( value ) ;
9171
92- Assert . AreEqual ( 4 , fieldItem . Value . ToString ( ) . Length ) ;
72+ Assert . AreEqual ( 4 , newValue . Length ) ;
9373 }
9474
9575 [ TestMethod ( ) , TestCategory ( "L1" ) ]
@@ -100,24 +80,93 @@ public void StringManipulatorTool_LengthLongerThanMaxTest()
10080 options . MaxStringLength = 10 ;
10181 var x = GetStringManipulatorTool ( options ) ;
10282
103- var fieldItem = new FieldItem
104- {
105- FieldType = "String" ,
106- internalObject = null ,
107- ReferenceName = "Custom.Test" ,
108- Name = "Test" ,
109- Value = "Test Test Test Test Test Test Test Test Test Test Test Test Test"
110- } ;
83+ string value = "Test Test Test Test Test Test Test Test Test Test Test Test Test" ;
84+ string ? newValue = x . ProcessString ( value ) ;
11185
112- x . ProcessorExecutionWithFieldItem ( null , fieldItem ) ;
86+ Assert . AreEqual ( 10 , newValue . Length ) ;
87+ }
11388
114- Assert . AreEqual ( 10 , fieldItem . Value . ToString ( ) . Length ) ;
89+ [ DataTestMethod ( ) , TestCategory ( "L1" ) ]
90+ [ DataRow ( null , null ) ]
91+ [ DataRow ( "" , "" ) ]
92+ [ DataRow ( "lorem" , "lorem" ) ]
93+ public void StringManipulatorTool_Disabled ( string ? value , string ? expected )
94+ {
95+ var options = new StringManipulatorToolOptions ( ) ;
96+ options . Enabled = false ;
97+ options . MaxStringLength = 15 ;
98+ options . Manipulators = new List < RegexStringManipulator >
99+ {
100+ new RegexStringManipulator
101+ {
102+ Enabled = true ,
103+ Pattern = "(^.*$)" ,
104+ Replacement = "$1 $1" ,
105+ Description = "Test"
106+ }
107+ } ;
108+ var x = GetStringManipulatorTool ( options ) ;
109+
110+ string ? newValue = x . ProcessString ( value ) ;
111+ Assert . AreEqual ( expected , newValue ) ;
115112 }
116113
117- private static StringManipulatorTool GetStringManipulatorTool ( )
114+ [ DataTestMethod ( ) , TestCategory ( "L1" ) ]
115+ [ DataRow ( null , null ) ]
116+ [ DataRow ( "" , " " ) ]
117+ [ DataRow ( "lorem" , "lorem lorem" ) ]
118+ [ DataRow ( "lorem ipsum" , "lorem ipsum lor" ) ]
119+ public void StringManipulatorTool_Process ( string ? value , string ? expected )
118120 {
119- var options = new StringManipulatorToolOptions ( ) ;
120- return GetStringManipulatorTool ( options ) ;
121+ var options = new StringManipulatorToolOptions ( ) ;
122+ options . Enabled = true ;
123+ options . MaxStringLength = 15 ;
124+ options . Manipulators = new List < RegexStringManipulator >
125+ {
126+ new RegexStringManipulator
127+ {
128+ Enabled = true ,
129+ Pattern = "(^.*$)" ,
130+ Replacement = "$1 $1" ,
131+ Description = "Test"
132+ }
133+ } ;
134+ var x = GetStringManipulatorTool ( options ) ;
135+
136+ string ? newValue = x . ProcessString ( value ) ;
137+ Assert . AreEqual ( expected , newValue ) ;
138+ }
139+
140+ [ DataTestMethod ( ) , TestCategory ( "L1" ) ]
141+ [ DataRow ( null , null ) ]
142+ [ DataRow ( "" , " 1 2" ) ]
143+ [ DataRow ( "lorem" , "lorem 1 2" ) ]
144+ public void StringManipulatorTool_MultipleManipulators ( string ? value , string ? expected )
145+ {
146+ var options = new StringManipulatorToolOptions ( ) ;
147+ options . Enabled = true ;
148+ options . MaxStringLength = 15 ;
149+ options . Manipulators = new List < RegexStringManipulator >
150+ {
151+ new RegexStringManipulator
152+ {
153+ Enabled = true ,
154+ Pattern = "(^.*$)" ,
155+ Replacement = "$1 1" ,
156+ Description = "Add 1"
157+ } ,
158+ new RegexStringManipulator
159+ {
160+ Enabled = true ,
161+ Pattern = "(^.*$)" ,
162+ Replacement = "$1 2" ,
163+ Description = "Add 2"
164+ }
165+ } ;
166+ var x = GetStringManipulatorTool ( options ) ;
167+
168+ string ? newValue = x . ProcessString ( value ) ;
169+ Assert . AreEqual ( expected , newValue ) ;
121170 }
122171
123172 private static StringManipulatorTool GetStringManipulatorTool ( StringManipulatorToolOptions options )
@@ -134,4 +183,4 @@ private static StringManipulatorTool GetStringManipulatorTool(StringManipulatorT
134183 return services . BuildServiceProvider ( ) . GetService < StringManipulatorTool > ( ) ;
135184 }
136185 }
137- }
186+ }
0 commit comments