From 2ad294aa417d706873ef6eb5e4aac221766a34d0 Mon Sep 17 00:00:00 2001 From: Dylan Steele Date: Sat, 15 Jun 2019 15:21:38 -0400 Subject: [PATCH 1/2] added ranges to number scrubbers --- ShamWow.Interfaces/Attributes/ScrubDecimal.cs | 8 +++ ShamWow.Interfaces/Attributes/ScrubDouble.cs | 8 +++ ShamWow.Interfaces/Attributes/ScrubInteger.cs | 8 +++ ShamWow.Interfaces/Attributes/ScrubLong.cs | 8 +++ ShamWow.Interfaces/ShamWow.Interfaces.csproj | 3 +- ShamWow.Tests/RangeTest.cs | 51 +++++++++++++++++++ ShamWow/Processor/Router.cs | 22 +++++++- ShamWow/ShamWow.csproj | 3 +- 8 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 ShamWow.Tests/RangeTest.cs diff --git a/ShamWow.Interfaces/Attributes/ScrubDecimal.cs b/ShamWow.Interfaces/Attributes/ScrubDecimal.cs index a209692..d326843 100644 --- a/ShamWow.Interfaces/Attributes/ScrubDecimal.cs +++ b/ShamWow.Interfaces/Attributes/ScrubDecimal.cs @@ -7,6 +7,8 @@ namespace ShamWow.Interfaces.Attributes public class ScrubDecimal : Attribute { public DecimalScrubber scrubber { get; private set; } + public int start { get; private set; } + public int end { get; private set; } public ScrubDecimal() { } @@ -14,5 +16,11 @@ public ScrubDecimal(DecimalScrubber scrubber) { this.scrubber = scrubber; } + + public ScrubDecimal(int start, int end) + { + this.start = start; + this.end = end; + } } } diff --git a/ShamWow.Interfaces/Attributes/ScrubDouble.cs b/ShamWow.Interfaces/Attributes/ScrubDouble.cs index 8b45bb5..243cbca 100644 --- a/ShamWow.Interfaces/Attributes/ScrubDouble.cs +++ b/ShamWow.Interfaces/Attributes/ScrubDouble.cs @@ -7,6 +7,8 @@ namespace ShamWow.Interfaces.Attributes public class ScrubDouble : Attribute { public DoubleScrubber scrubber {get; private set; } + public int start { get; private set; } + public int end { get; private set; } public ScrubDouble() { } @@ -14,5 +16,11 @@ public ScrubDouble(DoubleScrubber scrubber) { this.scrubber = scrubber; } + + public ScrubDouble(int start, int end) + { + this.start = start; + this.end = end; + } } } diff --git a/ShamWow.Interfaces/Attributes/ScrubInteger.cs b/ShamWow.Interfaces/Attributes/ScrubInteger.cs index 3c3ead0..fe86788 100644 --- a/ShamWow.Interfaces/Attributes/ScrubInteger.cs +++ b/ShamWow.Interfaces/Attributes/ScrubInteger.cs @@ -7,6 +7,8 @@ namespace ShamWow.Interfaces.Attributes public class ScrubInteger : Attribute { public IntegerScrubber scrubber { get; private set; } + public int start { get; private set; } + public int end { get; private set; } public ScrubInteger() { } @@ -14,5 +16,11 @@ public ScrubInteger(IntegerScrubber scrubber) { this.scrubber = scrubber; } + + public ScrubInteger(int start, int end) + { + this.start = start; + this.end = end; + } } } diff --git a/ShamWow.Interfaces/Attributes/ScrubLong.cs b/ShamWow.Interfaces/Attributes/ScrubLong.cs index e8529ef..9a7abed 100644 --- a/ShamWow.Interfaces/Attributes/ScrubLong.cs +++ b/ShamWow.Interfaces/Attributes/ScrubLong.cs @@ -7,6 +7,8 @@ namespace ShamWow.Interfaces.Attributes public class ScrubLong : Attribute { public LongScrubber scrubber { get; set; } + public int start { get; private set; } + public int end { get; private set; } public ScrubLong() { } @@ -14,5 +16,11 @@ public ScrubLong(LongScrubber scrubber) { this.scrubber = scrubber; } + + public ScrubLong(int start, int end) + { + this.start = start; + this.end = end; + } } } diff --git a/ShamWow.Interfaces/ShamWow.Interfaces.csproj b/ShamWow.Interfaces/ShamWow.Interfaces.csproj index 4bd3b3f..01b1857 100644 --- a/ShamWow.Interfaces/ShamWow.Interfaces.csproj +++ b/ShamWow.Interfaces/ShamWow.Interfaces.csproj @@ -6,11 +6,12 @@ Dills122 Steele Inc. true - 2.1 + 2.2 Attributes and scrubbers for ShamWow scrubber. https://github.com/dills122/ShamWow/blob/master/LICENSE https://github.com/dills122/ShamWow + 2.2.0.0 diff --git a/ShamWow.Tests/RangeTest.cs b/ShamWow.Tests/RangeTest.cs new file mode 100644 index 0000000..af269b6 --- /dev/null +++ b/ShamWow.Tests/RangeTest.cs @@ -0,0 +1,51 @@ +using ShamWow.Interfaces.Attributes; +using ShamWow.Processor; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace ShamWow.Tests +{ + public class RangeTestObj + { + [ScrubDecimal(100,200)] + public decimal dec { get; set; } + [ScrubDouble(100, 200)] + public double dub { get; set; } + [ScrubInteger(100, 200)] + public int ing { get; set; } + [ScrubLong(100, 200)] + public long lng { get; set; } + } + + public class RangeTest + { + const int predefinedValue = 1000; + [Fact] + public void SimpleTest() + { + + var obj = new RangeTestObj { + dec = predefinedValue, + dub = predefinedValue, + ing = predefinedValue, + lng = predefinedValue + }; + + IShamWow processor = ShamWowEngine.GetFactory().Create(obj, Constants.ScrubMode.Marked); + + processor.Scrub(); + var cleanedData = (RangeTestObj)processor.CleanData(); + + var man = processor.GetManifest(); + Assert.InRange(cleanedData.dub, 100, 200); + Assert.InRange(cleanedData.dec, 100, 200); + Assert.InRange(cleanedData.ing, 100, 200); + Assert.InRange(cleanedData.lng, 100, 200); + Assert.NotNull(cleanedData); + Assert.IsType(cleanedData); + Assert.True(processor.CheckManifest()); + } + } +} diff --git a/ShamWow/Processor/Router.cs b/ShamWow/Processor/Router.cs index ec0b761..0842200 100644 --- a/ShamWow/Processor/Router.cs +++ b/ShamWow/Processor/Router.cs @@ -199,6 +199,11 @@ private object RouteIntegerType() ScrubInteger atr = propAttribute as ScrubInteger; IntegerScrubber attrScrubType = atr.scrubber; + if (atr.start > int.MinValue && atr.end > int.MinValue && atr.end > atr.start) + { + return Faker.RandomNumber.Next(atr.start, atr.end); + } + switch (attrScrubType) { case IntegerScrubber.Zip: @@ -271,10 +276,14 @@ private object RouteDecimalType() { ScrubDecimal atr = scrubber as ScrubDecimal; DecimalScrubber attrScrubType = atr.scrubber; - switch (attrScrubType) { default: + if(atr.start > int.MinValue && atr.end > int.MinValue && atr.end > atr.start) + { + var value = Faker.RandomNumber.Next(atr.start, atr.end); + return (decimal)(value == atr.end ? value : value + new Random().NextDouble()); + } var defaultValue = Faker.RandomNumber.Next(50000) + new Random().NextDouble(); return Convert.ToDecimal(defaultValue); } @@ -304,6 +313,11 @@ private object RouteDoubleType() switch (attrScrubType) { default: + if (atr.start > int.MinValue && atr.end > int.MinValue && atr.end > atr.start) + { + var value = Faker.RandomNumber.Next(atr.start, atr.end); + return value == atr.end ? value : value + new Random().NextDouble(); + } var defaultValue = Faker.RandomNumber.Next(50000) + new Random().NextDouble(); return defaultValue; } @@ -323,6 +337,12 @@ private object RouteLongType() ScrubLong atr = scrubber as ScrubLong; LongScrubber attrScrubType = atr.scrubber; + if (atr.start > int.MinValue && atr.end > int.MinValue && atr.end > atr.start) + { + var value = Faker.RandomNumber.Next(atr.start, atr.end); + return (long)(value == atr.end ? value : value + new Random().NextDouble()); + } + switch (attrScrubType) { case LongScrubber.Phone: diff --git a/ShamWow/ShamWow.csproj b/ShamWow/ShamWow.csproj index 3942910..cc48e26 100644 --- a/ShamWow/ShamWow.csproj +++ b/ShamWow/ShamWow.csproj @@ -10,10 +10,11 @@ ShamWow ShamWow true - 2.1 + 2.2 https://github.com/dills122/ShamWow/blob/master/LICENSE https://github.com/dills122/ShamWow + 2.2.0.0 From c4bf0e6ec259037b6f9b65b6fe3831ac881080a9 Mon Sep 17 00:00:00 2001 From: Dylan Steele Date: Sat, 15 Jun 2019 15:25:34 -0400 Subject: [PATCH 2/2] minor updates --- ShamWow.Tests/RangeTest.cs | 24 +++++------------------- ShamWow.Tests/TestModels/RangeTestObj.cs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 ShamWow.Tests/TestModels/RangeTestObj.cs diff --git a/ShamWow.Tests/RangeTest.cs b/ShamWow.Tests/RangeTest.cs index af269b6..e156406 100644 --- a/ShamWow.Tests/RangeTest.cs +++ b/ShamWow.Tests/RangeTest.cs @@ -1,32 +1,18 @@ -using ShamWow.Interfaces.Attributes; -using ShamWow.Processor; -using System; -using System.Collections.Generic; -using System.Text; +using ShamWow.Processor; +using ShamWow.Tests.TestModels; using Xunit; namespace ShamWow.Tests { - public class RangeTestObj - { - [ScrubDecimal(100,200)] - public decimal dec { get; set; } - [ScrubDouble(100, 200)] - public double dub { get; set; } - [ScrubInteger(100, 200)] - public int ing { get; set; } - [ScrubLong(100, 200)] - public long lng { get; set; } - } - public class RangeTest { const int predefinedValue = 1000; + [Fact] public void SimpleTest() { - - var obj = new RangeTestObj { + var obj = new RangeTestObj + { dec = predefinedValue, dub = predefinedValue, ing = predefinedValue, diff --git a/ShamWow.Tests/TestModels/RangeTestObj.cs b/ShamWow.Tests/TestModels/RangeTestObj.cs new file mode 100644 index 0000000..fc7c3f6 --- /dev/null +++ b/ShamWow.Tests/TestModels/RangeTestObj.cs @@ -0,0 +1,16 @@ +using ShamWow.Interfaces.Attributes; + +namespace ShamWow.Tests.TestModels +{ + public class RangeTestObj + { + [ScrubDecimal(100, 200)] + public decimal dec { get; set; } + [ScrubDouble(100, 200)] + public double dub { get; set; } + [ScrubInteger(100, 200)] + public int ing { get; set; } + [ScrubLong(100, 200)] + public long lng { get; set; } + } +}