Beispiel #1
0
        public static void LoadCommand(string command)
        {
            var parts = command.Split(' ');

            if (parts.Length != 2)
            {
                Console.WriteLine("Command not valid, Load requires a name.");
                return;
            }
            var name      = parts[1];
            var gradeBook = BaseGradeBook.Load(name);

            if (gradeBook == null)
            {
                return;
            }

            GradeBookUserInterface.CommandLoop(gradeBook);
        }
        public static void LoadCommand(string command)
        {
            var parts = command.Split(' ');

            if (parts.Length != 2)
            {
                Console.WriteLine("command not valid, create requires a name, type of gradebook, if it's weighted (true / false).");
                return;
            }
            var name      = parts[1];
            var gradeBook = BaseGradeBook.Load(name);

            if (gradeBook == null)
            {
                return;
            }

            GradeBookUserInterface.CommandLoop(gradeBook);
        }
Beispiel #3
0
        public void AddMultipleGradeBookTypeSupportToBaseGradeBookTest()
        {
            var gradebookEnum = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
                                 from type in assembly.GetTypes()
                                 where type.FullName == "GradeBook.Enums.GradeBookType"
                                 select type).FirstOrDefault();

            Assert.True(gradebookEnum != null, "GradeBook.Enums.GradeBookType doesn't exist. @create-gradebook-variable");

            // Test if when the `GradeBookType` is `Standard` the matching `StandardGradeBook` object is returned.
            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. @create-gradebook-variable");

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

            Assert.True(ctor != null, "`GradeBook.GradeBooks.StandardGradeBook` doesn't appear to have a constructor. @create-gradebook-variable");

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

            if (parameters.Count() == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(bool))
            {
                gradeBook = Activator.CreateInstance(standardGradeBook, "LoadTest", true);
            }
            else if (parameters.Count() == 1 && parameters[0].ParameterType == typeof(string))
            {
                gradeBook = Activator.CreateInstance(standardGradeBook, "LoadTest");
            }
            Assert.True(gradeBook != null, "The constructor for `GradeBook.GradeBooks.StandardGradeBook` doesn't have the expected parameters. @create-gradebook-variable");

            Assert.True(gradeBook.GetType().GetProperty("Type") != null, "`GradeBook.GradeBooks.BaseGradeBook` doesn't appear to have a `Type` property. @create-gradebook-variable");
            gradeBook.GetType().GetProperty("Type").SetValue(gradeBook, Enum.Parse(gradebookEnum, "Standard", true));

            try
            {
                using (var file = new FileStream("LoadTest.gdbk", FileMode.Create, FileAccess.Write))
                {
                    using (var writer = new StreamWriter(file))
                    {
                        var json = JsonConvert.SerializeObject(gradeBook);
                        writer.Write(json);
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.True(ex != null, "Test for GradeBook.GradeBooks.BaseGradeBook.Load was unable to run. This is likely due to issues being able to read/write gradebook files to the local file system. @create-gradebook-variable");
            }

            var actual = BaseGradeBook.Load("LoadTest");

            File.Delete("LoadTest.gdbk");
            Assert.True((string)actual.GetType().GetProperty("Name").GetValue(gradeBook) == "LoadTest", "`GradeBook.GradeBooks.BaseGradeBook.Load` did not properly load when the gradebook is a `StandardGradeBook`. @get-gradebooktype");
            Assert.True(actual.GetType() == standardGradeBook, "`GradeBook.GradeBooks.BaseGradeBook.Load` did not properly create a `StandardGradeBook` when the loaded gradebook is a `StandardGradeBook`. @instantiate-standardgradebook");
            Assert.True(actual.GetType().GetProperty("Type").GetValue(actual).ToString() == Enum.Parse(gradebookEnum, "Standard", true).ToString(), "`GradeBook.GradeBooks.BaseGradeBook.Load` did not properly set the `Type` property of gradebook to `Standard` when the gradebook is a `StandardGradeBook`. @instantiate-standardgradebook");

            // Test if when the `GradeBookType` isn't set the matching `StandardGradeBook` object is returned.
            var esnuGradeBook = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
                                 from type in assembly.GetTypes()
                                 where type.Name == "ESNUGradeBook"
                                 select type).FirstOrDefault();

            if (esnuGradeBook == null)
            {
                parameters = ctor.GetParameters();
                gradeBook  = null;
                if (parameters.Count() == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(bool))
                {
                    gradeBook = Activator.CreateInstance(standardGradeBook, "LoadTest", true);
                }
                else if (parameters.Count() == 1 && parameters[0].ParameterType == typeof(string))
                {
                    gradeBook = Activator.CreateInstance(standardGradeBook, "LoadTest");
                }
                Assert.True(gradeBook != null, "The constructor for `GradeBook.GradeBooks.StandardGradeBook` doesn't have the expected parameters. @handle-invalid-types");

                Assert.True(gradeBook.GetType().GetProperty("Type") != null, "`GradeBook.GradeBooks.BaseGradeBook` doesn't appear to have a `Type` property. @handle-invalid-types");
                gradeBook.GetType().GetProperty("Type").SetValue(gradeBook, Enum.Parse(gradebookEnum, "ESNU", true));


                try
                {
                    using (var file = new FileStream("LoadTest.gdbk", FileMode.Create, FileAccess.Write))
                    {
                        using (var writer = new StreamWriter(file))
                        {
                            var json = JsonConvert.SerializeObject(gradeBook);
                            writer.Write(json);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Assert.True(ex != null, "Test for GradeBook.GradeBooks.BaseGradeBook.Load was unable to run. This is likely due to issues being able to read/write gradebook files to the local file system. @handle-invalid-types");
                }

                try
                {
                    BaseGradeBook.Load("LoadTest");
                    Assert.True(1 == 1, "`GradeBook.GradeBooks.BaseGradeBook.Load` didn't throw an `InvalidOperationException` when the `GradeBookType` was not yet implimented. @handle-invalid-types");
                }
                catch (Exception ex)
                {
                    Assert.True(ex.GetType() == typeof(InvalidOperationException), "`GradeBook.GradeBooks.BaseGradeBook.Load` threw an exception, however; it was not an `InvalidOperationException` @handle-invalid-types.");
                    Assert.True(ex.Message == "The gradebook you've attempted to load is not in a supported type of gradebook.", "`GradeBook.GradeBooks.BaseGradeBook`'s `Load` method threw the proper exception type, but didn't have the message \"The gradebook you've attempted to load is not in a supported type of gradebook.\" @handle-invalid-types");
                }
                File.Delete("LoadTest.gdbk");
            }

            // Test if when the `GradeBookType` is `Ranked` the matching `RankedGradeBook` object is returned.
            var rankedGradeBook = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
                                   from type in assembly.GetTypes()
                                   where type.Name == "RankedGradeBook"
                                   select type).FirstOrDefault();

            Assert.True(rankedGradeBook != null, "`GradeBook.GradeBooks.RankedGradeBook` doesn't exist. @instantiate-rankedgradebook");

            ctor = rankedGradeBook.GetConstructors().FirstOrDefault();
            Assert.True(ctor != null, "`GradeBook.GradeBooks.RankedGradeBook` doesn't appear to have a constructor. @instantiate-rankedgradebook");

            parameters = ctor.GetParameters();
            gradeBook  = null;
            if (parameters.Count() == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(bool))
            {
                gradeBook = Activator.CreateInstance(rankedGradeBook, "LoadTest", true);
            }
            else if (parameters.Count() == 1 && parameters[0].ParameterType == typeof(string))
            {
                gradeBook = Activator.CreateInstance(rankedGradeBook, "LoadTest");
            }
            Assert.True(gradeBook != null, "The constructor for `GradeBook.GradeBooks.RankedGradeBook` doesn't have the expected parameters. @instantiate-rankedgradebook");

            gradeBook.GetType().GetProperty("Type").SetValue(gradeBook, Enum.Parse(gradebookEnum, "Ranked", true));

            try
            {
                using (var file = new FileStream("LoadTest.gdbk", FileMode.Create, FileAccess.Write))
                {
                    using (var writer = new StreamWriter(file))
                    {
                        var json = JsonConvert.SerializeObject(gradeBook);
                        writer.Write(json);
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.True(ex != null, "Test for GradeBook.GradeBooks.BaseGradeBook.Load was unable to run. This is likely due to issues being able to read/write gradebook files to the local file system. @instantiate-rankedgradebook");
            }

            actual = BaseGradeBook.Load("LoadTest");
            File.Delete("LoadTest.gdbk");
            Assert.True((string)actual.GetType().GetProperty("Name").GetValue(gradeBook) == "LoadTest", "`GradeBook.GradeBooks.BaseGradeBook.Load` did not properly load when the gradebook is a `RankedGradeBook`. @instantiate-rankedgradebook @update-loads-return");
            Assert.True(actual.GetType() == rankedGradeBook, "`GradeBook.GradeBooks.BaseGradeBook.Load` did not properly create a `RankedGradeBook` when the loaded gradebook is a `RankedGradeBook`. @instantiate-rankedgradebook @update-loads-return");
            Assert.True(actual.GetType().GetProperty("Type").GetValue(actual).ToString() == Enum.Parse(gradebookEnum, "Ranked", true).ToString(), "`GradeBook.GradeBooks.BaseGradeBook.Load` did not properly set the `Type` property of gradebook to `Ranked` when the gradebook is a `RankedGradeBook`. @instantiate-rankedgradebook");
        }