public void TestMoved()
        {
            var oldStub = new StubIFile()
            {
                FileLocationGet = () => "D:\\File.avi",
                ExtensionGet    = () => ".avi",
                FileNameGet     = () => "File"
            };
            var scanStub = new StubIFile()
            {
                FileLocationGet = () => "D:\\folder\\File.avi",
                ExtensionGet    = () => ".avi",
                FileNameGet     = () => "File"
            };
            var old = new List <IFile>()
            {
                oldStub
            };
            var scan = new List <IFile>()
            {
                scanStub
            };


            var comparer = new FilesComparer(old);
            IEnumerable <ScanCompareResult> result = comparer.Compare(scan);

            var comparedResult = result.Single();

            Assert.AreEqual(scanStub.FileLocationGet(), comparedResult.NewScan.FileLocation);
            Assert.AreEqual(oldStub.FileLocationGet(), comparedResult.OldScan.FileLocation);
            Assert.AreEqual(CompareResult.Moved, comparedResult.Result);
        }
        public void TestDelete()
        {
            var oldStub = new StubIFile()
            {
                FileLocationGet = () => "D:\\File.avi",
                ExtensionGet    = () => ".avi",
                FileNameGet     = () => "File"
            };
            var scanStub = new StubIFile()
            {
                FileLocationGet = () => "D:\\File2.avi",
                ExtensionGet    = () => ".avi",
                FileNameGet     = () => "File2"
            };
            var old = new List <IFile>()
            {
                oldStub,
                scanStub
            };
            var scan = new List <IFile>()
            {
                oldStub
            };


            var comparer = new FilesComparer(old);
            IEnumerable <ScanCompareResult> result = comparer.Compare(scan);

            var comparedResult = result.Single();

            Assert.AreEqual(scanStub.FileLocationGet(), comparedResult.OldScan.FileLocation, "FilesComparer.Compare() resulting location should be the same");
            Assert.AreEqual(CompareResult.Removed, comparedResult.Result);
        }
Esempio n. 3
0
        public void FileReader_FileExist_ReadTheFiles()
        {
            //Arrange
            const string filePath  = "MyFilePath";
            const int    noOfLines = 5;
            const string content   = "This is a line";

            //Generate mock implementation of the fileReader using stub
            IFile fileMock = new StubIFile
            {
                ExistsString = (fileName) =>
                {
                    return(true);
                },

                ReadLinesString = (filepath) =>
                {
                    var linesMock = Enumerable.Repeat <string>(content, 5);
                    return(linesMock);
                },
            };


            //Act
            var fileReader = new FileReader(fileMock);
            var result     = fileReader.ReadFile(filePath);

            //Assert
            Assert.AreEqual(noOfLines, result.Count(), "Failed to expected no of lines");
            Assert.IsTrue(result.All(g => g == content), "Failed to match expected content");
            Assert.IsInstanceOfType(result, typeof(IEnumerable <string>), "Failed to match expected type");
        }
        public void WhenPassingValidFileItWillCreateProjectExplorerItem()
        {
            var file = new StubIFile();
            var projectExplorerItem = SetupClass().Create(file);

            Assert.IsNotNull(projectExplorerItem);
            Assert.AreEqual(file, projectExplorerItem.Value);
        }
        public void WhenInitializedItWillStoreFileValues()
        {
            var previousFile = new StubIFile();
            var currentFile = new StubIFile();

            var fileChangedEventArgs = new FileChangedEventArgs(previousFile, currentFile);

            Assert.AreEqual(previousFile, fileChangedEventArgs.PreviousFile);
            Assert.AreEqual(currentFile, fileChangedEventArgs.CurrentFile);
        }
Esempio n. 6
0
        public void FileReader_FileNotExist_ThrowNotFoundException()
        {
            //Arrange
            const string filePath = "MyFilePath";

            //Generate mock implementation of the fileReader using stub
            IFile fileMock = new StubIFile
            {
                ExistsString = (fileName) =>
                {
                    return(false);
                }
            };


            //Act
            var fileReader = new FileReader(fileMock);

            ExceptionAssert.Throws <FileNotFoundException>(() => fileReader.ReadFile(filePath));

            //Assert
        }
Esempio n. 7
0
        public void FileReader_PathEmpty_ThrowArgumentException()
        {
            //Arrange
            const string filePath = null;

            //Generate mock implementation of the fileReader using stub
            IFile fileMock = new StubIFile
            {
                ReadLinesString = (fileName) =>
                {
                    return(new List <string>());
                }
            };


            //Act
            var fileReader = new FileReader(fileMock);

            ExceptionAssert.Throws <ArgumentNullException>(() => fileReader.ReadFile(filePath));


            //Assert
        }