Ejemplo n.º 1
0
        public void Test_Constructor(KeyValuePair <string, string> data)
        {
            if (data.Value == null || string.IsNullOrEmpty(data.Key) || string.IsNullOrWhiteSpace(data.Key))
            {
                Assert.That(() => new File(data.Key, data.Value), Throws.Exception);
            }
            else
            {
                var file = new File(data.Key, data.Value);

                string expect_extention = new System.IO.FileInfo(data.Key).Extension;
                if (!string.IsNullOrEmpty(expect_extention))
                {
                    expect_extention = expect_extention.Split('.')[1];
                }
                string expect_fileName = data.Key;
                string expect_content  = data.Value;
                double expect_size     = data.Value.Length / 2;

                string actual_extention = HelpfulMethods.GetPrivateField("extension", file).ToString();
                string actual_fileName  = HelpfulMethods.GetPrivateField("filename", file).ToString();
                string actual_content   = HelpfulMethods.GetPrivateField("content", file).ToString();
                double actual_size      = Convert.ToDouble(HelpfulMethods.GetPrivateField("size", file));

                Assert.AreEqual(expect_extention, actual_extention);
                Assert.AreEqual(expect_fileName, actual_fileName);
                Assert.AreEqual(expect_content, actual_content);
                Assert.AreEqual(expect_size, actual_size);
            }
        }
        public void Test_WriteFileGraterThanMaxPossibleSize(int maxPossibleFileContentSize)
        {
            File        file    = new File(TestData.FileName, HelpfulMethods.RandomString(maxPossibleFileContentSize));
            FileStorage storage = new FileStorage(Convert.ToInt32(file.getSize() - 1));

            Assert.False(storage.write(file));
        }
        public void Test_UserConstructor(int size)
        {
            FileStorage userConstructor      = new FileStorage(size);
            int         actual_maxSize       = Convert.ToInt32(HelpfulMethods.GetPrivateField("maxSize", userConstructor));
            int         actual_availableSize = Convert.ToInt32(HelpfulMethods.GetPrivateField("availableSize", userConstructor));

            Assert.AreEqual(size, actual_maxSize);
            Assert.AreEqual(size, actual_availableSize);
        }
Ejemplo n.º 4
0
        public static List <File> GetFileCollection(int filesQuality, int maxPossibleStringLength)
        {
            List <File> files = new List <File>();

            while (filesQuality-- > 0)
            {
                files.Add(new File($"{HelpfulMethods.RandomString(5)}.txt", HelpfulMethods.RandomString(random.Next(maxPossibleStringLength))));
            }

            return(files);
        }
        public void Test_CompareConstructors()
        {
            FileStorage defaultConstructor     = new FileStorage();
            int         expected_maxSize       = Convert.ToInt32(HelpfulMethods.GetPrivateField("maxSize", defaultConstructor));
            int         expected_availableSize = Convert.ToInt32(HelpfulMethods.GetPrivateField("availableSize", defaultConstructor));

            FileStorage userConstructor      = new FileStorage(expected_availableSize);
            int         actual_maxSize       = Convert.ToInt32(HelpfulMethods.GetPrivateField("maxSize", userConstructor));
            int         actual_availableSize = Convert.ToInt32(HelpfulMethods.GetPrivateField("availableSize", userConstructor));

            Assert.AreEqual(expected_maxSize, actual_maxSize);
            Assert.AreEqual(expected_availableSize, actual_availableSize);
        }