public void UpdateHelpCommandTest()
        {
            //Setup Test
            var output = string.Empty;

            Console.Clear();
            try
            {
                using (var consoleInputStream = new StringReader("close"))
                {
                    Console.SetIn(consoleInputStream);
                    using (var consolestream = new StringWriter())
                    {
                        Console.SetOut(consolestream);
                        StartingUserInterface.HelpCommand();
                        output = consolestream.ToString().ToLower();

                        // Test if help command message is correct
                        Assert.True(output.Contains("create 'name' 'type' 'weighted' - creates a new gradebook where 'name' is the name of the gradebook, 'type' is what type of grading it should use, and 'weighted' is whether or not grades should be weighted (true or false)."), "`GradeBook.UserInterfaces.StartingUserInterface.HelpCommand` didn't write \"Create 'Name' 'Type' 'Weighted' - Creates a new gradebook where 'Name' is the name of the gradebook, 'Type' is what type of grading it should use, and 'Weighted' is whether or not grades should be weighted (true or false).\"");
                    }
                }
            }
            finally
            {
                StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
                Console.SetOut(standardOutput);
            }
        }
Ejemplo n.º 2
0
        public void UpdateStartingUserInterfacesCreateCommandMethodsCondition()
        {
            //Setup Test
            var output = string.Empty;

            try
            {
                using (var consoleInputStream = new StringReader("close"))
                {
                    Console.SetIn(consoleInputStream);
                    using (var consolestream = new StringWriter())
                    {
                        Console.SetOut(consolestream);
                        StartingUserInterface.CreateCommand("create test standard");
                        output = consolestream.ToString().ToLower();

                        //Test that message written to console when parts.length != 4.
                        Assert.True(output.Contains("command not valid"), "`GradeBook.UserInterfaces.StartingUserInterface` didn't write a message to the console when the create command didn't contain a name, type, and if it was weighted (true / false).");

                        //Test that message written to console is correct.
                        Assert.True(output.Contains("command not valid, create requires a name, type of gradebook, if it's weighted (true / false)."), "`GradeBook.UserInterfaces.StartingUserInterface` didn't write 'Command not valid, Create requires a name, type of gradebook, if it's weighted (true / false)..' to the console when the create command didn't contain both a name and type.");

                        //Test that `CreateCommand` escapes returns without setting the gradebook when parts.Length != 4.
                        Assert.True(!output.Contains("created gradebook"), "`GradeBook.UserInterfaces.StartingUserInterface` still created a gradebook when the create command didn't contain a name, type, if it's weighted (true / false).");
                    }
                }
            }
            finally
            {
                StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
                Console.SetOut(standardOutput);
                StreamReader standardInput = new StreamReader(Console.OpenStandardInput());
                Console.SetIn(standardInput);
            }

            output = string.Empty;

            try
            {
                using (var consoleInputStream = new StringReader("close"))
                {
                    Console.SetIn(consoleInputStream);
                    using (var consolestream = new StringWriter())
                    {
                        Console.SetOut(consolestream);
                        StartingUserInterface.CreateCommand("create test standard true");
                        output = consolestream.ToString().ToLower();

                        Assert.True(output.Contains("standard"), "`GradeBook.UserInterfaces.StartingUserInterface` didn't create a gradebook when the `CreateCommand` included a name, type, and if it was weighted (true / false).");
                    }
                }
            }
            finally
            {
                StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
                Console.SetOut(standardOutput);
                StreamReader standardInput = new StreamReader(Console.OpenStandardInput());
                Console.SetIn(standardInput);
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("#=======================#");
            Console.WriteLine("# Welcome to GradeBook! #");
            Console.WriteLine("#=======================#");
            Console.WriteLine();

            //var students = new List<Student>
            //{
            //    new Student("jamie",StudentType.Standard,EnrollmentType.Campus)
            //    {
            //        Grades = new List<double>{ 100, 102 }
            //    },
            //    new Student("john",StudentType.Standard,EnrollmentType.Campus)
            //    {
            //        Grades = new List<double>{ 75 }
            //    }
            //};

            //foreach (var student in students)
            //{
            //    Console.WriteLine(student.Name);
            //    foreach (var item in student.Grades)
            //    {
            //        Console.WriteLine(item);
            //    }
            //}

            StartingUserInterface.CommandLoop();

            Console.WriteLine("Thank you for using GradeBook!");
            Console.WriteLine("Have a nice day!");
            Console.Read();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Sheril's Gradebook");

            StartingUserInterface.CommandLoop();

            Console.WriteLine("Thank you for using GradeBook!");
            Console.WriteLine("Have a nice day!");

            Console.Read();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("#=======================#");
            Console.WriteLine("# Welcome to GradeBook! #");
            Console.WriteLine("#=======================#");
            Console.WriteLine();

            StartingUserInterface.CommandLoop();

            Console.WriteLine("Thank you for using GradeBook!");
            Environment.Exit(0);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("#=======================#");
            Console.WriteLine("# Welcome to GradeBook! #");
            Console.WriteLine("#=======================#");

            StartingUserInterface.CommandLoop();

            Console.WriteLine("Thank you for using GradeBook!");
            Console.WriteLine("Have a nice Day!");
            Console.Read();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("#=============================================#");
            Console.WriteLine("# Welcome to the ServiceNow Report Assistant! #");
            Console.WriteLine("#=============================================#");
            Console.WriteLine();

            StartingUserInterface.CommandLoop();

            Console.WriteLine("Thank you for using ServiceNow Report Assistant!");
            Console.WriteLine("Have a nice day!");
            Console.Read();
        }
        public void UpdateValidationMessageTest()
        {
            //Bypass Test if Create Command for Weighted GPA has been started
            var rankedGradeBook = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
                                   from type in assembly.GetTypes()
                                   where type.FullName == "GradeBook.GradeBooks.RankedGradeBook"
                                   select type).FirstOrDefault();

            var ctor = rankedGradeBook.GetConstructors().FirstOrDefault();

            var parameters = ctor.GetParameters();

            if (parameters.Count() == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(bool))
            {
                return;
            }

            //Setup Test
            var output = string.Empty;

            Console.Clear();
            try
            {
                using (var consoleInputStream = new StringReader("close"))
                {
                    Console.SetIn(consoleInputStream);
                    using (var consolestream = new StringWriter())
                    {
                        Console.SetOut(consolestream);
                        StartingUserInterface.CreateCommand("create test");
                        output = consolestream.ToString().ToLower();

                        //Test that message written to console is correct.
                        Assert.True(output.Contains("command not valid, create requires a name and type of gradebook."), "`GradeBook.UserInterfaces.StartingUserInterface` didn't write 'Command not valid, Create requires a name and type of gradebook.' to the console when the create command didn't contain both a name and type.");
                    }
                }
            }
            finally
            {
                StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
                Console.SetOut(standardOutput);
                StreamReader standardInput = new StreamReader(Console.OpenStandardInput());
                Console.SetIn(standardInput);
            }
        }
        public void IncreasePartsCheckToThreeTest()
        {
            //Bypass Test if Create Command for Weighted GPA has been started
            var rankedGradeBook = TestHelpers.GetUserType("GradeBook.GradeBooks.RankedGradeBook");

            Assert.True(rankedGradeBook != null, "`RankedGradeBook` wasn't found in the `GradeBooks.GradeBook` namespace.");

            var ctor = rankedGradeBook.GetConstructors().FirstOrDefault();

            var parameters = ctor.GetParameters();

            if (parameters.Count() == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(bool))
            {
                return;
            }

            //Setup Test
            var output = string.Empty;

            Console.Clear();
            try
            {
                using (var consoleInputStream = new StringReader("close"))
                {
                    Console.SetIn(consoleInputStream);
                    using (var consolestream = new StringWriter())
                    {
                        Console.SetOut(consolestream);
                        StartingUserInterface.CreateCommand("create test");
                        output = consolestream.ToString().ToLower();

                        //Test that message written to console when parts.length != 3.
                        Assert.True(output.Contains("command not valid"), "`GradeBook.UserInterfaces.StartingUserInterface` didn't write a message to the console when the create command didn't contain both a name and type.");
                    }
                }
            }
            finally
            {
                StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
                Console.SetOut(standardOutput);
                StreamReader standardInput = new StreamReader(Console.OpenStandardInput());
                Console.SetIn(standardInput);
            }
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("#=======================#");
                Console.WriteLine("# Welcome to GradeBook! #");
                Console.WriteLine("#=======================#");

                StartingUserInterface.CommandLoop();

                Console.WriteLine("Thank you for using GradeBook!");
                Console.WriteLine("Have a nice day!");
                Console.Read();
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message + " [Exception]");
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("#=======================#");
            Console.WriteLine("# Welcome to GradeBook! #");
            Console.WriteLine("#=======================#");
            Console.WriteLine();

            //RankedGradeBook book = new RankedGradeBook("Test Grade Book");
            //Student student1 = new Student("Matt", Enums.StudentType.Honors, Enums.EnrollmentType.Campus);
            //student1.AddGrade(100);
            //student1.DisplayStudent();
            //Student student2 = new Student("Blam", Enums.StudentType.DualEnrolled, Enums.EnrollmentType.International);
            //student2.AddGrade(75);
            //student2.DisplayStudent();
            //Student student3 = new Student("Alama", Enums.StudentType.Standard, Enums.EnrollmentType.National);
            //student3.AddGrade(50);
            //student3.DisplayStudent();
            //Student student4 = new Student("Ding", Enums.StudentType.DualEnrolled, Enums.EnrollmentType.State);
            //student4.AddGrade(25);
            //student4.DisplayStudent();
            //Student student5 = new Student("Dong", Enums.StudentType.Honors, Enums.EnrollmentType.Campus);
            //student5.AddGrade(0);
            //student5.DisplayStudent();

            //Console.WriteLine();

            //book.AddStudent(student1);
            //book.AddStudent(student2);
            //book.AddStudent(student3);
            //book.AddStudent(student4);
            //book.AddStudent(student5);
            //Console.WriteLine("Student List:");
            //book.ListStudents();
            //Console.WriteLine("Statistics:");
            //book.CalculateStatistics();

            StartingUserInterface.CommandLoop();

            Console.WriteLine();
            Console.WriteLine("Thank you for using GradeBook!");
            Console.WriteLine("Have a nice day!");
            //Console.Read();
        }
        public void InstantiateGradeBookTest()
        {
            //Bypass Test if Create Command for Weighted GPA has been started
            var rankedGradeBook = TestHelpers.GetUserType("GradeBook.GradeBooks.RankedGradeBook");

            Assert.True(rankedGradeBook != null, "`RankedGradeBook` wasn't found in the `GradeBooks.GradeBook` namespace.");

            var ctor = rankedGradeBook.GetConstructors().FirstOrDefault();

            var parameters = ctor.GetParameters();

            if (parameters.Count() == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(bool))
            {
                return;
            }

            //Setup Test
            var output = string.Empty;

            Console.Clear();

            try
            {
                //Test that a `StandardGradeBook` is created with the correct name when value is "standard".
                using (var consoleInputStream = new StringReader("close"))
                {
                    Console.SetIn(consoleInputStream);
                    using (var consolestream = new StringWriter())
                    {
                        Console.SetOut(consolestream);
                        StartingUserInterface.CreateCommand("create test standard");
                        output = consolestream.ToString().ToLower();

                        Assert.True(output.Contains("standard"), "`GradeBook.UserInterfaces.StartingUserInterface` didn't create a `StandardGradeBook` when 'standard' was used with the `CreateCommand`.");
                    }
                }
            }
            finally
            {
                StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
                Console.SetOut(standardOutput);
                StreamReader standardInput = new StreamReader(Console.OpenStandardInput());
                Console.SetIn(standardInput);
            }

            //Test that a `RankedGradeBook` is created with the correct name when value is "ranked".
            output = string.Empty;
            Console.Clear();

            try
            {
                using (var consoleInputStream = new StringReader("close"))
                {
                    Console.SetIn(consoleInputStream);
                    using (var consolestream = new StringWriter())
                    {
                        Console.SetOut(consolestream);
                        StartingUserInterface.CreateCommand("create test ranked");
                        output = consolestream.ToString().ToLower();

                        Assert.True(output.Contains("ranked"), "`GradeBook.UserInterfaces.StartingUserInterface` didn't create a `RankedGradeBook` when 'ranked' was used with the `CreateCommand`.");
                    }
                }
            }
            finally
            {
                StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
                Console.SetOut(standardOutput);
                StreamReader standardInput = new StreamReader(Console.OpenStandardInput());
                Console.SetIn(standardInput);
            }

            //Test that the correct message is written to console when value isn't handled.
            output = string.Empty;
            Console.Clear();

            try
            {
                using (var consolestream = new StringWriter())
                {
                    Console.SetOut(consolestream);
                    StartingUserInterface.CreateCommand("create test incorrect");
                    output = consolestream.ToString().ToLower();

                    Assert.True(output.Contains("incorrect is not a supported type of gradebook, please try again"), "`GradeBook.UserInterfaces.StartingUserInterface` write the entered type followed by ' is not a supported type of gradebook, please try again' when an unknown value was used with the `CreateCommand`.");
                }
            }
            finally
            {
                StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
                Console.SetOut(standardOutput);
                StreamReader standardInput = new StreamReader(Console.OpenStandardInput());
                Console.SetIn(standardInput);
            }
        }
Ejemplo n.º 13
0
        public void UpdateCreateCommandTest()
        {
            //Bypass Test if Create Command for Weighted GPA has been started
            var rankedGradeBook = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
                                   from type in assembly.GetTypes()
                                   where type.FullName == "GradeBook.GradeBooks.RankedGradeBook"
                                   select type).FirstOrDefault();

            Assert.True(rankedGradeBook != null, "GradeBook.GradeBooks.RankedGradeBook doesn't exist. @set-parts-check-to-3");

            var ctor = rankedGradeBook.GetConstructors().FirstOrDefault();

            Assert.True(ctor != null, "No constructor found for GradeBook.GradeBooks.RankedGradeBook. @set-parts-check-to-3");

            var parameters = ctor.GetParameters();

            if (parameters.Count() == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(bool))
            {
                return;
            }

            //Setup Test
            var output = string.Empty;

            Console.Clear();
            using (var consoleInputStream = new StringReader("close"))
            {
                Console.SetIn(consoleInputStream);
                using (var consolestream = new StringWriter())
                {
                    Console.SetOut(consolestream);
                    StartingUserInterface.CreateCommand("create test");
                    output = consolestream.ToString().ToLower();
                }
            }
            StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());

            Console.SetOut(standardOutput);
            StreamReader standardInput = new StreamReader(Console.OpenStandardInput());

            Console.SetIn(standardInput);

            //Test that message written to console when parts.length != 3.
            Assert.True(output.Contains("command not valid"), "`GradeBook.UserInterfaces.StartingUserInterface` didn't write a message to the console when the create command didn't contain both a name and type. @createcommand-type-error-message");

            //Test that message written to console is correct.
            Assert.True(output.Contains("command not valid, create requires a name and type of gradebook."), "`GradeBook.UserInterfaces.StartingUserInterface` didn't write 'Command not valid, Create requires a name and type of gradebook.' to the console when the create command didn't contain both a name and type. @createcommand-type-error-message");

            //Test that `CreateCommand` escapes returns without setting the gradebook when parts.Length != 3.
            Assert.True(!output.Contains("created gradebook"), "`GradeBook.UserInterfaces.StartingUserInterface` still created a gradebook when the create command didn't contain both a name and type. @set-parts-check-to-3");

            //Test that a `StandardGradeBook` is created with the correct name when value is "standard".
            output = string.Empty;
            Console.Clear();
            using (var consoleInputStream = new StringReader("close"))
            {
                Console.SetIn(consoleInputStream);
                using (var consolestream = new StringWriter())
                {
                    Console.SetOut(consolestream);
                    StartingUserInterface.CreateCommand("create test standard");
                    output = consolestream.ToString().ToLower();
                }
            }
            standardOutput = new StreamWriter(Console.OpenStandardOutput());
            Console.SetOut(standardOutput);
            standardInput = new StreamReader(Console.OpenStandardInput());
            Console.SetIn(standardInput);

            Assert.True(output.Contains("standard"), "`GradeBook.UserInterfaces.StartingUserInterface` didn't create a `StandardGradeBook` when 'standard' was used with the `CreateCommand`. @basegradebook-uninstantiate @createcommand-type-part @createcommand-instantiate");

            //Test that a `RankedGradeBook` is created with the correct name when value is "ranked".
            output = string.Empty;
            Console.Clear();
            using (var consoleInputStream = new StringReader("close"))
            {
                Console.SetIn(consoleInputStream);
                using (var consolestream = new StringWriter())
                {
                    Console.SetOut(consolestream);
                    StartingUserInterface.CreateCommand("create test ranked");
                    output = consolestream.ToString().ToLower();
                }
            }
            standardOutput = new StreamWriter(Console.OpenStandardOutput());
            Console.SetOut(standardOutput);
            standardInput = new StreamReader(Console.OpenStandardInput());
            Console.SetIn(standardInput);

            Assert.True(output.Contains("ranked"), "`GradeBook.UserInterfaces.StartingUserInterface` didn't create a `RankedGradeBook` when 'ranked' was used with the `CreateCommand`. @createcommand-instantiate");

            //Test that the correct message is written to console when value isn't handled.
            output = string.Empty;
            Console.Clear();
            using (var consolestream = new StringWriter())
            {
                Console.SetOut(consolestream);
                StartingUserInterface.CreateCommand("create test incorrect");
                output = consolestream.ToString().ToLower();
            }
            standardOutput = new StreamWriter(Console.OpenStandardOutput());
            Console.SetOut(standardOutput);

            Assert.True(output.Contains("incorrect is not a supported type of gradebook, please try again"), "`GradeBook.UserInterfaces.StartingUserInterface` write the entered type followed by ' is not a supported type of gradebook, please try again' when an unknown value was used with the `CreateCommand`. @createcommand-instantiate");
        }
        public void RefactorConstructorTest()
        {
            var standardGradeBook = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
                                     from type in assembly.GetTypes()
                                     where type.Name == "StandardGradeBook"
                                     select type).FirstOrDefault();

            Assert.True(standardGradeBook != null, "`GradeBook.GradeBooks.StandardGradeBook` doesn't exist. @add-bool-to-basegradebook-constructor");

            // Test if `StandardGradeBook` is `public`.
            Assert.True(standardGradeBook.IsPublic, "`GradeBook.GradeBooks.StandardGradeBook` isn't public. @add-bool-to-basegradebook-constructor");

            // Test if `StandardGradeBook` is inheritting `BaseGradeBook`.
            Assert.True(standardGradeBook.BaseType == typeof(BaseGradeBook), "`GradeBook.GradeBooks.StandardGradeBook` doesn't inherit `BaseGradeBook`. @add-bool-to-basegradebook-constructor");

            // Test if `StandardGradeBook`'s constructor has the proper signature (consider both this task and later signature)
            var ctor = standardGradeBook.GetConstructors().FirstOrDefault();

            Assert.True(ctor != null, "No constructor found for GradeBook.GradeBooks.StardardGradeBook. @add-bool-to-basegradebook-constructor");

            var    parameters = ctor.GetParameters();
            object gradeBook  = null;

            Assert.True(parameters.Count() == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(bool), "`GradeBook.GradeBooks.BaseGradeBook`'s constructor doesn't have the correct parameters. It should be a `string` and a `bool`. @add-bool-to-standardgradebook @add-bool-to-rankedgradebook");

            gradeBook = Activator.CreateInstance(standardGradeBook, "WeightedTest", true);
            Assert.True(gradeBook.GetType().GetProperty("IsWeighted").GetValue(gradeBook).ToString().ToLower() == "true", "`GradeBook.GradeBooks.BaseGradeBook`'s constructor didn't propertly set the `IsWeighted` property based on the provided bool parameter. @set-isweighted-property @instantiate-with-weight");

            //Setup Test
            var output = string.Empty;

            Console.Clear();
            using (var consoleInputStream = new StringReader("close"))
            {
                Console.SetIn(consoleInputStream);
                using (var consolestream = new StringWriter())
                {
                    Console.SetOut(consolestream);
                    StartingUserInterface.CreateCommand("create test standard");
                    output = consolestream.ToString().ToLower();
                }
            }
            StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());

            Console.SetOut(standardOutput);
            StreamReader standardInput = new StreamReader(Console.OpenStandardInput());

            Console.SetIn(standardInput);

            //Test that message written to console when parts.length != 4.
            Assert.True(output.Contains("command not valid"), "`GradeBook.UserInterfaces.StartingUserInterface` didn't write a message to the console when the create command didn't contain a name, type, and if it was weighted (true / false). @add-weighted-to-createcommand");

            //Test that message written to console is correct.
            Assert.True(output.Contains("command not valid, create requires a name, type of gradebook, if it's weighted (true / false)."), "`GradeBook.UserInterfaces.StartingUserInterface` didn't write 'Command not valid, Create requires a name, type of gradebook, if it's weighted (true / false)..' to the console when the create command didn't contain both a name and type. @add-weighted-to-createcommand @add-weighted-to-message");

            //Test that `CreateCommand` escapes returns without setting the gradebook when parts.Length != 4.
            Assert.True(!output.Contains("created gradebook"), "`GradeBook.UserInterfaces.StartingUserInterface` still created a gradebook when the create command didn't contain a name, type, if it's weighted (true / false). @add-weighted-to-createcommand");

            output = string.Empty;
            Console.Clear();
            using (var consoleInputStream = new StringReader("close"))
            {
                Console.SetIn(consoleInputStream);
                using (var consolestream = new StringWriter())
                {
                    Console.SetOut(consolestream);
                    StartingUserInterface.CreateCommand("create test standard true");
                    output = consolestream.ToString().ToLower();
                }
            }
            standardOutput = new StreamWriter(Console.OpenStandardOutput());
            Console.SetOut(standardOutput);
            standardInput = new StreamReader(Console.OpenStandardInput());
            Console.SetIn(standardInput);

            Assert.True(output.Contains("standard"), "`GradeBook.UserInterfaces.StartingUserInterface` didn't create a gradebook when the `CreateCommand` included a name, type, and if it was weighted (true / false). @add-weighted-to-createcommand");
        }