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); }
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); }
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); }
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); }
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); }
public void OneRandom_TwoCallsReturnsDifferentNumbers() { OrganizationNumber orgNo1 = OrganizationNumber.OneRandom(); OrganizationNumber orgNo2 = OrganizationNumber.OneRandom(); Assert.IsNotNull(orgNo1); Assert.IsNotNull(orgNo2); Assert.AreNotEqual(orgNo1.Number, orgNo2.Number); }
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); } }
public void OneRandom_GoodPattern_ReturnsValidNumber(string pattern) { Assert.DoesNotThrow(() => OrganizationNumber.OneRandom(pattern)); }
public void OneRandom_ReturnsValidNumber() { Assert.DoesNotThrow(() => OrganizationNumber.OneRandom()); }