Example #1
0
        public void Test1()
        {
            SimpleRandomQuoteProvider simple = new SimpleRandomQuoteProvider();
            int           input    = 1;
            List <string> expected = new List <string>();

            expected.Add("1. We know what we are, but know not what we may be. By William Shakespeare");
            var actual = simple.getQuotes(input);

            Assert.AreEqual(expected, actual);
        }
        public void Test()
        {
            // arrange
            var  provider = new SimpleRandomQuoteProvider();
            long input    = 5;

            // assert
            Assert.AreEqual(("Quote: " + input), provider.getQuotes(input));
            Assert.AreEqual(input, provider.getID(input));
            Assert.AreEqual(("Author: " + input), provider.getAuthor(input));
        }
Example #3
0
        static void Main(string[] args)
        {
            SimpleRandomQuoteProvider sr = new SimpleRandomQuoteProvider();
            long numOfQuotes             = long.Parse(Console.ReadLine());
            IEnumerable <string> quotes  = sr.getQuotes(numOfQuotes);

            foreach (string q in quotes)
            {
                Console.WriteLine(q);
            }
        }
        public void Test()
        {
            // arrange
            var provider = new SimpleRandomQuoteProvider();

            var actual = provider.getQuotesByID(1);

            // assert
            Assert.AreEqual(actual.ID, 1);
            Assert.AreEqual(actual.Author, "Dr.Seuss");
            var actual2 = provider.getQuotesByID(0);

            // assert
            Assert.AreEqual(actual2.ID, 0);
            Assert.AreEqual(actual2.Text, "You’re off to great to places. Today is your day. Your mountain is waiting. So get on your way");


            var actual3 = provider.getQuotesByID(2);

            // assert
            Assert.AreEqual(actual3.ID, 2);

            var actual4 = provider.getQuotes(3).Count();

            Assert.IsTrue(actual4 == 3);

            var actual5 = provider.getQuotes(7).Count();

            Assert.IsTrue(actual5 == 7);

            var actual6 = provider.getAllQuotes().Count();

            Assert.IsTrue(actual6 == provider.quoteList.Length);

            var actual7     = provider.getRandomQuote();
            var countQuotes = provider.quoteList.Length;

            Assert.IsTrue(actual7.ID <= countQuotes);
        }
Example #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the number of quotes you want:");
            int  number;
            bool isNumber = int.TryParse(Console.ReadLine(), out number);


            while (!isNumber)
            {
                Console.WriteLine("Enter the number of quotes you want:");
                isNumber = int.TryParse(Console.ReadLine(), out number);
            }

            SimpleRandomQuoteProvider obj = new SimpleRandomQuoteProvider();
            var quotes = obj.getQuotes(number);

            foreach (string quote in quotes)
            {
                Console.WriteLine(quote);
            }

            Console.ReadKey();
        }
Example #6
0
 public IEnumerable <string> Get()
 {
     return(Provider.getQuotes(3));
 }
Example #7
0
        /// <summary>
        /// Main creates an instance of SimpleRandomQuoteProvider named simple that
        /// then creates 7 simple quotes in SimpleRandomQuoteProvider from quotable.core
        ///
        /// Main then creates a DefaultRandomQuoteGenerator that prints out quotes
        /// from DefaultRandomQuoteGenerator in quotable.core
        /// </summary>
        /// <param name="args"></param>
        // [miko]
        // entering the world of async
        // see the stackoverflow entry below if your visual studio
        // is complaining about not finding a main method.
        // https://stackoverflow.com/a/44254451/167160
        static async Task Main(string[] args)
        {
            SimpleRandomQuoteProvider simple = new SimpleRandomQuoteProvider();

            foreach (var s in simple.getQuotes(7))
            {
                Console.WriteLine(s);
            }

            string[] quo = new string[4] {
                "one", "two", "three", "four"
            };

            DefaultRandomQuoteGenerator defaultRand = new DefaultRandomQuoteGenerator(quo);

            // [miko]
            // even in a plain console application, we can use the dependency injection functionality
            // provided by microsoft...it is not limited to only aspnet.core applications.
            var container = new ServiceCollection();

            // setup to use a sqlite database
            container.AddDbContext <QuotableContext>(options => options.UseSqlite("Data Source=quote.db"), ServiceLifetime.Transient);
            // [miko]
            // getting a context that has already been disposed.
            // yup.
            // AddDbContext is implicitly scoped.
            // explicitly set the service lifetime
            // https://github.com/aspnet/EntityFrameworkCore/issues/4988

            var provider = container.BuildServiceProvider();

            using (var context = provider.GetService <QuotableContext>())
            {
                // [miko]
                // good for testing
                // bad for production...
                await context.Database.EnsureDeletedAsync();

                // [miko]
                // if the database doesn't exist it will be created
                // this should ideally only be run once in an application lifetime
                // this only ensure existence, this does not perform migrations.
                var dbDidntExist = await context.Database.EnsureCreatedAsync();

                if (dbDidntExist)
                {
                    await PopulateDatabase(context);
                }
            }

            using (var context = provider.GetService <QuotableContext>())
            {
                var quotes = context.Quotes
                             .Include(d => d.QuoteAuthor)
                             .ThenInclude(x => x.Author);

                foreach (var quote in quotes)
                {
                    Console.WriteLine($"quote.id = {quote.Id}");
                    Console.WriteLine($"quote.title = {quote.Body}");

                    foreach (var author in quote.Authors)
                    {
                        Console.WriteLine($"quote.author.id = {author.Id}");
                        Console.WriteLine($"quote.author.firstname = {author.FirstName}");
                        Console.WriteLine($"quote.author.firstname = {author.LastName}");
                    }

                    Console.WriteLine();
                }
            }

            Console.ReadKey();
        }
Example #8
0
 public IEnumerable <string> Get()
 {
     return(simple.getQuotes(2));
 }