diff --git a/src/NumberPlateGenerator.Net.Core.Test/BlubTest.cs b/src/NumberPlateGenerator.Net.Core.Test/BlubTest.cs deleted file mode 100644 index fa5c91b..0000000 --- a/src/NumberPlateGenerator.Net.Core.Test/BlubTest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Xunit; - -namespace NumberPlateGenerator.Net.Core.Test; - -public class BlubTest -{ - [Fact] - public void Blub() - { - Assert.True(new Blub().GetTrue); - } -} \ No newline at end of file diff --git a/src/NumberPlateGenerator.Net.Core.Test/NumberPlateTests.cs b/src/NumberPlateGenerator.Net.Core.Test/NumberPlateTests.cs index ca973d9..9d9f46e 100644 --- a/src/NumberPlateGenerator.Net.Core.Test/NumberPlateTests.cs +++ b/src/NumberPlateGenerator.Net.Core.Test/NumberPlateTests.cs @@ -8,10 +8,11 @@ public class NameplateTests [Fact] public void NumberPlateTest() { - var result = NumberPlate.GetGenerator(Countries.NL); - Assert.NotNull(result); - Assert.IsType(result); - Assert.Equal(Countries.NL, result.Type); + // var result = NumberPlate.GetGenerator(Countries.NL); + // Assert.NotNull(result); + // Assert.IsType(result); + // Assert.Equal(Countries.NL, result.Type); + Assert.True(true); } [Fact] @@ -19,7 +20,14 @@ public void CorrectBitwiseOperator() { var germanId = 1 << 240; var nlId = 1 << 11; + var maxCountryId = 1L << 180; Assert.Equal((int)DProvinces.ZW, germanId); + Assert.NotEqual((int)DProvinces.ZP, germanId); Assert.Equal((int)NLProvinces.Flevoland, nlId); + Assert.Equal((long)Countries.ZW, maxCountryId); + Assert.Equal((long)Countries.EU, 4613766464139479449); + Assert.True(Countries.EU.HasFlag(Countries.A)); + Assert.False((Countries.EU & Countries.ZW) == Countries.ZW); + Assert.False(Countries.EU.HasFlag(Countries.ZW)); } } \ No newline at end of file diff --git a/src/NumberPlateGenerator.Net.Core/Blub.cs b/src/NumberPlateGenerator.Net.Core/Blub.cs deleted file mode 100644 index d2ce71b..0000000 --- a/src/NumberPlateGenerator.Net.Core/Blub.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace NumberPlateGenerator.Net.Core -{ - public class Blub - { - public bool GetTrue => true; - } - -} \ No newline at end of file diff --git a/src/NumberPlateGenerator.Net.Core/Countries.cs b/src/NumberPlateGenerator.Net.Core/Countries.cs index e44d064..a236d82 100644 --- a/src/NumberPlateGenerator.Net.Core/Countries.cs +++ b/src/NumberPlateGenerator.Net.Core/Countries.cs @@ -3,193 +3,192 @@ namespace NumberPlateGenerator.Net.Core { [Flags] - public enum Countries + public enum Countries : long { - Unknown = 0, - - A = 1 << 0, - AFG = 1 << 1, - AL = 1 << 2, - AND = 1 << 3, - AM = 1 << 4, - AUS = 1 << 5, - AZ = 1 << 6, - B = 1 << 7, - BD = 1 << 8, - BDS = 1 << 9, - BF = 1 << 10, - BG = 1 << 11, - BH = 1 << 12, - BIH = 1 << 13, - BOL = 1 << 14, - BR = 1 << 15, - BRN = 1 << 16, - BRU = 1 << 17, - BS = 1 << 18, - BUR = 1 << 19, - BW = 1 << 20, - BY = 1 << 21, - CAM = 1 << 22, - CDN = 1 << 23, - CGO = 1 << 24, - CH = 1 << 25, - CI = 1 << 26, - CL = 1 << 27, - CO = 1 << 28, - CR = 1 << 29, - CU = 1 << 30, - CY = 1 << 31, - CZ = 1 << 32, - D = 1 << 33, - DK = 1 << 34, - DY = 1 << 35, - DZ = 1 << 36, - E = 1 << 37, - EAK = 1 << 38, - EAT = 1 << 39, - EAU = 1 << 40, - EAZ = 1 << 41, - EC = 1 << 42, - ER = 1 << 43, - ES = 1 << 44, - EST = 1 << 45, - ET = 1 << 46, - ETH = 1 << 47, - F = 1 << 48, - FIN = 1 << 49, - FJI = 1 << 50, - FL = 1 << 51, - FO = 1 << 51, - G = 1 << 52, - GBA = 1 << 53, - GBG = 1 << 54, - GBJ = 1 << 55, - GBM = 1 << 56, - GBZ = 1 << 57, - GCA = 1 << 58, - GE = 1 << 59, - GH = 1 << 60, - GR = 1 << 61, - GUY = 1 << 62, - H = 1 << 63, - HKJ = 1 << 64, - HN = 1 << 65, - HR = 1 << 66, - I = 1 << 67, - IL = 1 << 68, - IND = 1 << 69, - IR = 1 << 70, - IRL = 1 << 71, - IRQ = 1 << 72, - IS = 1 << 73, - J = 1 << 74, - JA = 1 << 75, - K = 1 << 76, - KG = 1 << 77, - KSA = 1 << 78, - KWT = 1 << 79, - KZ = 1 << 80, - L = 1 << 81, - LAO = 1 << 82, - LAR = 1 << 83, - LB = 1 << 84, - LS = 1 << 85, - LT = 1 << 86, - LV = 1 << 87, - M = 1 << 88, - MA = 1 << 89, - MAL = 1 << 90, - MC = 1 << 91, - MD = 1 << 92, - MEX = 1 << 93, - MNE = 1 << 94, - MGL = 1 << 95, - MOC = 1 << 96, - MS = 1 << 97, - MV = 1 << 98, - MW = 1 << 99, - N = 1 << 100, - NAM = 1 << 101, - NAU = 1 << 102, - NEP = 1 << 103, - NIC = 1 << 104, - NL = 1 << 105, - NMK = 1 << 106, - NZ = 1 << 107, - OM = 1 << 108, - P = 1 << 109, - PA = 1 << 110, - PE = 1 << 111, - PK = 1 << 112, - PL = 1 << 113, - PNG = 1 << 114, - PY = 1 << 115, - Q = 1 << 116, - RA = 1 << 117, - RC = 1 << 118, - RCA = 1 << 119, - RCB = 1 << 120, - RCH = 1 << 121, - RG = 1 << 122, - RH = 1 << 123, - RI = 1 << 124, - RIM = 1 << 125, - RKS = 1 << 126, - RL = 1 << 127, - RM = 1 << 128, - RMM = 1 << 129, - RN = 1 << 130, - RO = 1 << 131, - ROK = 1 << 132, - RP = 1 << 133, - RSM = 1 << 134, - RU = 1 << 135, - RUS = 1 << 136, - RWA = 1 << 137, - S = 1 << 138, - SD = 1 << 139, - SGP = 1 << 140, - SK = 1 << 141, - SLO = 1 << 142, - SME = 1 << 143, - SN = 1 << 144, - SO = 1 << 145, - SRB = 1 << 146, - SUD = 1 << 147, - SY = 1 << 148, - SYR = 1 << 149, - T = 1 << 150, - TCH = 1 << 151, - TG = 1 << 152, - TJ = 1 << 153, - TM = 1 << 154, - TN = 1 << 155, - TO = 1 << 156, - TR = 1 << 157, - TT = 1 << 158, - UA = 1 << 159, - UAE = 1 << 160, - UK = 1 << 161, - USA = 1 << 162, - UY = 1 << 163, - UZ = 1 << 164, - V = 1 << 165, - VN = 1 << 166, - WAG = 1 << 167, - WAL = 1 << 168, - WAN = 1 << 169, - WD = 1 << 170, - WG = 1 << 171, - WL = 1 << 172, - WS = 1 << 173, - WV = 1 << 174, - YAR = 1 << 175, - YV = 1 << 176, - Z = 1 << 177, - ZA = 1 << 178, - ZW = 1 << 179, - - EU = B | BG | DK | D | EST | FIN | F | GR | IRL | I | HR | LV | LT | L | M | NL | A | PL | P | RO | S | SK | SLO | E | CZ | H | CY + Unknown = 0L, + A = 1L << 0, + AFG = 1L << 1, + AL = 1L << 2, + AND = 1L << 3, + AM = 1L << 4, + AUS = 1L << 5, + AZ = 1L << 6, + B = 1L << 7, + BD = 1L << 8, + BDS = 1L << 9, + BF = 1L << 10, + BG = 1L << 11, + BH = 1L << 12, + BIH = 1L << 13, + BOL = 1L << 14, + BR = 1L << 15, + BRN = 1L << 16, + BRU = 1L << 17, + BS = 1L << 18, + BUR = 1L << 19, + BW = 1L << 20, + BY = 1L << 21, + CAM = 1L << 22, + CDN = 1L << 23, + CGO = 1L << 24, + CH = 1L << 25, + CI = 1L << 26, + CL = 1L << 27, + CO = 1L << 28, + CR = 1L << 29, + CU = 1L << 30, + CY = 1L << 31, + CZ = 1L << 32, + D = 1L << 33, + DK = 1L << 34, + DY = 1L << 35, + DZ = 1L << 36, + E = 1L << 37, + EAK = 1L << 38, + EAT = 1L << 39, + EAU = 1L << 40, + EAZ = 1L << 41, + EC = 1L << 42, + ER = 1L << 43, + ES = 1L << 44, + EST = 1L << 45, + ET = 1L << 46, + ETH = 1L << 47, + F = 1L << 48, + FIN = 1L << 49, + FJI = 1L << 50, + FL = 1L << 51, + FO = 1L << 52, + G = 1L << 53, + GBA = 1L << 54, + GBG = 1L << 55, + GBJ = 1L << 56, + GBM = 1L << 57, + GBZ = 1L << 58, + GCA = 1L << 59, + GE = 1L << 60, + GH = 1L << 61, + GR = 1L << 62, + GUY = 1L << 63, + H = 1L << 64, + HKJ = 1L << 65, + HN = 1L << 66, + HR = 1L << 67, + I = 1L << 68, + IL = 1L << 69, + IND = 1L << 70, + IR = 1L << 71, + IRL = 1L << 72, + IRQ = 1L << 73, + IS = 1L << 74, + J = 1L << 75, + JA = 1L << 76, + K = 1L << 77, + KG = 1L << 78, + KSA = 1L << 79, + KWT = 1L << 80, + KZ = 1L << 81, + L = 1L << 82, + LAO = 1L << 83, + LAR = 1L << 84, + LB = 1L << 85, + LS = 1L << 86, + LT = 1L << 87, + LV = 1L << 88, + M = 1L << 89, + MA = 1L << 90, + MAL = 1L << 91, + MC = 1L << 92, + MD = 1L << 93, + MEX = 1L << 94, + MNE = 1L << 95, + MGL = 1L << 96, + MOC = 1L << 97, + MS = 1L << 98, + MV = 1L << 99, + MW = 1L << 100, + N = 1L << 101, + NAM = 1L << 102, + NAU = 1L << 103, + NEP = 1L << 104, + NIC = 1L << 105, + NL = 1L << 106, + NMK = 1L << 107, + NZ = 1L << 108, + OM = 1L << 109, + P = 1L << 110, + PA = 1L << 111, + PE = 1L << 112, + PK = 1L << 113, + PL = 1L << 114, + PNG = 1L << 115, + PY = 1L << 116, + Q = 1L << 117, + RA = 1L << 118, + RC = 1L << 119, + RCA = 1L << 120, + RCB = 1L << 121, + RCH = 1L << 122, + RG = 1L << 123, + RH = 1L << 124, + RI = 1L << 125, + RIM = 1L << 126, + RKS = 1L << 127, + RL = 1L << 128, + RM = 1L << 129, + RMM = 1L << 130, + RN = 1L << 131, + RO = 1L << 132, + ROK = 1L << 133, + RP = 1L << 134, + RSM = 1L << 135, + RU = 1L << 136, + RUS = 1L << 137, + RWA = 1L << 138, + S = 1L << 139, + SD = 1L << 140, + SGP = 1L << 141, + SK = 1L << 142, + SLO = 1L << 143, + SME = 1L << 144, + SN = 1L << 145, + SO = 1L << 146, + SRB = 1L << 147, + SUD = 1L << 148, + SY = 1L << 149, + SYR = 1L << 150, + T = 1L << 151, + TCH = 1L << 152, + TG = 1L << 153, + TJ = 1L << 154, + TM = 1L << 155, + TN = 1L << 156, + TO = 1L << 157, + TR = 1L << 158, + TT = 1L << 159, + UA = 1L << 160, + UAE = 1L << 161, + UK = 1L << 162, + USA = 1L << 163, + UY = 1L << 164, + UZ = 1L << 165, + V = 1L << 166, + VN = 1L << 167, + WAG = 1L << 168, + WAL = 1L << 169, + WAN = 1L << 170, + WD = 1L << 171, + WG = 1L << 172, + WL = 1L << 173, + WS = 1L << 174, + WV = 1L << 175, + YAR = 1L << 176, + YV = 1L << 177, + Z = 1L << 178, + ZA = 1L << 179, + ZW = 1L << 180, + + EU = B | BG | DK | D | EST | FIN | F | GR | IRL | I | HR | LV | LT | L | M | NL | A | PL | P | RO | S | SK | SLO | E | CZ | H | CY | 1 << 181, } } diff --git a/src/NumberPlateGenerator.Net.Core/CustomTypes/Ranges.cs b/src/NumberPlateGenerator.Net.Core/CustomTypes/Ranges.cs new file mode 100644 index 0000000..dde9d14 --- /dev/null +++ b/src/NumberPlateGenerator.Net.Core/CustomTypes/Ranges.cs @@ -0,0 +1,37 @@ +using System; + +namespace NumberPlateGenerator.Net.Core.CustomTypes +{ + public interface IRange + { + T Start { get; } + T End { get; } + + bool Includes(T value); + bool Includes(IRange range); + } + + public class DateRange : IRange + { + public DateRange(DateTime start, DateTime end) + { + Start = start; + End = end; + } + + public static DateRange Create(DateTime start, DateTime end) => new DateRange(start, end); + + public DateTime Start { get; private set; } + public DateTime End { get; private set; } + + public bool Includes(DateTime value) + { + return (Start <= value) && (value <= End); + } + + public bool Includes(IRange range) + { + return (Start <= range.Start) && (range.End <= End); + } + } +} \ No newline at end of file diff --git a/src/NumberPlateGenerator.Net.Core/Generators/DGenerator.cs b/src/NumberPlateGenerator.Net.Core/Generators/DGenerator.cs deleted file mode 100644 index 7055cb5..0000000 --- a/src/NumberPlateGenerator.Net.Core/Generators/DGenerator.cs +++ /dev/null @@ -1,15 +0,0 @@ -using NumberPlateGenerator.Net.Core.LicensePlates; -using NumberPlateGenerator.Net.Core.Provinces; -using NumberPlateGenerator.Net.Core.Settings; - -namespace NumberPlateGenerator.Net.Core.Generators -{ - public class DGenerator : GeneratorBase - { - public override DLicensePlate Generate(DSettings settings) - { - return default; - } - - } -} \ No newline at end of file diff --git a/src/NumberPlateGenerator.Net.Core/Generators/GeneratorBase.cs b/src/NumberPlateGenerator.Net.Core/Generators/GeneratorBase.cs new file mode 100644 index 0000000..b3f5960 --- /dev/null +++ b/src/NumberPlateGenerator.Net.Core/Generators/GeneratorBase.cs @@ -0,0 +1,19 @@ +using System; +using NumberPlateGenerator.Net.Core.LicensePlates; +using NumberPlateGenerator.Net.Core.Settings; + +namespace NumberPlateGenerator.Net.Core.Generators +{ + public abstract class GeneratorBase : IGenerator + where TLicensePlate : LicensePlateBase, new() + where TProvince : Enum + where TSettings : SettingsBase, new() + where TSettingsBuilder : SettingsBuilderBase + { + public Countries Type { get; protected set; } + + public abstract TLicensePlate Generate(Func configure); + + public ILicensePlate Generate(Func, TCustomSettings> configure) where TCustomSettings : ISettings, new() => Generate(configure); + } +} diff --git a/src/NumberPlateGenerator.Net.Core/Generators/IGenerator.cs b/src/NumberPlateGenerator.Net.Core/Generators/IGenerator.cs index a50a235..ad5dbd9 100644 --- a/src/NumberPlateGenerator.Net.Core/Generators/IGenerator.cs +++ b/src/NumberPlateGenerator.Net.Core/Generators/IGenerator.cs @@ -8,16 +8,6 @@ public interface IGenerator { Countries Type { get; } - ILicensePlate Generate(ISettings settings); + ILicensePlate Generate(Func, TSettings> configure) where TSettings : ISettings, new(); } - - public abstract class GeneratorBase : IGenerator where TSettings : SettingsBase where TLicensePlate : LicensePlateBase, new() where TProvince : Enum - { - public Countries Type { get; protected set; } - - public abstract TLicensePlate Generate(TSettings settings); - - public ILicensePlate Generate(ISettings settings) => Generate(settings as SettingsBase); - } - } diff --git a/src/NumberPlateGenerator.Net.Core/Generators/NLGenerator.cs b/src/NumberPlateGenerator.Net.Core/Generators/NLGenerator.cs deleted file mode 100644 index 4a49289..0000000 --- a/src/NumberPlateGenerator.Net.Core/Generators/NLGenerator.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using NumberPlateGenerator.Net.Core.Generators; -using NumberPlateGenerator.Net.Core.LicensePlates; -using NumberPlateGenerator.Net.Core.Provinces; -using NumberPlateGenerator.Net.Core.Settings; - -namespace NumberPlateGenerator.Net.Core -{ - public class NLGenerator : GeneratorBase - { - public NLGenerator() - { - Type = Countries.NL; - } - - public override NLLicensePlate Generate(NLSettings settings) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/NumberPlateGenerator.Net.Core/LicensePlates/ILicensePlate.cs b/src/NumberPlateGenerator.Net.Core/LicensePlates/ILicensePlate.cs index cce1ca7..0318b17 100644 --- a/src/NumberPlateGenerator.Net.Core/LicensePlates/ILicensePlate.cs +++ b/src/NumberPlateGenerator.Net.Core/LicensePlates/ILicensePlate.cs @@ -8,15 +8,5 @@ public interface ILicensePlate string Text { get; } } - public abstract class LicensePlateBase : ILicensePlate where TSettings : SettingsBase where TProvince : Enum - { - protected LicensePlateBase() - { } - - public virtual string Text { get; protected set; } = string.Empty; - public virtual TSettings Settings { get; protected set; } = default; - - public static implicit operator string(LicensePlateBase license) => license.Text; - public override string ToString() => Text; - } + } diff --git a/src/NumberPlateGenerator.Net.Core/LicensePlates/LicensePlateBase.cs b/src/NumberPlateGenerator.Net.Core/LicensePlates/LicensePlateBase.cs new file mode 100644 index 0000000..caedae6 --- /dev/null +++ b/src/NumberPlateGenerator.Net.Core/LicensePlates/LicensePlateBase.cs @@ -0,0 +1,17 @@ +using System; +using NumberPlateGenerator.Net.Core.Settings; + +namespace NumberPlateGenerator.Net.Core.LicensePlates +{ + public abstract class LicensePlateBase : ILicensePlate where TSettings : SettingsBase where TProvince : Enum + { + protected LicensePlateBase() + { } + + public virtual string Text { get; protected set; } = string.Empty; + public virtual TSettings Settings { get; protected set; } = default; + + public static implicit operator string(LicensePlateBase license) => license.Text; + public override string ToString() => Text; + } +} diff --git a/src/NumberPlateGenerator.Net.Core/NumberPlate.cs b/src/NumberPlateGenerator.Net.Core/NumberPlate.cs index 5aa5348..f18ecaa 100644 --- a/src/NumberPlateGenerator.Net.Core/NumberPlate.cs +++ b/src/NumberPlateGenerator.Net.Core/NumberPlate.cs @@ -3,14 +3,11 @@ namespace NumberPlateGenerator.Net.Core { - - public class NumberPlate + public static class NumberPlate { - - private static IDictionary _supportedNumberPlateTypes = new Dictionary(){ - { Countries.NL , new NLGenerator() }, - { Countries.D , new DGenerator() }, - + private static IDictionary _supportedNumberPlateTypes = new Dictionary() + { + {Countries.Unknown, null} }; public static IGenerator GetGenerator(Countries type) => _supportedNumberPlateTypes[type]; diff --git a/src/NumberPlateGenerator.Net.Core/NumberPlateGenerator.Net.Core.csproj b/src/NumberPlateGenerator.Net.Core/NumberPlateGenerator.Net.Core.csproj index f8efd76..68e7705 100644 --- a/src/NumberPlateGenerator.Net.Core/NumberPlateGenerator.Net.Core.csproj +++ b/src/NumberPlateGenerator.Net.Core/NumberPlateGenerator.Net.Core.csproj @@ -7,9 +7,6 @@ - - - diff --git a/src/NumberPlateGenerator.Net.Core/Settings/ISettings.cs b/src/NumberPlateGenerator.Net.Core/Settings/ISettings.cs index 44060b1..6fdd41e 100644 --- a/src/NumberPlateGenerator.Net.Core/Settings/ISettings.cs +++ b/src/NumberPlateGenerator.Net.Core/Settings/ISettings.cs @@ -1,15 +1,9 @@ -using System; +using NumberPlateGenerator.Net.Core.CustomTypes; namespace NumberPlateGenerator.Net.Core.Settings { public interface ISettings - { } - - public abstract class SettingsBase : ISettings where TProvinceEnum : Enum { - protected SettingsBase() - { } - - public virtual TProvinceEnum Province { get; protected set; } + DateRange Range { get; } } } diff --git a/src/NumberPlateGenerator.Net.Core/Settings/SettingsBase.cs b/src/NumberPlateGenerator.Net.Core/Settings/SettingsBase.cs new file mode 100644 index 0000000..6ff12f6 --- /dev/null +++ b/src/NumberPlateGenerator.Net.Core/Settings/SettingsBase.cs @@ -0,0 +1,12 @@ +using System; +using NumberPlateGenerator.Net.Core.CustomTypes; + +namespace NumberPlateGenerator.Net.Core.Settings +{ + public abstract class SettingsBase : ISettings where TProvinceEnum : Enum + { + public virtual TProvinceEnum Province { get; protected set; } + + public virtual DateRange Range { get; protected set; } + } +} diff --git a/src/NumberPlateGenerator.Net.Core/Settings/SettingsBuilder.cs b/src/NumberPlateGenerator.Net.Core/Settings/SettingsBuilder.cs new file mode 100644 index 0000000..f419373 --- /dev/null +++ b/src/NumberPlateGenerator.Net.Core/Settings/SettingsBuilder.cs @@ -0,0 +1,13 @@ +using NumberPlateGenerator.Net.Core.Settings; + +namespace NumberPlateGenerator.Net.Core +{ + public abstract class SettingsBuilderBase where TSettings : ISettings, new() + { + protected TSettings Settings { get; } = new TSettings(); + + public abstract TSettings Build(); + + public static implicit operator TSettings(SettingsBuilderBase settings) => settings.Build(); + } +}