Example #1
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);
            }
        }
        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);
            }
        }
        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);
            }
        }
Example #5
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");
        }