-
-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1) Create StringManipulatorEnricher 2) String field too long 3) String field is shortter than max 4) Apply regex manipulator
- Loading branch information
Showing
3 changed files
with
166 additions
and
11 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
src/MigrationTools.Tests/ProcessorEnrichers/StringManipulatorEnricherTests.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using MigrationTools.DataContracts; | ||
using MigrationTools.Endpoints; | ||
using MigrationTools.Enrichers; | ||
using MigrationTools.ProcessorEnrichers.WorkItemProcessorEnrichers; | ||
using MigrationTools.Processors; | ||
using MigrationTools.Tests; | ||
|
||
namespace MigrationTools.ProcessorEnrichers.Tests | ||
{ | ||
[TestClass()] | ||
public class StringManipulatorEnricherTests | ||
{ | ||
private ServiceProvider Services; | ||
|
||
[TestInitialize] | ||
public void Setup() | ||
{ | ||
Services = ServiceProviderHelper.GetWorkItemMigrationProcessor(); | ||
} | ||
|
||
[TestMethod(), TestCategory("L0"), TestCategory("Generic.Processor")] | ||
public void StringManipulatorEnricher_ConfigureTest() | ||
{ | ||
var y = new StringManipulatorEnricherOptions | ||
{ | ||
Enabled = true, | ||
MaxStringLength = 10, | ||
Manipulators = new List<RegexStringManipulator> | ||
{ | ||
new RegexStringManipulator | ||
{ | ||
Enabled = true, | ||
Pattern = ".*", | ||
Replacement = "Test", | ||
Description = "Test" | ||
} | ||
} | ||
|
||
}; | ||
var x = Services.GetRequiredService<StringManipulatorEnricher>(); | ||
x.Configure(y); | ||
Assert.IsNotNull(x); | ||
} | ||
|
||
[TestMethod(), TestCategory("L1"), TestCategory("ProcessorEnrichers")] | ||
public void StringManipulatorEnricher_RegexTest() | ||
{ | ||
var y = new StringManipulatorEnricherOptions | ||
{ | ||
Enabled = true, | ||
MaxStringLength = 10, | ||
Manipulators = new List<RegexStringManipulator> | ||
{ | ||
new RegexStringManipulator | ||
{ | ||
Enabled = true, | ||
Pattern = "Test", | ||
Replacement = "Test 2", | ||
Description = "Test" | ||
} | ||
} | ||
|
||
}; | ||
var x = Services.GetRequiredService<StringManipulatorEnricher>(); | ||
x.Configure(y); | ||
|
||
var fieldItem = new FieldItem | ||
{ | ||
FieldType = "String", | ||
internalObject = null, | ||
ReferenceName = "Custom.Test", | ||
Name = "Test", | ||
Value = "Test" | ||
}; | ||
|
||
|
||
x.ProcessorExecutionWithFieldItem(null, fieldItem); | ||
|
||
Assert.AreEqual("Test 2", fieldItem.Value); | ||
} | ||
|
||
[TestMethod(), TestCategory("L1"), TestCategory("ProcessorEnrichers")] | ||
public void StringManipulatorEnricher_LengthShorterThanMaxTest() | ||
{ | ||
var y = new StringManipulatorEnricherOptions | ||
{ | ||
Enabled = true, | ||
MaxStringLength = 10, | ||
}; | ||
var x = Services.GetRequiredService<StringManipulatorEnricher>(); | ||
x.Configure(y); | ||
|
||
var fieldItem = new FieldItem | ||
{ | ||
FieldType = "String", | ||
internalObject = null, | ||
ReferenceName = "Custom.Test", | ||
Name = "Test", | ||
Value = "Test" | ||
}; | ||
|
||
|
||
x.ProcessorExecutionWithFieldItem(null, fieldItem); | ||
|
||
Assert.AreEqual(4, fieldItem.Value.ToString().Length); | ||
} | ||
|
||
[TestMethod(), TestCategory("L1"), TestCategory("ProcessorEnrichers")] | ||
public void StringManipulatorEnricher_LengthLongerThanMaxTest() | ||
{ | ||
var y = new StringManipulatorEnricherOptions | ||
{ | ||
Enabled = true, | ||
MaxStringLength = 10, | ||
}; | ||
var x = Services.GetRequiredService<StringManipulatorEnricher>(); | ||
x.Configure(y); | ||
|
||
var fieldItem = new FieldItem | ||
{ | ||
FieldType = "String", | ||
internalObject = null, | ||
ReferenceName = "Custom.Test", | ||
Name = "Test", | ||
Value = "Test Test Test Test Test Test Test Test Test Test Test Test Test" | ||
}; | ||
|
||
|
||
x.ProcessorExecutionWithFieldItem(null, fieldItem); | ||
|
||
Assert.AreEqual(10, fieldItem.Value.ToString().Length); | ||
} | ||
} | ||
} |
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
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