Пример #1
0
        public void Test1()
        {
            var    generator = new SimpleRandomQuoteProvider();
            long   input     = 0;
            string expected  = "Quote number: 0 The quote: Fear of a name only increases fear of the thing itself. Author: Hermione Granger ";
            var    actual    = generator.getQuoteByID(input);

            Assert.AreEqual(expected, actual);

            input    = 1;
            expected = "Quote number: 1 The quote: It is our choices, Harry, that show what we truly are, far more than our abilities. Author: Albus Dumbledore ";
            actual   = generator.getQuoteByID(input);
            Assert.AreEqual(expected, actual);

            input    = 2;
            expected = "Quote number: 2 The quote: I solemnly swear I am up to no good. Author: Harry Potter ";
            actual   = generator.getQuoteByID(input);
            Assert.AreEqual(expected, actual);

            input    = -1;
            expected = "There is not a quote at this index";
            actual   = generator.getQuoteByID(input);
            Assert.AreEqual(expected, actual);

            input    = 3;
            expected = "There is not a quote at this index";
            actual   = generator.getQuoteByID(input);
            Assert.AreEqual(expected, actual);

            //Assert.Pass();
        }
Пример #2
0
        public void getAllQuotesTest()
        {
            SimpleRandomQuoteProvider simp     = new SimpleRandomQuoteProvider();
            List <string>             expected = new List <string>();

            expected.Add("0");
            expected.Add("endure and survive");
            expected.Add("-Ellie, Last of Us");
            expected.Add("");
            expected.Add("1");
            expected.Add("You Live to Hunt Another Day");
            expected.Add("-HuntShowdown");
            expected.Add("");
            expected.Add("2");
            expected.Add("Rise Up Damned Soul");
            expected.Add("-HuntShowdown");
            expected.Add("");
            expected.Add("3");
            expected.Add("War, War Never Changes");
            expected.Add("-Fallout");
            expected.Add("");
            expected.Add("4");
            expected.Add("You have died of dysentery");
            expected.Add("-Oregon Trail");
            expected.Add("");

            IEnumerable <string> actual = simp.getAllQuotes();


            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        public void test_simpleRandomQuoteProvider_returnQ_Null()
        {
            RandomQuoteProvider Provider = new SimpleRandomQuoteProvider();
            var actual = Provider.returnQ(2);

            Assert.That(actual, Is.Not.Null.Or.Empty);
        }
Пример #4
0
        //the main meat of the program
        static void Main(string[] args)
        {
            //sets up the quotes and quote numbers

            var numberOfQuotes = (long)1;

            if (args.Length > 1)
            {
                goto usage;
            }
            if (args.Length == 1)
            {
                bool result = long.TryParse(args[0], out numberOfQuotes);
                if (!result)
                {
                    goto usage;
                }
            }

            var provider = new SimpleRandomQuoteProvider();

            //outputs the quotes
            foreach (var quote in provider.GetRandomQuotes(numberOfQuotes))
            {
                Console.WriteLine(quote);
            }
            goto exit;

usage:
            Console.Error.WriteLine("usage: dotnet run [numberOfQuotes]");
exit:
            return;
        }
Пример #5
0
        private static void Main(string[] args)
        {
            IEnumerable <string>        quotesList = new string[] { "quote1", "quote2", "quote3", "quote4", "quote5", "quotes6" };
            SimpleRandomQuoteProvider   object1    = new SimpleRandomQuoteProvider();
            DefaultRandomQuoteGenerator object2    = new DefaultRandomQuoteGenerator(quotesList);

            if (args.Length > 0)
            {
                Console.WriteLine("Number of quotes wanted (enter a number):" + args[0]);
                object1.printNumberofQuotes(Convert.ToInt64(args[0]));
                object2.printNumberofQuotes(Convert.ToInt64(args[0]));
            }

            else
            {
                Console.WriteLine("No command line arguments found.");
            }

            Console.ReadKey();

            // test code to see if simpleRandomQuoteProvider and DefaultRandomQuoteGenerator works
            object1.printNumberofQuotes(3);
            Console.WriteLine("---------------------");
            object2.printNumberofQuotes(4);
        }
Пример #6
0
        public void test_simpleRandomQuoteProvider_getQuoteById()
        {
            RandomQuoteProvider Provider = new SimpleRandomQuoteProvider();
            var actual = Provider.returnQuoteById(0);

            Assert.That(actual.id, Is.EqualTo("0"));
            Assert.That(actual.quote, Is.EqualTo("I'm selfish, impatient and a little insecure. I make mistakes, I am out of control and at times hard to handle. But if you can't handle me at my worst, then you sure as hell don't deserve me at my best."));
        }
Пример #7
0
        public void Test_Get_Success()
        {
            var generator  = new SimpleRandomQuoteProvider();
            var controller = new QuoteController();

            var actual   = controller.Get(3);
            var expected = "ID 3" + " If life were predictable it would cease to be life, and be without flavor. " + " by Eleanor Roosevelt";

            Assert.AreEqual(actual, expected);
        }
Пример #8
0
        /// <summary>
        /// Tests the getSingleQuote method
        /// </summary>
        public void Test2()
        {
            SimpleRandomQuoteProvider simple = new SimpleRandomQuoteProvider();
            int           input    = 2;
            List <string> expected = new List <string>();

            expected.Add("2. No act of kindness, no matter how small, is ever wasted. By Aesop");
            var actual = simple.getSingleQuote(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));
        }
Пример #10
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);
        }
Пример #11
0
        public void Test_Get_Success()
        {
            var provider   = new SimpleRandomQuoteProvider();
            var controller = new QuoteController(provider);

            var actual = controller.Get(5);

            Assert.That(actual.Value.ID, Is.EqualTo(5));
            Assert.That(actual.Value.Quote, Is.EquivalentTo(new string ("get " + actual + " quotes")));
            Assert.That(actual.Value.Author, Is.EquivalentTo(new string("get " + actual + " authors")));
        }
Пример #12
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);
            }
        }
Пример #13
0
        public void test_simpleRandomQuoteProvider_returnQ()
        {
            var quoteArr = new Quote[] {
                new Quote(),
                new Quote(),
            };
            RandomQuoteProvider Provider = new SimpleRandomQuoteProvider();

            Quote[] actual = Provider.returnQ(2).Cast <Quote>().ToArray();
            Assert.That(actual[0].quote, Is.EqualTo(quoteArr[0].quote));
            Assert.That(actual[1].quote, Is.EqualTo(quoteArr[1].quote));
        }
Пример #14
0
        public void getQuoteByIDTest()
        {
            SimpleRandomQuoteProvider simp     = new SimpleRandomQuoteProvider();
            List <string>             expected = new List <string>();
            string input = "0";

            expected.Add("0");
            expected.Add("endure and survive");
            expected.Add("-Ellie, Last of Us");

            IEnumerable <string> actual = simp.getQuoteByID(input);

            Assert.AreEqual(expected, actual);
        }
Пример #15
0
        public void Test1()
        {
            SimpleRandomQuoteProvider simple  = new SimpleRandomQuoteProvider();
            QuoteController           control = new QuoteController();

            int input  = 2;
            var actual = control.Get(input);

            List <string> expected = new List <string>();

            expected.Add("1. We know what we are, but know not what we may be. By William Shakespeare");
            expected.Add("2. No act of kindness, no matter how small, is ever wasted. By Aesop");

            Assert.AreEqual(expected, actual);
        }
Пример #16
0
        public void getRandomQuoteTest()
        {
            SimpleRandomQuoteProvider simp       = new SimpleRandomQuoteProvider(new Random(1));
            randomController          controller = new randomController();

            var result = controller.Get();

            List <string> expected = new List <string>();
            string        input    = "1";

            expected.Add(input);
            expected.Add("You Live to Hunt Another Day");
            expected.Add("-HuntShowdown");

            Assert.AreEqual(expected, result.Value);
        }
Пример #17
0
        public void getQuoteByIDTest()
        {
            SimpleRandomQuoteProvider simp       = new SimpleRandomQuoteProvider();
            quoteController           controller = new quoteController();

            var result = controller.Get(0);

            List <string> expected = new List <string>();
            string        input    = "0";

            expected.Add(input);
            expected.Add("endure and survive");
            expected.Add("-Ellie, Last of Us");

            Assert.AreEqual(expected, result.Value);
        }
Пример #18
0
        /// <summary>
        /// Testing the SimpleRandomQuoteProvider in a console app.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter a valid number/integer.");
            RandomQuoteProvider simpleRandomQuoteObject = new SimpleRandomQuoteProvider();
            var userInput = new int(); //holds user input as an int

            if (int.TryParse(Console.ReadLine(), out userInput))
            {
                simpleRandomQuoteObject.returnQ(userInput);
            }
            else
            {
                Console.Error.WriteLine("Please enter a valid number/integer");
            }
            Console.ReadKey();
        }
Пример #19
0
        static void Main(string[] args)
        {
            SimpleRandomQuoteProvider threeQuotes = new SimpleRandomQuoteProvider();

            Console.WriteLine("Enter a number of quotes to show.");
            Console.WriteLine();
            //  Quickly googled how to cast string to long, it will crash if the input isn't a number though.
            long N = long.Parse(Console.ReadLine());

            threeQuotes.showQuotes(N);


            //  Now time for DefaultRandomQuoteGenerator:
            Console.WriteLine("     Now using DefaultRandomQuoteGenerator, printing all 3 quotes:");
            Console.WriteLine();
            DefaultRandomQuoteGenerator someName = new DefaultRandomQuoteGenerator(theQuotes);

            Console.ReadLine();
        }
Пример #20
0
        static void Main(string[] args)
        {
            SimpleRandomQuoteProvider object1 = new SimpleRandomQuoteProvider();

            if (args.Length > 0)
            {
                Console.WriteLine("Arguments Passed by the Programmer:" + args[0]);
                object1.printNumberOfQuotes(Convert.ToInt64(args[0]));
            }

            else
            {
                Console.WriteLine("No command line arguments found.");
            }

            object1.printNumberOfQuotes(3);
            Console.WriteLine("---------------------");
            object1.printNumberOfQuotes(1);
        }
Пример #21
0
        // [miko]
        // how am i going to test the logic in the method since the main() method isn't simple
        static void Main(string[] args)
        {
            // setting the number of quotes to 1 by default.
            // this way if the number of argument passed in are 0, we can default to
            // simply returning a single quote.

            var numberOfQuotes = (long)1;

            if (args.Length > 1)
            {
                goto usage;
            }

            if (args.Length == 1)
            {
                bool result = long.TryParse(args[0], out numberOfQuotes);

                if (!result)
                {
                    // yes c# has goto
                    // yes i'm using goto
                    // yes i'm okay with that
                    goto usage;
                }
            }

            var provider = new SimpleRandomQuoteProvider();

            // [miko]
            // how do we test for output?
            foreach (var quote in provider.GetRandomQuotes(numberOfQuotes))
            {
                Console.WriteLine(quote);
            }
            goto exit;

usage:
            Console.Error.WriteLine("usage: dotnet run [numberOfQuotes]");

exit:
            return;
        }
Пример #22
0
        /// <summary>
        /// Main class the runs both parts of the program.
        /// The SimpleRandomQuoteProvider is run first after the long value is typed into the console.
        /// Afterwards, an IEnumerable reads the quotes.txt file, and the DefaultRandomQuoteGenerator is run.
        /// </summary>
        private void HW2()
        {
            SimpleRandomQuoteProvider s = new SimpleRandomQuoteProvider();
            long N = long.Parse(Console.ReadLine());

            foreach (string i in s.FindQuotes(N))
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("\nThese are the default quotes.");
            IEnumerable <string>        lines = System.IO.File.ReadAllLines(@"..\..\quotes.txt");
            DefaultRandomQuoteGenerator d     = new DefaultRandomQuoteGenerator(lines);

            N = long.Parse(Console.ReadLine());
            foreach (string i in d.FindQuotes(N))
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("End of Program HW1-2");
        }
Пример #23
0
        public void Test1()
        {
            var generator  = new SimpleRandomQuoteProvider();
            var controller = new QuotesController(generator);

            var actual = controller.Get(0);

            Assert.That(actual.Value.getQuoteByID, Is.EqualTo("Quote number: 0 The quote: Fear of a name only increases fear of the thing itself. Author: Hermione Granger "));
            actual = controller.Get(1);
            Assert.That(actual.Value.getQuoteByID, Is.EqualTo("Quote number: 1 The quote: It is our choices, Harry, that show what we truly are, far more than our abilities. Author: Albus Dumbledore "));
            actual = controller.Get(2);
            Assert.That(actual.Value.getQuoteByID, Is.EqualTo("Quote number: 2 The quote: I solemnly swear I am up to no good. Author: Harry Potter "));
            actual = controller.Get(-1);
            Assert.That(actual.Value.getQuoteByID, Is.EqualTo("There is not a quote at this index"));
            actual = controller.Get(3);
            Assert.That(actual.Value.getQuoteByID, Is.EqualTo("There is not a quote at this index"));

            Assert.That(actual.Value.showQuotes, Is.EquivalentTo(new string[] { "Quote number: 0 The quote: Fear of a name only increases fear of the thing itself. Author: Hermione Granger ", "Quote number: 1 The quote: It is our choices, Harry, that show what we truly are, far more than our abilities. Author: Albus Dumbledore ", "Quote number: 2 The quote: I solemnly swear I am up to no good. Author: Harry Potter " }));
            //  Why aren't or's allowed?
            //Assert.That(actual.Value.getRandomQuote, Is.EqualTo("Quote number: 0 The quote: Fear of a name only increases fear of the thing itself. Author: Hermione Granger " || "Quote number: 1 The quote: It is our choices, Harry, that show what we truly are, far more than our abilities. Author: Albus Dumbledore " || "Quote number: 2 The quote: I solemnly swear I am up to no good. Author: Harry Potter "));
            //Assert.That(actual.Value.getRandomQuote, Is.EquivalentTo(new string[] { "Quote number: 0 The quote: Fear of a name only increases fear of the thing itself. Author: Hermione Granger " || "Quote number: 2 The quote: I solemnly swear I am up to no good. Author: Harry Potter " }));
        }
        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);
        }
Пример #25
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();
        }
Пример #26
0
        public void Test_Get_Success()
        {
            var provider   = new SimpleRandomQuoteProvider();
            var controller = new QuoteController(provider);

            var actual = controller.Get(1);

            Assert.IsTrue(actual.Value.ID == 1);


            var actual2 = controller.Get(2);

            Assert.IsTrue(actual2.Value.Text == "It is better to know how to learn than to know");

            var actual3 = controller.Get();

            Assert.IsTrue(actual3.Value.Count() == provider.quoteList.Length);


            var controller2 = new RandomController(provider);
            var actual4     = controller2.Get();

            Assert.IsTrue(actual4.Value.ID <= provider.quoteList.Length);
        }
Пример #27
0
 public ValuesController(SimpleRandomQuoteProvider provider)
 {
     Provider = provider;
 }
Пример #28
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();
        }