public void ToString_With_Original_Format() { var sut = new Isbn("978-0-123456789"); sut.ToString("O").Should().Be("978-0-123456789"); sut.ToString("G").Should().Be("978-0-123456789"); sut.ToString("").Should().Be("978-0-123456789"); sut.ToString((string)null).Should().Be("978-0-123456789"); }
public void ToString_With_Invalid_Format_By_Case_Throws_FormatException() { var sut = new Isbn("978-0-123456789"); Action action = () => sut.ToString("o"); action.Should().Throw <FormatException>(); }
public void TestToString(string inputString, IsbnFormat format, string expectedResult) { var isbn = new Isbn(inputString); var actualResult = isbn.ToString(format); Assert.AreEqual(expectedResult, actualResult); }
/// <summary> Convert Book to string by certain format.</summary> /// <param name="format"> Format. </param> /// <param name="formatProvider"> Defines the symbols used in converting an object to its string representation. </param> /// <returns>String representation.</returns> public string ToString(string format, IFormatProvider formatProvider) { if (string.IsNullOrEmpty(format)) { format = DefaultFormatString; } if (formatProvider == null) { formatProvider = CultureInfo.CurrentCulture; } StringBuilder formattedString = new StringBuilder(); formattedString.Append("Book:"); foreach (char c in format) { switch (c) { case 'I': formattedString.Append(" Isbn - " + Isbn.ToString(formatProvider)); break; case 'A': formattedString.Append(" Author - " + Author.ToString(formatProvider)); break; case 'N': formattedString.AppendFormat(" Name - " + Name.ToString(formatProvider)); break; case 'P': formattedString.Append(" Publisher - " + Publisher.ToString(formatProvider)); break; case 'Y': formattedString.Append(" Year of publication - " + PublicationYear.ToString(formatProvider)); break; case 'C': formattedString.AppendFormat(" Count of page - " + PageCount.ToString(formatProvider)); break; case 'p': formattedString.Append(" Price - " + Price.ToString(formatProvider)); break; default: throw new FormatException(string.Format("Format string is not supported.")); } } return(formattedString.ToString()); }
public String dadosBasicos() { return("Isbn: " + Isbn.ToString() + "\nTitulo: " + Titulo + "\nAutor: " + Autor + "\nEditora: " + Editora + "\nQt exemplares: " + qtdeExemplares() + "\nQt disponíveis: " + qtdeDisponiveis() + "\nQt empréstimos: " + qtdeEmprestimos() + "\npercentual Disponível: " + percDisponibilidade() + "%"); }
public override string ToString() { StringBuilder builder = new StringBuilder(); builder.Append(Isbn.ToString()); builder.Append(", "); builder.Append(Title); builder.Append(", "); builder.Append(Author); builder.Append(", "); builder.Append(Publishing); builder.Append(", "); builder.Append(Year); builder.Append("y"); builder.Append(", "); builder.Append(Size); builder.Append("pp"); builder.Append(", "); builder.Append(Price); builder.Append('$'); return(builder.ToString()); }
private string IsbnToString(Isbn isbn) => isbn.ToString(IsbnFormat.IncludeHyphens);
public void ToString_Bare_Returns_Without_Hyphens() { var sut = new Isbn("978-0-123456789"); sut.ToString("B").Should().Be("9780123456789"); }