示例#1
0
        public void CopyFilesWhenIndicated(bool shouldInitialize)
        {
            var initializationDeterminer = new MockLevelInitializationDeterminer(shouldInitialize);

            var copyDir = new MockCopyDir();

            var levelId           = "level";
            var levelToInitialize = new Level(id: levelId, folderFilepath: ".");
            var levelsProvider    = new FakeLevelsProvider(new[] { levelToInitialize });
            var mockFileSystem    = new MockFileSystem();

            mockFileSystem.AddDirectory(levelToInitialize.GetMasterFolder()); //will throw error if no master folder

            var masterFolderLevelInitializer = new MasterFolderLevelInitializer(initializationDeterminer,
                                                                                copyDir,
                                                                                levelsProvider,
                                                                                mockFileSystem.Path);

            var someUser = "******";

            masterFolderLevelInitializer.InitializeIfNecessary(levelId, someUser);

            Assert.Equal(shouldInitialize, copyDir.DidCopy);
            Assert.Equal(shouldInitialize, initializationDeterminer.IsMarkedAsInitialized);
        }
        public void ReturnProjectFolderPathForSpecifiedLevelAndUser(FakeLevelsProvider provider, string levelId, string user, string expectedPath)
        {
            var command = new OpenLevelCommand(new MockLevelInitializer(), provider);

            var result = command.Execute(levelId, user);

            Assert.Equal(expectedPath, result);
        }
示例#3
0
        public void ReturnInstructionsPathForSpecifiedLevel(FakeLevelsProvider provider, string levelId, string expectedPath)
        {
            var command = new GetInstructionsPathCommand(provider);

            var result = command.Execute(levelId);

            Assert.Equal(expectedPath, result);
        }
        public void RemoveContentsOfProjectFolder(MockFileSystem fs, FakeLevelsProvider provider, Level level, string user)
        {
            var initializer = new MasterFolderLevelInitializer(new MockLevelInitializationDeterminer(false), new MockCopyDir(), provider, fs.Path);

            initializer.Clean(level.Id, user);

            Assert.Empty(fs.Directory.EnumerateFileSystemEntries("C:\\" + level.GetProjectFolder(user)));
        }
        public void ReturnAllAvailableLevels()
        {
            var availableLevels = new Level[] { new Level(), new Level(), new Level() };
            var levelsProvider  = new FakeLevelsProvider(availableLevels);
            var command         = new GetLevelsCommand(levelsProvider);

            var result = (Level[])command.Execute();

            Assert.Equal(availableLevels, result);
        }
        public void SupplyCorrectParametersToInitializer(FakeLevelsProvider provider, string levelId, string user)
        {
            var initializer = new MockLevelInitializer();
            var command     = new OpenLevelCommand(initializer, provider);

            command.Execute(levelId, user);

            Assert.Equal(levelId, initializer.InitializedLevelId);
            Assert.Equal(user, initializer.InitializedUser);
        }
示例#7
0
        public void RunCorrectVerifierForUser(FakeLevelsProvider provider, string levelId, string user)
        {
            var mockVerifier = new MockVerifier();
            var command      = new VerifyCommand(provider, mockVerifier);

            command.Execute(levelId, user);

            Assert.Equal(levelId, mockVerifier.Level.Id);
            Assert.Equal(user, mockVerifier.User);
        }
        public void UnmarkUserFolder(FakeLevelsProvider provider, string levelId, string user, string expectedUserFolder)
        {
            var determiner  = new MockLevelInitializationDeterminer(false, true);
            var initializer = new MasterFolderLevelInitializer(determiner, new MockCopyDir(), provider, new MockPath(new MockFileSystem()));

            //This Assert.Throws code is necessary, as we are not testing for any actual IO operations
            Assert.Throws <DirectoryNotFoundException>(() => initializer.Clean(levelId, user));

            Assert.False(determiner.IsMarkedAsInitialized);
            Assert.Equal(expectedUserFolder, determiner.SuppliedUserFolderPath);
        }
        public static FakeLevelsProvider GenerateRandomLevelsWithProvider(this Random random, int minLevels, int maxLevels)
        {
            var amountOfLevels = random.Next(minLevels, maxLevels);
            var levels         = new List <Level>();

            for (int i = 0; i < amountOfLevels; i++)
            {
                levels.Add(random.GenerateRandomLevel());
            }
            var levelsProvider = new FakeLevelsProvider(levels);

            return(levelsProvider);
        }
示例#10
0
        public void ThrowExceptionIfMasterFolderDoesNotExist(FakeLevelsProvider fakeLevelsProvider, string levelId, string user, string expectedSourceDir, string expectedDestDir)
        {
            var determinerIndicatingInitialization = new MockLevelInitializationDeterminer(true);
            var copyDir = new MockCopyDir();
            var path    = new MockPath(new MockFileSystem());
            var masterFolderLevelInitializer = new MasterFolderLevelInitializer(determinerIndicatingInitialization,
                                                                                copyDir,
                                                                                fakeLevelsProvider,
                                                                                path);

            var exception = Assert.Throws <DirectoryNotFoundException>(() => masterFolderLevelInitializer.InitializeIfNecessary(levelId, user));

            Assert.Equal($"Master folder for level {levelId} not found.", exception.Message);
        }
示例#11
0
        public void CopyCorrectFilesToCorrectLocation(FakeLevelsProvider fakeLevelsProvider, string levelId, string user, string expectedSourceDir, string expectedDestDir)
        {
            var determinerIndicatingInitialization = new MockLevelInitializationDeterminer(true);
            var copyDir        = new MockCopyDir();
            var mockFileSystem = new MockFileSystem();

            foreach (var level in fakeLevelsProvider.GetLevels())
            {
                mockFileSystem.AddDirectory(level.GetMasterFolder()); //put master folder in every level folder to prevent error
            }
            var masterFolderLevelInitializer = new MasterFolderLevelInitializer(determinerIndicatingInitialization,
                                                                                copyDir,
                                                                                fakeLevelsProvider,
                                                                                mockFileSystem.Path);

            masterFolderLevelInitializer.InitializeIfNecessary(levelId, user);

            Assert.Equal(expectedSourceDir, copyDir.SuppliedSourceDir);
            Assert.Equal(expectedDestDir, copyDir.SuppliedDestDir);
        }