示例#1
0
        public OperationResult Generate(string pattern)
        {
            OperationResult result;

            try
            {
                switch (_generationKind)
                {
                case GenerationKind.OrganizationNumber:
                    OrganizationNumber on = OrganizationNumber.OneRandom(pattern);
                    result = WriteNumber(on);
                    break;

                case GenerationKind.BirthNumber:
                    BirthNumber bn = BirthNumber.OneRandom(pattern);
                    result = WriteNumber(bn);
                    break;

                case GenerationKind.DNumber:
                    DNumber dn = DNumber.OneRandom(pattern);
                    result = WriteNumber(dn);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (NinException ex)
            {
                result = new OperationResult {
                    Code = ex.Code, Message = ex.Message
                };
            }
            return(result);
        }
示例#2
0
        public OperationResult Generate(int count)
        {
            OperationResult result;

            try
            {
                switch (_generationKind)
                {
                case GenerationKind.OrganizationNumber:
                    if (count > 1)
                    {
                        IEnumerable <OrganizationNumber> ons = OrganizationNumber.ManyRandom(count);
                        result = WriteList(ons.Select(x => x.Number));
                    }
                    else
                    {
                        OrganizationNumber on = OrganizationNumber.OneRandom();
                        result = WriteNumber(on);
                    }
                    break;

                case GenerationKind.BirthNumber:
                    if (count > 1)
                    {
                        IEnumerable <BirthNumber> bns = BirthNumber.ManyRandom(count);
                        result = WriteList(bns.Select(x => x.Number));
                    }
                    else
                    {
                        BirthNumber bn = BirthNumber.OneRandom();
                        result = WriteNumber(bn);
                    }
                    break;

                case GenerationKind.DNumber:
                    if (count > 1)
                    {
                        IEnumerable <DNumber> dns = DNumber.ManyRandom(count);
                        result = WriteList(dns.Select(x => x.Number));
                    }
                    else
                    {
                        DNumber dn = DNumber.OneRandom();
                        result = WriteNumber(dn);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (NinException ex)
            {
                result = new OperationResult {
                    Code = ex.Code, Message = ex.Message
                };
            }
            return(result);
        }
示例#3
0
        public void OneRandom_NoWildcardInPattern_ThrowsException()
        {
            var          ex  = Assert.Throws(typeof(NinException), () => OrganizationNumber.OneRandom("987654321"));
            NinException nex = ex as NinException;

            Assert.IsNotNull(nex);
            Assert.AreEqual(Statuscode.BadPattern, nex.Code);
        }
示例#4
0
        public void OneRandom_InvalidCharacterInPattern_ThrowsException(string pattern)
        {
            var          ex  = Assert.Throws(typeof(NinException), () => OrganizationNumber.OneRandom(pattern));
            NinException nex = ex as NinException;

            Assert.IsNotNull(nex);
            Assert.AreEqual(Statuscode.BadPattern, nex.Code);
        }
示例#5
0
        public void OneRandom_EmptyPattern_ThrowsException()
        {
            var          ex  = Assert.Throws(typeof(NinException), () => OrganizationNumber.OneRandom(string.Empty));
            NinException nex = ex as NinException;

            Assert.IsNotNull(nex);
            Assert.AreEqual(Statuscode.PatternIsNullOrEmpty, nex.Code);
        }
示例#6
0
        public void OneRandom_TwoCallsReturnsDifferentNumbers()
        {
            OrganizationNumber orgNo1 = OrganizationNumber.OneRandom();
            OrganizationNumber orgNo2 = OrganizationNumber.OneRandom();

            Assert.IsNotNull(orgNo1);
            Assert.IsNotNull(orgNo2);
            Assert.AreNotEqual(orgNo1.Number, orgNo2.Number);
        }
示例#7
0
        private void GenerateOrganizationNumber()
        {
            string pattern = textBoxPattern.Text.Trim();

            try
            {
                OrganizationNumber orgNo = string.IsNullOrEmpty(pattern)
                    ? OrganizationNumber.OneRandom()
                    : OrganizationNumber.OneRandom(pattern);
                ShowGenerated(orgNo);
            }
            catch (NinException ex)
            {
                ShowResult("Feil", string.Format("Klarte ikke å generere organisasjonsnummer:\r\n{0}", ex.Message), true);
            }
        }
示例#8
0
 public void OneRandom_GoodPattern_ReturnsValidNumber(string pattern)
 {
     Assert.DoesNotThrow(() => OrganizationNumber.OneRandom(pattern));
 }
示例#9
0
 public void OneRandom_ReturnsValidNumber()
 {
     Assert.DoesNotThrow(() => OrganizationNumber.OneRandom());
 }