public static bool TryCreate(string invoiceReferenceNumber, out InvoiceReferenceNumber result, out string failureReason) { var specification = new InvoiceReferenceNumberSpecification(); if (specification.IsSatisfiedBy(invoiceReferenceNumber)) { result = new InvoiceReferenceNumber(invoiceReferenceNumber); failureReason = string.Empty; return true; } result = null; failureReason = specification.GetReasonsForDissatisfactionSeparatedWithNewLine(); return false; }
public static InvoiceReferenceNumber Create(string invoiceReferenceNumber) { if (invoiceReferenceNumber == null) { throw new ArgumentNullException("invoiceReferenceNumber"); } var specification = new InvoiceReferenceNumberSpecification(); if (specification.IsSatisfiedBy(invoiceReferenceNumber)) { return new InvoiceReferenceNumber(invoiceReferenceNumber); } throw new ArgumentException(string.Format("Invoice reference number '{0}' does not satisfy specification.", invoiceReferenceNumber), "invoiceReferenceNumber"); }
private static void AssertDissatisfiedSpecification(int value) { var specification = new InvoiceReferenceNumberSpecification(); Assert.IsFalse(specification.IsSatisfiedBy(value)); Assert.IsFalse(string.IsNullOrWhiteSpace(specification.GetReasonsForDissatisfactionSeparatedWithNewLine())); }
private void AssertValidValue(int value) { InvoiceReferenceNumber.Create(value); var specification = new InvoiceReferenceNumberSpecification(); Assert.IsTrue(specification.IsSatisfiedBy(value)); }