public void ISBNMapper_ConvertsISBN13ToISBN10Correctly(string isbn, string expectedResult) { ISBN10 newIsbn = null; Assert.DoesNotThrow(() => newIsbn = ISBNMapper.From(new ISBN13(isbn))); Assert.AreEqual(newIsbn.Value, expectedResult); }
public static ISBN Create(string isbn) { var clearIsbn = isbn?.Replace("-", "") ?? ""; return(clearIsbn?.Length switch { 10 => ISBNMapper.From(new ISBN10(isbn)), 13 => new ISBN13(isbn), _ => throw new FormatException($"The passed ISBN has incorrect format. Expected 10 or 13 digits, but got only {clearIsbn.Length}"), });
public void ISBNMapper_ThrowsFormatExceptionIfISBN13StartsWith979(string isbn) { ISBN13 newIsbn = new ISBN13(isbn); Assert.Throws <FormatException>(() => ISBNMapper.From(newIsbn)); }