Exemplo n.º 1
0
        /// <summary>
        /// Returns representation of book, including <see cref="formatProvider"/>
        /// <list type="bullet">
        /// <item>
        /// <term>"V"</term>
        /// <description>Returns representation of book, including Author,Name,Year,PublishingOffice</description>
        /// </item>
        /// <item>
        /// <term>"B"</term>
        /// <description>Returns representation of book, including Author,Name,Year</description>
        /// </item>
        /// <item>
        /// <term>"S"</term>
        /// <description>Returns representation of book, including Author,Name</description>
        /// </item>
        /// <item>
        /// <term>"L"</term>
        /// <description>Returns representation of book, including Name,Year,PublishingOffice</description>
        /// </item>
        /// <item>
        /// <term>"A"</term>
        /// <description>Returns representation of book, including only Author</description>
        /// </item>
        /// <item>
        /// <term>"N"</term>
        /// <description>Returns representation of book, including only Name</description>
        /// </item>
        /// <item>
        /// <term>"Y"</term>
        /// <description>Returns representation of book, including only Year</description>
        /// </item>
        /// <item>
        /// <term>"H"</term>
        /// <description>Returns representation of book, including only PublishingOffice</description>
        /// </item>
        /// <item>
        /// <term>"I"</term>
        /// <description>Returns representation of book, including only ISBN</description>
        /// </item>
        /// <item>
        /// <term>"P"</term>
        /// <description>Returns representation of book, including only Pages</description>
        /// </item>
        /// </list>
        /// </summary>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (string.IsNullOrEmpty(format))
            {
                format = "V";
            }

            if (formatProvider == null)
            {
                formatProvider = CultureInfo.CurrentCulture;
            }

            switch (format.ToUpperInvariant())
            {
            case "A":
                return(Author?.ToString(formatProvider) ?? string.Empty);

            case "N":
                return(Name?.ToString(formatProvider) ?? string.Empty);

            case "Y":
                return(Year.ToString(formatProvider));

            case "H":
                return(PublishingOffice != null ? "\"" + PublishingOffice?.ToString(formatProvider) + "\"" : string.Empty);

            case "I":
                return("ISBN 13: " + ISBN.ToString(formatProvider));

            case "P":
                return("P. " + NumberOfPages.ToString(formatProvider));

            case "V":
                return(Author?.ToString(formatProvider) + ", " + Name?.ToString(formatProvider) + ", "
                       + Year.ToString(formatProvider) + ", " + PublishingOffice?.ToString(formatProvider));

            case "B":
                return(Author?.ToString(formatProvider) + ", " + Name?.ToString(formatProvider) + ", "
                       + Year.ToString(formatProvider));

            case "S":
                return(Author?.ToString(formatProvider) + ", " + Name?.ToString(formatProvider));

            case "L":
                return(Name?.ToString(formatProvider) + ", " + Year.ToString(formatProvider) + ", "
                       + PublishingOffice?.ToString(formatProvider));

            case string str when !str.Except(SimpleFormats).Any():
                return(string.Join(", ", format.Select(c => this.ToString(c.ToString(), formatProvider))));

            default:
                throw new FormatException($"The {format} format string is not supported.");
            }
        }
        // This function is here to show more information about each Item when a client want more.
        public virtual string DescriptionString()
        {
            StringBuilder _sb = new StringBuilder();

            _sb.AppendLine(string.Format("{0}, ", Title));
            _sb.AppendLine(string.Format("Price: \t{0:#0.##$} ", Price));
            if (Discount > 0m)
            {
                _sb.AppendLine(string.Format("Discount: \t{0:#0.##%} ", Discount / 100));
            }

            _sb.AppendLine(string.Format("Subject: \t{0} ", Subject));
            _sb.AppendLine(string.Format("EditionDate: \t{0:d} ", EditionDate));

            StringBuilder isbn = new StringBuilder(ISBN.ToString());

            isbn.Remove(0, isbn.Length - 10);

            _sb.AppendLine(string.Format("ISBN: \t{0} ", isbn.ToString()));
            _sb.AppendLine(string.Format("Stock: \t{0} ", _stock));

            return(_sb.ToString());
        }
Exemplo n.º 3
0
 public override int GetHashCode()
 {
     return((Author + Title).GetHashCode() ^ (Gerne + ISBN.ToString()).GetHashCode());
 }
Exemplo n.º 4
0
 public override string ToString()
 {
     return(ISBN.ToString());
 }
Exemplo n.º 5
0
        /// <summary>
        /// Returns a string representation of the book, using the specified format.
        /// </summary>
        /// <param name="format">Avaliable formats:
        ///                     "G" - general
        ///                     "S" - short
        ///                     You can enumerate the components of the book you want to get, separeted by ','.
        ///                     In the result the components values will also be separeted by ','.
        ///                     Components shortcuts:
        ///                     "ISBN" - Books ISBN number
        ///                     "AUT" - Books authors
        ///                     "TT" - Books Title
        ///                     "PB" - Books publisher
        ///                     "PBY" - Books publish year
        ///                     "PG" - Books number of pages
        ///                     "PR" - Books Price
        ///                     Example:
        ///                     The general format looks like this "ISBN,AUT,TT,PB,PBY,PG,PR".
        ///                     The short format "AUT,TT".
        ///                     </param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            string defaultFormat = "G";

            if (format == null)
            {
                format = defaultFormat;
            }

            if (formatProvider == null)
            {
                formatProvider = CultureInfo.CurrentCulture;
            }

            format = format.ToUpper();

            string generalFormat =
                "ISBN,AUT,TT,PB,PBY,PG,PR";
            string shortFormat =
                "AUT,TT";

            if (format == "G")
            {
                format = generalFormat;
            }

            if (format == "S")
            {
                format = shortFormat;
            }


            string[] fmtParts = format.Split(',');

            StringBuilder result = new StringBuilder();

            for (int i = 0; i < fmtParts.Length; i++)
            {
                if (i != 0)
                {
                    result.Append(", ");
                }

                switch (fmtParts[i])
                {
                case "ISBN":
                    result.Append(ISBN.ToString());
                    break;

                case "AUT":
                    result.Append(Author.ToString(formatProvider));
                    break;

                case "TT":
                    result.Append(Title.ToString(formatProvider));
                    break;

                case "PB":
                    result.Append(Publisher.ToString(formatProvider));
                    break;

                case "PBY":
                    result.Append(PublishYear.ToString(formatProvider));
                    break;

                case "PG":
                    result.Append($"P.{NumberOfPages.ToString(formatProvider)}");
                    break;

                case "PR":
                    result.Append(Price.ToString(formatProvider));
                    break;

                default:
                    throw new FormatException($"{fmtParts[i]} format is not supported");
                }
            }

            return(result.ToString());
        }
Exemplo n.º 6
0
        public void FromISBN10CreatesRightISBN13()
        {
            ISBN isbn = "2123456802";

            Assert.AreEqual("97282123456803", isbn.ToString());
        }
 public override string ToString() => string.Format(nameof(ISBN) + ": " + ISBN.ToString() + ", " + nameof(Title) + ": " + Title + ", " + nameof(Author) + ": " + Author + ", " + nameof(NumberPages) + ": " + NumberPages + ", " + nameof(PublishYear) + ": " + PublishYear + ", " + nameof(Edition) + ": " + Edition);
Exemplo n.º 8
0
 public void NaConstructorAanroepMetGetalVanDertienCijfersMetCorrecteControleDieNulIsGeeftDeToStringDezelfdeStringAlsDeToStringVanDatGetal()
 {
     iSBN = new ISBN(correctNummerMetNul);
     iSBN.ToString().ShouldBeEquivalentTo(correctNummerMetNul.ToString(), "this book is this book");
 }
        public void convert_ISBN_string()
        {
            var isbn = new ISBN(978, 957, 331, 724, 1);

            isbn.ToString().Should().Be("978-957-331-724-1");
        }