コード例 #1
0
        public void PrintGreeting_CustomWithEncryption_BadLength()
        {
            // Create an abnormally long string.
            string longString = null;

            for (int i = 0; i < 1024; i++)
            {
                longString += "x";
            }

            // Create our API object.
            HelloWorldAPI api = new HelloWorldAPI();

            // Run our test.
            api.PrintGreeting(longString, true);

            // Check our exceptions and assert.
            if (api.Errors.Count > 0)
            {
                Assert.IsInstanceOfType(api.Errors[0], typeof(CryptographicException));
            }
            else
            {
                throw new ApplicationException("No errors were found.");
            }
        }
コード例 #2
0
        public void StoreData_Container_PathTooLong()
        {
            // Create an abnormally long path.
            string path       = null;
            string longString = null;

            for (int i = 0; i < 1024; i++)
            {
                longString += "x";
            }
            path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\" + longString;

            // Create a new API object.
            HelloWorldAPI api = new HelloWorldAPI(path);

            // Try storing our data.
            api.StoreData("Test data...", HelloWorldAPI.StorageType.Container);

            // Check our exceptions and assert.
            if (api.Errors.Count > 0)
            {
                Assert.IsInstanceOfType(api.Errors[0], typeof(PathTooLongException));
            }
            else
            {
                throw new ApplicationException("No errors were found.");
            }
        }
コード例 #3
0
        public void StoreData_Database()
        {
            // Since this method hasn't been fully implemented, it will pass.
            HelloWorldAPI api = new HelloWorldAPI();

            api.StoreData("More test data...", HelloWorldAPI.StorageType.Database);
        }
コード例 #4
0
        public void PrintGreeting_CustomWithEncryption()
        {
            /* Encrypted output is indeterministic so we'll just run the method, and since we
             * have included error handling in our code our test will work regardless; otherwise
             * if there was any kind of error the test would fail. */
            HelloWorldAPI api = new HelloWorldAPI();

            api.PrintGreeting("Hoy es miercoles.", true);
        }
コード例 #5
0
        public void Test1()
        {
            IOptions <AppSettingsModel> settings;

            settings = null;
            var controller = new HelloWorldAPI(settings);

            var response = controller.Get();

            Assert.AreEqual("Hello World", response);
        }
コード例 #6
0
        public void StoreData_Container()
        {
            // Create a new API object.
            HelloWorldAPI api = new HelloWorldAPI();

            // Store our data into a container.
            api.StoreData("More test data...", HelloWorldAPI.StorageType.Container);

            // Check if the file exists.
            Assert.IsTrue(File.Exists(api.ContainerPath));
        }
コード例 #7
0
        public void StoreData_File()
        {
            // Create a new API object.
            HelloWorldAPI api = new HelloWorldAPI();

            // Store our data into a file.
            api.StoreData("Some test data...", HelloWorldAPI.StorageType.File);

            // Check if the file exists.
            Assert.IsTrue(File.Exists(api.FilePath));
        }
コード例 #8
0
        public void PrintGreeting_Default()
        {
            // Listen for the contents of the console.
            using (var co = new ConsoleOutput())
            {
                // Construct our API object and print a greeting.
                HelloWorldAPI api = new HelloWorldAPI();
                api.PrintGreeting();

                // Split up our output since we have a bunch of bells and whistles.
                string[] split = co.GetOuput().Split(':');

                // Check if we have our standard "Hello World" output.
                Assert.AreEqual("Hello World!", split[split.Length - 1].Trim(null));
            }
        }
コード例 #9
0
        public void StoreData_Container_DirectoryNotFound()
        {
            // Create a new API object.
            HelloWorldAPI api = new HelloWorldAPI("This is not a real directory");

            // Try storing our data into a non-existant file.
            api.StoreData("Invalid path data...", HelloWorldAPI.StorageType.Container);

            // Check our exceptions and assert.
            if (api.Errors.Count > 0)
            {
                Assert.IsInstanceOfType(api.Errors[0], typeof(DirectoryNotFoundException));
            }
            else
            {
                throw new ApplicationException("No errors were found.");
            }
        }
コード例 #10
0
        public void PrintGreeting_CustomNoEncryption()
        {
            // Create a new greeting string.
            string greeting = "This is a custom greeting!";

            // Listen for the contents of the console.
            using (var co = new ConsoleOutput())
            {
                // Construct our API object and print a greeting.
                HelloWorldAPI api = new HelloWorldAPI();
                api.PrintGreeting(greeting);

                // Split up our output because of formatting.
                string[] split = co.GetOuput().Split(':');

                // Check our assertion.
                Assert.AreEqual(greeting, split[split.Length - 1].Trim(null));
            }
        }
コード例 #11
0
        public void StoreData_Container_UnauthorizedAccess()
        {
            /* Note - This unauthorized access test method will fail if run under
             * an adminstrator or higher elevated user. So, run it unprivileged. */

            // Create a new API object.
            HelloWorldAPI api = new HelloWorldAPI(@"C:\Windows\System32");

            // Try storing our data into a non-existant file.
            api.StoreData("Data being written...", HelloWorldAPI.StorageType.Container);

            // Check our exceptions and assert.
            if (api.Errors.Count > 0)
            {
                Assert.IsInstanceOfType(api.Errors[0], typeof(UnauthorizedAccessException));
            }
            else
            {
                throw new ApplicationException("No errors were found.");
            }
        }