示例#1
0
        public void RemoveComponent_TheCurrentFolderDoesNotContainTheRemovableComponent_ReturnsFalse()
        {
            //Arrange
            Component removableFolder = SimpleComponentFactory.CreateComponent("Folder", "removableFolder");

            //Act
            bool resultAfterRemoving = _currentFolder.Remove(removableFolder);

            //Assert
            Assert.False(resultAfterRemoving);
        }
示例#2
0
        public void CreateComponent_CreatingFolder_ReturnsNewObjectOfTypeFolder(string componentType)
        {
            //Arrange

            //Act
            Component resultAfterCreatingFolder1 = SimpleComponentFactory.CreateComponent(componentType, componentType);
            Component resultAfterCreatingFolder2 = SimpleComponentFactory.CreateComponent(componentType, componentType);

            //Assert
            Assert.AreEqual(resultAfterCreatingFolder1.GetType(), typeof(Folder));
            Assert.AreEqual(resultAfterCreatingFolder2.GetType(), typeof(Folder));
        }
示例#3
0
        public void CreateComponent_CreatingFile_ReturnsNewObjectOfTypeFile(string componentType)
        {
            //Arrange

            //Act
            Component resultAfterCreatingFile1 = SimpleComponentFactory.CreateComponent(componentType, componentType);
            Component resultAfterCreatingFile2 = SimpleComponentFactory.CreateComponent(componentType, componentType);

            //Assert
            Assert.AreEqual(typeof(File), resultAfterCreatingFile1.GetType());
            Assert.AreEqual(typeof(File), resultAfterCreatingFile2.GetType());
        }
示例#4
0
        public void CreateComponent_CreatingSomethingThatIsNotAComponent_ReturnsNull(string componentType)
        {
            //Arrange

            //Act
            Component resultAfterCreatingFolder = SimpleComponentFactory.CreateComponent(componentType, "Folder");
            Component resultAfterCreatingFile   = SimpleComponentFactory.CreateComponent(componentType, "File");

            //Assert
            Assert.AreEqual(null, resultAfterCreatingFolder);
            Assert.AreEqual(null, resultAfterCreatingFile);
        }
示例#5
0
        public void AddNewFile_ThereIsAlreadyAComponentWithTheSameName_GiveAnErrorMessage()
        {
            //Arrange
            Component fileWithTheSameName = SimpleComponentFactory.CreateComponent("File", "SameName");

            //Act
            _consoleFileManager.AddNewFileToTheCurrentDirectory(fileWithTheSameName.Name);

            //Assert
            string expectedMessage = "A component with this name already exists";
            string actualMessage   = _lastMessageFromViewer;

            Assert.AreEqual(expectedMessage, actualMessage);
        }
示例#6
0
        public void AddNewComponent_AnyAttemptToAddAComponentInFile_ReturnsFalse()
        {
            //Arrange
            Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "newFolder");
            Component newFile   = SimpleComponentFactory.CreateComponent("File", "newFile");

            //Act
            bool resultAfterAddingFolder = _currentFile.Add(newFolder);
            bool resultAfterAddingFile   = _currentFile.Add(newFile);

            //Assert
            Assert.False(resultAfterAddingFolder);
            Assert.False(resultAfterAddingFile);
        }
示例#7
0
        public void RemoveComponent_AnyAttemptToRemoveAComponentFromFile_ReturnsFalse()
        {
            //Arrange
            Component removableFolder = SimpleComponentFactory.CreateComponent("Folder", "removableFolder");
            Component removableFile   = SimpleComponentFactory.CreateComponent("File", "removableFile");

            //Act
            bool resultAfterRemovingFolder = _currentFile.Remove(removableFolder);
            bool resultAfterRemovingFile   = _currentFile.Remove(removableFile);

            //Assert
            Assert.False(resultAfterRemovingFolder);
            Assert.False(resultAfterRemovingFile);
        }
示例#8
0
        public void RemoveComponent_TheCurrentFolderContainsTheRemovableComponent_RemovingComponentAndReturnsTrue()
        {
            //Arrange
            Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "newFolder");

            _currentFolder.Add(newFolder);

            //Act
            bool resultAfterRemoving = _currentFolder.Remove(newFolder);

            //Assert
            bool IsTheRemovedComponentAppearInTheCurrentFolder = isThereComponent("newFolder");

            Assert.False(IsTheRemovedComponentAppearInTheCurrentFolder);
            Assert.True(resultAfterRemoving);
        }
示例#9
0
        public void GetPathOfTheCurrentDirectory_AddNewFolderAfterRootAndGoDownThere_ReturnPathWithNewFolderAfterRoot()
        {
            //Arrange
            Component newFolder  = SimpleComponentFactory.CreateComponent("Folder", "newFolder");
            Component rootFolder = _currentDirectory.GetCurrentComponent();

            rootFolder.Add(newFolder);
            _currentDirectory.Down("newFolder");

            //Act
            string actualPathOfCurrentDirectory = _currentDirectory.GetPathOfTheCurrentDirectory();

            //Assert
            string expectedPathOfCurrentDirectory = "Root/newFolder/";

            Assert.AreEqual(actualPathOfCurrentDirectory, expectedPathOfCurrentDirectory);
        }
示例#10
0
        public void GetPathOfTheCurrentDirectory_WeAreNotInTheRoot_ReturnTheFullPath(string nameOfFolderOnTheLowerLevel)
        {
            //Arrange
            Component componentOnTheLowerLevel = SimpleComponentFactory.CreateComponent("Folder", nameOfFolderOnTheLowerLevel);

            _currentDirectory.GetCurrentComponent().Add(componentOnTheLowerLevel);

            _currentDirectory.Down(nameOfFolderOnTheLowerLevel);

            //Act
            string actualPathOfCurrentDirectory = _currentDirectory.GetPathOfTheCurrentDirectory();

            //Assert
            string expectedPathOfCurrentDirectory = $"Root/{nameOfFolderOnTheLowerLevel}/";

            Assert.AreEqual(actualPathOfCurrentDirectory, expectedPathOfCurrentDirectory);
        }
示例#11
0
        public void GetCurrentComponent_AddNewFolderAfterRootAndGoDownThere_ReturnNameOfNewAddedFolder()
        {
            //Arrange
            Component newFolder  = SimpleComponentFactory.CreateComponent("Folder", "newFolder");
            Component rootFolder = _currentDirectory.GetCurrentComponent();

            rootFolder.Add(newFolder);
            _currentDirectory.Down("newFolder");

            //Act
            string actualNameOfCurrentComponent = _currentDirectory.GetCurrentComponent().Name;

            //Assert
            string expectedNameOfCurrentComponent = "newFolder";

            Assert.AreEqual(actualNameOfCurrentComponent, expectedNameOfCurrentComponent);
        }
示例#12
0
        public void GetContents_FromNotEmptyFolder_ReturnsContentsOfThisFolder()
        {
            //Arrange
            Component folder = SimpleComponentFactory.CreateComponent("Folder", "folder");
            Component file   = SimpleComponentFactory.CreateComponent("File", "file");

            _currentFolder.Add(folder);
            _currentFolder.Add(file);

            //Act
            List <Component> resultAfterGettingContentsFromNotEmptyFolder = _currentFolder.GetContents();

            //Assert
            Assert.NotNull(resultAfterGettingContentsFromNotEmptyFolder);
            Assert.True(resultAfterGettingContentsFromNotEmptyFolder.Any(f => f.Name == "folder"));
            Assert.True(resultAfterGettingContentsFromNotEmptyFolder.Any(f => f.Name == "file"));
        }
示例#13
0
        public void GoDown_ComponentInWhichWeWantToGoDownIsComposite_GoDownIntoAComponentAndReturnsTrue()
        {
            //Arrange
            Component newFolder  = SimpleComponentFactory.CreateComponent("Folder", "lowerFolder");
            Component rootFolder = _currentDirectory.GetCurrentComponent();

            rootFolder.Add(newFolder);

            //Act
            bool resultOfGoDown = _currentDirectory.Down("lowerFolder");

            //Assert
            string expectedNameOfCurrentComponent = "lowerFolder";
            string actualNameOfCurrentComponent   = _currentDirectory.GetCurrentComponent().Name;

            Assert.AreEqual(expectedNameOfCurrentComponent, actualNameOfCurrentComponent);
            Assert.True(resultOfGoDown);
        }
示例#14
0
        public void GoDown_ComponentInWhichWeWantToGoDownIsNotComposite_NotGoDownAndReturnsFalse()
        {
            //Arrange
            Component newFile    = SimpleComponentFactory.CreateComponent("File", "lowerFile");
            Component rootFolder = _currentDirectory.GetCurrentComponent();

            rootFolder.Add(newFile);

            //Act
            bool resultOfGoDown = _currentDirectory.Down("lowerFile");

            //Assert
            string expectedNameOfCurrentComponent = "Root";
            string actualNameOfCurrentComponent   = _currentDirectory.GetCurrentComponent().Name;

            Assert.AreEqual(expectedNameOfCurrentComponent, actualNameOfCurrentComponent);
            Assert.False(resultOfGoDown);
        }
示例#15
0
        public void GoDownToTheLowerLevel_ComponentExistButIsNotAComposite_GiveAnErrorMessage()
        {
            //Arrange
            List <Component> fakeListWithNonCompositeComponent = new List <Component>();

            fakeListWithNonCompositeComponent.Add(SimpleComponentFactory.CreateComponent("File", "nameOfNonCompositeComponent"));

            FakeComponent.Setup(method => method.GetContents())
            .Returns(fakeListWithNonCompositeComponent);

            //Act
            _consoleFileManager.GoDownToTheLowerLevel("nameOfNonCompositeComponent");

            //Assert
            string expectedMessage = "The component nameOfNonCompositeComponent can not be descended because it is not a composite";
            string actualMessage   = _lastMessageFromViewer;

            Assert.AreEqual(expectedMessage, actualMessage);
        }
示例#16
0
        public void RiseUp_WeAreNotInTheRoot_RiseUpAndReturnsTrue()
        {
            //Arrange
            Component newFolder  = SimpleComponentFactory.CreateComponent("Folder", "lowerFolder");
            Component rootFolder = _currentDirectory.GetCurrentComponent();

            rootFolder.Add(newFolder);
            _currentDirectory.Down("lowerFolder");

            //Act
            bool resultOfRiseUp = _currentDirectory.Up();

            //Assert
            string expectedNameOfCurrentComponent = "Root";
            string actualNameOfCurrentComponent   = _currentDirectory.GetCurrentComponent().Name;

            Assert.AreEqual(expectedNameOfCurrentComponent, actualNameOfCurrentComponent);
            Assert.True(resultOfRiseUp);
        }
示例#17
0
        public void AddNewComponent_ThereIsNotComponentWithTheSameName_AddingANewComponentAndReturnsTrue()
        {
            //Arrange
            Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "newFolder");
            Component newFile   = SimpleComponentFactory.CreateComponent("File", "newFile");

            //Act
            bool resultAfterAddingFolder = _currentFolder.Add(newFolder);
            bool resultAfterAddingFile   = _currentFolder.Add(newFile);

            //Assert
            bool IsTheAddedFolderAppearInTheCurrentFolder = isThereComponent("newFolder");

            bool IsTheAddedFileAppearInTheCurrentFolder = isThereComponent("newFile");


            Assert.True(IsTheAddedFolderAppearInTheCurrentFolder);
            Assert.True(IsTheAddedFileAppearInTheCurrentFolder);

            Assert.True(resultAfterAddingFolder);
            Assert.True(resultAfterAddingFile);
        }
示例#18
0
        public void AddNewComponent_ThereIsAComponentWithTheSameName_NotAddingANewComponentAndReturnsFalse()
        {
            //Arrange

            Component newFolder           = SimpleComponentFactory.CreateComponent("Folder", "newFolder");
            Component fileWithTheSameName = SimpleComponentFactory.CreateComponent("File", "newFolder");

            _currentFolder.Add(newFolder);

            //Act
            bool resultAfterAddingFolderWithTheSameName = _currentFolder.Add(newFolder);
            bool resultAfterAddingFileWithTheSameName   = _currentFolder.Add(fileWithTheSameName);

            //Assert
            int countOfComponentsInCurrentFolderAfterAdding        = _currentFolder.GetContents().Count;
            int actualNumberOfComponentsInCurrentFolderAfterAdding = 1;


            Assert.AreEqual(countOfComponentsInCurrentFolderAfterAdding, actualNumberOfComponentsInCurrentFolderAfterAdding);

            Assert.False(resultAfterAddingFolderWithTheSameName);
            Assert.False(resultAfterAddingFileWithTheSameName);
        }
示例#19
0
 public FileTests()
 {
     _currentFile = SimpleComponentFactory.CreateComponent("File", "TestFile");
 }
示例#20
0
 public FolderTests()
 {
     _currentFolder = SimpleComponentFactory.CreateComponent("Folder", "TestFolder");
 }
示例#21
0
 public void SetUp()
 {
     _currentFolder = SimpleComponentFactory.CreateComponent("Folder", "TestFolder");
 }