public void OneRandom_TwoCallsReturnsDifferentNumbers() { BirthNumber birthNo1 = BirthNumber.OneRandom(); BirthNumber birthNo2 = BirthNumber.OneRandom(); Assert.IsNotNull(birthNo1); Assert.IsNotNull(birthNo2); Assert.AreNotEqual(birthNo1.Number, birthNo2.Number); }
public void AllPossible_ReturnsAllPossibleVariations() { List <BirthNumber> allPossible = BirthNumber.AllPossible().ToList(); Assert.IsNotNull(allPossible); Assert.AreEqual(BirthNumber.PossibleLegalVariations, allPossible.Count); Assert.AreEqual("01015450068", allPossible[0].Number); Assert.AreEqual("31123999935", allPossible[BirthNumber.PossibleLegalVariations - 1].Number); }
public void OneRandom_SpecificGender_ReturnsOnlySpecifiedGender(GenderRequest gender, int expectedOddOrEven) { for (int index = 0; index < 10; ++index) { BirthNumber birthNo = BirthNumber.OneRandom(DateBasedIdNumber.FirstPossible, DateBasedIdNumber.LastPossible, gender); Assert.IsNotNull(birthNo); int oddOrEven = birthNo.Number[8] & 1; Assert.AreEqual(expectedOddOrEven, oddOrEven); } }
public void StringRepresentationWithSlash_ReturnsBirthNumberWithSlash(string input, string expectedResult) { // Arrange var birthNumber = new BirthNumber(input); // Act var result = birthNumber.StringRepresentationWithSlash; // Assert Assert.That(result, Is.EqualTo(expectedResult)); }
public void Contains_ReturnsExpectedValue(string input, object value, bool expectedValue) { // Arrange var birthNumber = new BirthNumber(input); // Act var result = birthNumber.Contains(value); // Assert Assert.That(result, Is.EqualTo(expectedValue)); }
public void Equals_DoesNotMatchNull() { // Arrange var birthNumber = new BirthNumber("910725/6444"); // Act var result = birthNumber.Equals(null); // Arrange Assert.That(result, Is.False); }
public void WriteJson_SerializesCorrectly(string birthNumber, string expectedResult) { // Arrange var testBirthNumber = new BirthNumber(birthNumber); // Act var result = JsonConvert.SerializeObject(testBirthNumber); // Assert Assert.That(result, Is.EqualTo(expectedResult)); }
public void Equals_MatchEqualObject(string firstInput, string secondInput, bool expectedResult) { // Arrange var firstBirthNumber = new BirthNumber(firstInput); var secondBirthNumber = new BirthNumber(secondInput); // Act bool result = firstBirthNumber.Equals(secondBirthNumber); // Assert Assert.That(result, Is.EqualTo(expectedResult)); }
private void VerifyBirthNumber(string number) { try { // ReSharper disable once UnusedVariable BirthNumber bn = new BirthNumber(number); ShowResult("Fødselsnummer", string.Format("{0} er et lovlig fødselsnummer.", number)); } catch (NinException ex) { ShowResult("Fødselsnummer", ex.Message, true); } }
public void Equals_WithItself_ReturnsTrue() { // Arrange var birthNumber = new BirthNumber("9107256444"); var patient = new PatientInfo { PatientID = birthNumber }; // Act var result = patient.Equals(patient); // Assert Assert.That(result, Is.True); }
public void GetIdentifierHashCode_ReturnsHashCodeOfPatientID() { // Arrange var birthNumber = new BirthNumber("9107256444"); var patient = new PatientInfo { PatientID = birthNumber }; // Act int hashCode = patient.GetIdentifierHashCode(); // Assert Assert.That(hashCode, Is.EqualTo(birthNumber.GetHashCode())); }
private static OperationResult ValidateBirthNumber(string number) { try { BirthNumber birthNumber = new BirthNumber(number); return(new OperationResult { Code = Statuscode.Ok }); } catch (NinException ex) { return(new OperationResult { Code = ex.Code, Message = ex.Message }); } }
public void OneRandom_SpecificYear_ReturnsValidIndividualNumber(GenderRequest gender) { int firstYear = DateBasedIdNumber.FirstPossible.Year; int lastYear = DateBasedIdNumber.LastPossible.Year; for (int year = firstYear; year < lastYear; ++year) { IEnumerable <int> legalIndividualNumbers = IndividualNumberProvider.GetLegalNumbers(year, gender); DateTime dateFrom = new DateTime(year, 1, 1); DateTime dateTo = new DateTime(year, 12, 31); BirthNumber birthNumber = BirthNumber.OneRandom(dateFrom, dateTo, gender); if (null != birthNumber) { int individualNumber = int.Parse(birthNumber.Number.Substring(6, 3)); Assert.IsTrue(legalIndividualNumbers.Contains(individualNumber)); } } }
private void GenerateBirthNumber() { try { if (0 == comboBoxVaryUsing.SelectedIndex) { string pattern = textBoxPattern.Text.Trim(); BirthNumber birthNo = string.IsNullOrEmpty(pattern) ? BirthNumber.OneRandom() : BirthNumber.OneRandom(pattern); ShowGenerated(birthNo); } else { GenderRequest gender; switch (comboBoxGender.SelectedIndex) { case 1: gender = GenderRequest.Female; break; case 2: gender = GenderRequest.Male; break; default: gender = GenderRequest.Any; break; } BirthNumber birthNo = BirthNumber.OneRandom(dateTimePickerFrom.Value, dateTimePickerTo.Value, gender); ShowGenerated(birthNo); } } catch (NinException ex) { ShowResult("Feil", string.Format("Klarte ikke å generere fødselsnummer:\r\n{0}", ex.Message), true); } }
public void Equals_PatientsWithSameIDAndNameAreEqual() { // Arrange var birthNumber = new BirthNumber("9107256444"); var name = new PatientName("Doe^John"); var patient1 = new PatientInfo { PatientID = birthNumber, PatientName = name }; var patient2 = new PatientInfo { PatientID = birthNumber, PatientName = name }; // Act var result = patient1.Equals(patient2); // Assert Assert.That(result, Is.True); }
public void UseOfUnsupportedFormatThrowsException() { var birthNumber = new BirthNumber(1, 2, 3, 4, 5); Assert.Throws <ArgumentException>(() => birthNumber.ToString("unsupported", null)); }
public void OneRandom_GoodPattern_ReturnsValidNumber(string pattern) { Assert.DoesNotThrow(() => BirthNumber.OneRandom(pattern)); }
public void OneRandom_ReturnsValidNumber() { Assert.DoesNotThrow(() => BirthNumber.OneRandom()); }
public void MonthPartCanBeShiftedBy50ForWomen(int monthPart, int expectedMonth) { var dateOfBirth = new BirthNumber(0, monthPart, 1, 0, 0).DateOfBirth; Assert.Equal(expectedMonth, dateOfBirth.Value.Month); }
public void BirthNumberWithInvalidMonthWontHaveDateOfBirth(int year, int monthPart) { var dateOfBirth = new BirthNumber(year, monthPart, 1, 0, 0).DateOfBirth; Assert.Null(dateOfBirth); }
public void GetHashCode_SameCodeForEqualObjects() { // Arrange var firtBirthNumber = new BirthNumber("910725/6444"); var secondBirthNumber = new BirthNumber("9107256444"); // Act int firstHashCode = firtBirthNumber.GetHashCode(); int secondHashCode = secondBirthNumber.GetHashCode(); // Assert Assert.That(firstHashCode, Is.EqualTo(secondHashCode)); }
public void Equals_DoesMatchString([Values("910725/6444", "9107256444")] string firstNumber, [Values("910725/6444", "9107256444")] string secondNumber) { // Arrange var birthNumber = new BirthNumber(firstNumber); // Act var result = birthNumber.Equals(secondNumber); // Arrange Assert.That(result, Is.True); }
private void VerifyBirthNumber(string number) { try { // ReSharper disable once UnusedVariable BirthNumber bn = new BirthNumber(number); ShowResult("Fødselsnummer", string.Format("{0} er et gyldig fødselsnummer.", number)); } catch (NinException ex) { ShowResult("Fødselsnummer", ex.Message, true); } }
public void Create_Illegal_ReturnsNull(string number) { BirthNumber bn = BirthNumber.Create(number); Assert.IsNull(bn); }
public void BirthNumbersBefore1954_IsValid_OnlyIfItIsHasStandardFormAndValidDatePart(int yearPart, int monthPart, int dayPart, bool shouldBeValid) { var birthNumber = new BirthNumber(yearPart, monthPart, dayPart, 0, null); Assert.Equal(shouldBeValid, birthNumber.IsValid); }
public void BirthNumbersAfter1954_IsValid_OnlyIfItIsHasStandardFormAndValidDatePartAndCheckDigit(int yearPart, int monthPart, int dayPart, int sequence, int checkDigit, bool shouldBeValid) { var birthNumber = new BirthNumber(yearPart, monthPart, dayPart, sequence, checkDigit); Assert.Equal(shouldBeValid, birthNumber.IsValid); }
public void Equals_DoesMatchItself() { // Arrange var birthNumber = new BirthNumber("910725/6444"); // Act var result = birthNumber.Equals(birthNumber); // Arrange Assert.That(result, Is.True); }
public void Equals_WithDifferentType_ReturnsFalse() { // Arrange var birthNumber = new BirthNumber("9107256444"); var name = new PatientName("Doe^John"); var patient = new PatientInfo { PatientID = birthNumber, PatientName = name }; // Act var result = patient.Equals(new object()); // Assert Assert.That(result, Is.False); }
public void GetHashCode_PatientsWithSameIDAndNameAreEqual() { // Arrange var birthNumber = new BirthNumber("9107256444"); var name = new PatientName("Doe^John"); var patient1 = new PatientInfo { PatientID = birthNumber, PatientName = name }; var patient2 = new PatientInfo { PatientID = birthNumber, PatientName = name }; // Act var hash1 = patient1.GetHashCode(); var hash2 = patient2.GetHashCode(); // Assert Assert.That(hash1, Is.EqualTo(hash2)); }
public BirthNumber NinEngine() { return(BirthNumber.OneRandom(DateTime.Now, DateTime.Now)); }
public void BirthNumberWithUnspecifiedFormatUsesStandardFormat() { var birthNumber = new BirthNumber(1, 2, 3, 4, 5); Assert.Equal("010203/0045", birthNumber.ToString(null, null)); }