Пример #1
0
        public void TestGetFileSize_ShouldReturnFileAttribute()
        {
            var classUnderTest = new FileAttributeRequestHandler(new FileAttributeRequestParser(), new FileDetails());

            var fileAttribute = classUnderTest.GetFileAttribute(_attributeRequest, _filePath);

            Assert.That(!string.IsNullOrEmpty(fileAttribute), "File attribute is expected to be non-null value.");
            if (_attribute == FileAttribute.Size)
            {
                int fileSize;
                if (!int.TryParse(fileAttribute, out fileSize))
                {
                    Assert.Fail("File size must be an integer.");
                }

                Assert.That(fileSize > 0, "File size much be greater than zero.");
            }
            else if (_attribute == FileAttribute.Version)
            {
                var versionStringArray = fileAttribute.Split('.');
                Assert.That(versionStringArray != null && versionStringArray.Length >= 3, "Invalid file version.");

                foreach (var versionComponent in versionStringArray)
                {
                    int versionNumber;
                    Assert.That(int.TryParse(versionComponent, out versionNumber), "File version parts must be numeric.");
                }
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            IFileAttributeRequestHandler fileAttributeRequestHandler =
                new FileAttributeRequestHandler(new FileAttributeRequestParser(), new FileDetails());

            var attribute = fileAttributeRequestHandler.GetFileAttribute(args[0], args[1]);

            Console.WriteLine("File Attribute : {0}", attribute);
            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }
        public void TestGetFileSize_NullFilePath_ShouldThrowArgumentNullException()
        {
            var classUnderTest = new FileAttributeRequestHandler(new FileAttributeRequestParser(), new FileDetails());

            Assert.Throws <ArgumentNullException>(() => classUnderTest.GetFileAttribute("-s", null));
        }
        public void TestGetFileSize_ShouldThrowException()
        {
            var classUnderTest = new FileAttributeRequestHandler(new FileAttributeRequestParser(), new FileDetails());

            Assert.Throws <Exception>(() => classUnderTest.GetFileAttribute(_attributeRequest, _filePath));
        }