public void TestGetInstalledPackagesFormatted()
        {
            PackageInstallService service = new PackageInstallService();

            PrivateType privateType = new PrivateType(service.GetType());

            string[] input = new string[]
            {
                "Texture: Cabbage",
                "Bread: Amusement",
                "Cabbage: Giraffe",
                "Amusement: Giraffe",
                "Giraffe: Flower",
                "Flower: "
            };

            object[] args = new object[1] {
                input
            };

            List <PackageInfo> packageInfoList = (List <PackageInfo>)privateType.InvokeStatic("GetPackageInfoList", args);

            object[] new_args = new object[1] {
                packageInfoList
            };

            string installedPackagesFormatted = (string)privateType.InvokeStatic("GetInstalledPackagesFormatted", new_args);

            // We should get a result
            Assert.AreNotEqual(string.Empty, installedPackagesFormatted);

            // We should get the following formatted order (will just be the order of the given list because we aren't testing the topological sort here
            Assert.AreEqual("Texture, Bread, Cabbage, Amusement, Giraffe, Flower", installedPackagesFormatted);
        }
        public void TestGetPackageInfoList()
        {
            PackageInstallService service = new PackageInstallService();

            PrivateType privateType = new PrivateType(service.GetType());

            string[] input = new string[]
            {
                "KittenService: CamelCaser",
                "CamelCaser: "
            };

            object[] args = new object[1] {
                input
            };

            List <PackageInfo> packageInfoList = (List <PackageInfo>)privateType.InvokeStatic("GetPackageInfoList", args);

            // We should get a result
            Assert.AreNotEqual(null, packageInfoList);
            Assert.AreNotEqual(0, packageInfoList.Count);

            // Compare the first package
            Assert.AreEqual("KittenService", packageInfoList[0].Name);
            Assert.AreEqual("CamelCaser", packageInfoList[0].Dependency);

            // Compare the second package
            Assert.AreEqual("CamelCaser", packageInfoList[1].Name);
            Assert.AreEqual(string.Empty, packageInfoList[1].Dependency);
        }
        public void TestGetCleanedPackageListFromInput_Easy()
        {
            string input = "[ \"KittenService: CamelCaser\", \"CamelCaser: \" ]";

            string[] packages = PackageInstallService.GetCleanedPackageListFromInput(input);

            // We should get a result
            Assert.AreNotEqual(null, packages);
            Assert.AreNotEqual(0, packages.Length);

            // We should get the following list
            Assert.AreEqual("KittenService: CamelCaser", packages[0]);
            Assert.AreEqual("CamelCaser: ", packages[1]);
        }
        public void TestInstallPackagesInvalid_Easy()
        {
            string[] input = new string[]
            {
                "KittenService: ",
                "Leetmeme: Cyberportal",
            };

            PackageInstallResponse response = PackageInstallService.InstallPackages(input);

            // The response should never be null
            Assert.AreNotEqual(null, response);

            // This should report that it contains a package with a dependency on a missing package and no packages should be installed
            Assert.AreEqual(PackageInstallStatuses.CONTAINS_CYCLE, response.Status);
            Assert.AreEqual(string.Empty, response.InstalledPackages);
        }
        public void TestInstallPackagesValid_Easy()
        {
            string[] input = new string[]
            {
                "KittenService: CamelCaser",
                "CamelCaser: "
            };

            PackageInstallResponse response = PackageInstallService.InstallPackages(input);

            // The response should never be null
            Assert.AreNotEqual(null, response);

            // The response should be successful with this result
            Assert.AreEqual(PackageInstallStatuses.SUCCESS, response.Status);
            Assert.AreEqual("CamelCaser, KittenService", response.InstalledPackages);
        }
        public void TestInstallPackagesInvalid_Medium()
        {
            string[] input = new string[]
            {
                "KittenService: ",
                "Leetmeme: Cyberportal",
                "Cyberportal: Ice",
                "CamelCaser: KittenService",
                "Fraudstream: ",
                "Ice: Leetmeme"
            };

            PackageInstallResponse response = PackageInstallService.InstallPackages(input);

            // The response should never be null
            Assert.AreNotEqual(null, response);

            // This should report that it contains a cycle and no packages should be installed
            Assert.AreEqual(PackageInstallStatuses.CONTAINS_CYCLE, response.Status);
            Assert.AreEqual(string.Empty, response.InstalledPackages);
        }
        public void TestInstallPackagesValid_Hard()
        {
            string[] input = new string[]
            {
                "Texture: Cabbage",
                "Bread: Amusement",
                "Cabbage: Giraffe",
                "Amusement: Giraffe",
                "Giraffe: Flower",
                "Flower: "
            };

            PackageInstallResponse response = PackageInstallService.InstallPackages(input);

            // The response should never be null
            Assert.AreNotEqual(null, response);

            // The response should be successful with this result
            Assert.AreEqual(PackageInstallStatuses.SUCCESS, response.Status);
            Assert.AreEqual("Flower, Giraffe, Cabbage, Amusement, Texture, Bread", response.InstalledPackages);
        }
        public void TestInstallPackagesValid_Medium()
        {
            string[] input = new string[]
            {
                "KittenService: ",
                "Leetmeme: Cyberportal",
                "Cyberportal: Ice",
                "CamelCaser: KittenService",
                "Fraudstream: Leetmeme",
                "Ice: "
            };

            PackageInstallResponse response = PackageInstallService.InstallPackages(input);

            // The response should never be null
            Assert.AreNotEqual(null, response);

            // The response should be successful with this result
            Assert.AreEqual(PackageInstallStatuses.SUCCESS, response.Status);
            Assert.AreEqual("KittenService, Ice, CamelCaser, Cyberportal, Leetmeme, Fraudstream", response.InstalledPackages);
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            // Allow package input as arguments or wait for it in the program
            string[] packages = args;
            if (args.Length == 0)
            {
                try
                {
                    /*
                     * Accepts input in any of the following formats:
                     *      [ "PackageName: Dependency", "PackageName: " ]
                     *      "PackageName: Dependency", "PackageName: "
                     *      PackageName: Dependency, PackageName:
                     */
                    string input = Console.ReadLine();

                    packages = PackageInstallService.GetCleanedPackageListFromInput(input);
                }
                catch
                {
                    Console.WriteLine("Invalid input given, exiting program");

                    return;
                }
            }

            // Exit the program if no valid input was given.
            if (packages.Length == 0)
            {
                Console.WriteLine("There is nothing to install, exiting program");

                return;
            }

            // Install the given packages based on their dependencies
            PackageInstallResponse response = PackageInstallService.InstallPackages(packages);

            // Build a message based on the result of the install
            string message = string.Empty;

            switch (response.Status)
            {
            case PackageInstallStatuses.SUCCESS:
            {
                message = response.InstalledPackages;
                break;
            }

            case PackageInstallStatuses.CONTAINS_CYCLE:
            {
                message = "No Packages were installed, invalid dependency specification that contains cycles or a dependency on a missing package.";
                break;
            }

            case PackageInstallStatuses.ERROR:
            case PackageInstallStatuses.DEFAULT_NOT_SET:
            default:
            {
                message = "No Packages were installed, unknown error occurred.";
                break;
            }
            }

            // Print the result to the console
            Console.WriteLine(message);
        }