Skip to content

Commit

Permalink
Merge pull request #16 from dills122/number-range
Browse files Browse the repository at this point in the history
added ranges to number scrubbers
  • Loading branch information
dills122 authored Jun 15, 2019
2 parents dab59cd + c4bf0e6 commit 78b2c05
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 3 deletions.
8 changes: 8 additions & 0 deletions ShamWow.Interfaces/Attributes/ScrubDecimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ 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() { }

public ScrubDecimal(DecimalScrubber scrubber)
{
this.scrubber = scrubber;
}

public ScrubDecimal(int start, int end)
{
this.start = start;
this.end = end;
}
}
}
8 changes: 8 additions & 0 deletions ShamWow.Interfaces/Attributes/ScrubDouble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ 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() { }

public ScrubDouble(DoubleScrubber scrubber)
{
this.scrubber = scrubber;
}

public ScrubDouble(int start, int end)
{
this.start = start;
this.end = end;
}
}
}
8 changes: 8 additions & 0 deletions ShamWow.Interfaces/Attributes/ScrubInteger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ 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() { }

public ScrubInteger(IntegerScrubber scrubber)
{
this.scrubber = scrubber;
}

public ScrubInteger(int start, int end)
{
this.start = start;
this.end = end;
}
}
}
8 changes: 8 additions & 0 deletions ShamWow.Interfaces/Attributes/ScrubLong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ 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() { }

public ScrubLong(LongScrubber scrubber)
{
this.scrubber = scrubber;
}

public ScrubLong(int start, int end)
{
this.start = start;
this.end = end;
}
}
}
3 changes: 2 additions & 1 deletion ShamWow.Interfaces/ShamWow.Interfaces.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
<Authors>Dills122</Authors>
<Company>Steele Inc.</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.1</Version>
<Version>2.2</Version>
<Description>Attributes and scrubbers for ShamWow scrubber.</Description>
<PackageProjectUrl></PackageProjectUrl>
<PackageLicenseUrl>https://github.com/dills122/ShamWow/blob/master/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/dills122/ShamWow</RepositoryUrl>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
</PropertyGroup>

</Project>
37 changes: 37 additions & 0 deletions ShamWow.Tests/RangeTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using ShamWow.Processor;
using ShamWow.Tests.TestModels;
using Xunit;

namespace ShamWow.Tests
{
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<RangeTestObj>(cleanedData);
Assert.True(processor.CheckManifest());
}
}
}
16 changes: 16 additions & 0 deletions ShamWow.Tests/TestModels/RangeTestObj.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
22 changes: 21 additions & 1 deletion ShamWow/Processor/Router.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion ShamWow/ShamWow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<AssemblyName>ShamWow</AssemblyName>
<RootNamespace>ShamWow</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.1</Version>
<Version>2.2</Version>
<PackageLicenseUrl>https://github.com/dills122/ShamWow/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl></PackageProjectUrl>
<RepositoryUrl>https://github.com/dills122/ShamWow</RepositoryUrl>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 78b2c05

Please # to comment.