Exemple #1
0
                public void Should_Throw_If_Context_Is_Null()
                {
                    // Given
                    var fixture = new FileCopyFixture();

                    // When
                    var result = Record.Exception(() =>
                                                  FileAliases.MoveFiles(null, fixture.SourceFilePaths, "./target"));

                    // Then
                    AssertEx.IsArgumentNullException(result, "context");
                }
Exemple #2
0
            public void Should_Move_File()
            {
                // Given
                var fixture = new FileCopyFixture();

                // When
                FileAliases.MoveFileToDirectory(fixture.Context, "./file1.txt", "./target");

                // Then
                fixture.TargetFiles[0].Received(1).Move(
                    Arg.Is <FilePath>(p => p.FullPath == "/Working/target/file1.txt"));
            }
Exemple #3
0
            public void Should_Throw_If_File_Path_Is_Null()
            {
                // Given
                var context = Substitute.For <ICakeContext>();

                // When
                var result = Record.Exception(() =>
                                              FileAliases.CopyFileToDirectory(context, null, "./target"));

                // Then
                AssertEx.IsArgumentNullException(result, "filePath");
            }
Exemple #4
0
                public void Should_Throw_If_Glob_Expression_Is_Null()
                {
                    // Given
                    var context = Substitute.For <ICakeContext>();

                    // When
                    var result = Record.Exception(() =>
                                                  FileAliases.DeleteFiles(context, (string)null));

                    // Then
                    AssertEx.IsArgumentNullException(result, "pattern");
                }
Exemple #5
0
                public void Should_Delete_Files()
                {
                    // Given
                    var fixture = new FileDeleteFixture();

                    // When
                    FileAliases.DeleteFiles(fixture.Context, "*");

                    // Then
                    fixture.Files[0].Received(1).Delete();
                    fixture.Files[1].Received(1).Delete();
                }
Exemple #6
0
                public void Should_Throw_If_Context_Is_Null()
                {
                    // Given
                    var filePaths = new FilePath[] { };

                    // When
                    var result = Record.Exception(() =>
                                                  FileAliases.DeleteFiles(null, filePaths));

                    // Then
                    AssertEx.IsArgumentNullException(result, "context");
                }
Exemple #7
0
            public void Should_Make_Relative_File_Path_Absolute()
            {
                // Given
                var fixture = new FileDeleteFixture();

                // When
                FileAliases.DeleteFile(fixture.Context, "file1.txt");

                // Then
                fixture.FileSystem.Received(1).GetFile(Arg.Is <FilePath>(
                                                           p => p.FullPath == "/Working/file1.txt"));
            }
Exemple #8
0
                public void Should_Keep_Folder_Structure()
                {
                    // Given
                    var fixture = new FileCopyFixture();

                    // When
                    FileAliases.CopyFiles(fixture.Context, "*", "./target", true);

                    // Then
                    fixture.TargetFiles[0].Received(1).Copy(Arg.Any <FilePath>(), true);
                    fixture.TargetFiles[1].Received(1).Copy(Arg.Any <FilePath>(), true);
                }
Exemple #9
0
                public void Should_Throw_If_File_Paths_Are_Null()
                {
                    // Given
                    var context = Substitute.For <ICakeContext>();

                    // When
                    var result = Record.Exception(() =>
                                                  FileAliases.MoveFiles(context, (IEnumerable <FilePath>)null, "./target"));

                    // Then
                    AssertEx.IsArgumentNullException(result, "filePaths");
                }
Exemple #10
0
                public void Should_Throw_If_Glob_Expression_Is_Null()
                {
                    // Given
                    var fixture = new FileCopyFixture();

                    // When
                    var result = Record.Exception(() =>
                                                  FileAliases.MoveFiles(fixture.Context, (string)null, "./target"));

                    // Then
                    AssertEx.IsArgumentNullException(result, "pattern");
                }
Exemple #11
0
                public void Should_Throw_If_Target_Directory_Path_Is_Null()
                {
                    // Given
                    var fixture = new FileCopyFixture();

                    // When
                    var result = Record.Exception(() =>
                                                  FileAliases.MoveFiles(fixture.Context, "*", null));

                    // Then
                    AssertEx.IsArgumentNullException(result, "targetDirectoryPath");
                }
Exemple #12
0
            public void Should_Copy_File()
            {
                // Given
                var fixture = new FileCopyFixture();

                // When
                FileAliases.CopyFile(fixture.Context, "./file1.txt", "./target/file1.txt");

                // Then
                fixture.TargetFiles[0].Received(1).Copy(
                    Arg.Is <FilePath>(p => p.FullPath == "/Working/target/file1.txt"), true);
            }
Exemple #13
0
                public void Should_Copy_Files()
                {
                    // Given
                    var fixture = new FileCopyFixture();

                    // When
                    FileAliases.CopyFiles(fixture.Context, fixture.SourceFilePaths, "./target");

                    // Then
                    fixture.TargetFiles[0].Received(1).Copy(Arg.Any <FilePath>(), true);
                    fixture.TargetFiles[1].Received(1).Copy(Arg.Any <FilePath>(), true);
                }
Exemple #14
0
            public void Should_Throw_If_Target_File_Path_Is_Null()
            {
                // Given
                var context = Substitute.For <ICakeContext>();

                // When
                var result = Record.Exception(() =>
                                              FileAliases.CopyFile(context, "./file.txt", null));

                // Then
                Assert.IsArgumentNullException(result, "targetFilePath");
            }
Exemple #15
0
            public void Should_Throw_If_Context_Is_Null()
            {
                // Given, When
                var source = new FilePath("./source.txt");
                var target = new FilePath("./target.txt");

                var result = Record.Exception(() =>
                                              FileAliases.MoveFile(null, source, target));

                // Then
                AssertEx.IsArgumentNullException(result, "context");
            }
Exemple #16
0
                public void Should_Move_Files()
                {
                    // Given
                    var fixture = new FileCopyFixture();

                    // When
                    FileAliases.MoveFiles(fixture.Context, "*", "./target");

                    // Then
                    fixture.TargetFiles[0].Received(1).Move(Arg.Any <FilePath>());
                    fixture.TargetFiles[1].Received(1).Move(Arg.Any <FilePath>());
                }
Exemple #17
0
                public void Should_Keep_Folder_Structure()
                {
                    // Given
                    var fixture   = new FileCopyFixture();
                    var filePaths = fixture.SourceFilePaths.Select(x => x.FullPath);

                    // When
                    FileAliases.CopyFiles(fixture.Context, filePaths, "./target");

                    // Then
                    fixture.TargetFiles[0].Received(1).Copy(Arg.Any <FilePath>(), true);
                    fixture.TargetFiles[1].Received(1).Copy(Arg.Any <FilePath>(), true);
                }
            public void Should_Throw_If_File_Do_Not_Exist()
            {
                // Given
                var fixture = new FileDeleteFixture();

                // When
                var result = Record.Exception(() =>
                                              FileAliases.DeleteFile(fixture.Context, "/file.txt"));

                // Then
                Assert.IsType <FileNotFoundException>(result);
                Assert.Equal("The file '/file.txt' do not exist.", result.Message);
            }
Exemple #19
0
            public void Should_Throw_If_Directory_Does_Not_Exist()
            {
                // Given
                var context     = Substitute.For <ICakeContext>();
                var environment = FakeEnvironment.CreateUnixEnvironment();
                var fileSystem  = new FakeFileSystem(environment);

                context.FileSystem.Returns(fileSystem);
                context.Environment.Returns(environment);

                // When / Then
                Assert.Throws <FileNotFoundException>(() => FileAliases.FileSize(context, "non-existent-file.txt"));
            }
            public void Should_Throw_If_Target_File_Path_Is_Null()
            {
                // Given
                var context = Substitute.For <ICakeContext>();
                var source  = new FilePath("./source.txt");

                // When
                var result = Record.Exception(() =>
                                              FileAliases.MoveFileToDirectory(context, source, null));

                // Then
                Assert.IsArgumentNullException(result, "targetDirectoryPath");
            }
            public void Should_Throw_If_Source_File_Path_Is_Null()
            {
                // Given
                var context = Substitute.For <ICakeContext>();
                var target  = new FilePath("./target.txt");

                // When
                var result = Record.Exception(() =>
                                              FileAliases.MoveFile(context, null, target));

                // Then
                Assert.IsArgumentNullException(result, "filePath");
            }
                public void Should_Throw_If_Target_Directory_Path_Is_Null()
                {
                    // Given
                    var fixture   = new FileCopyFixture();
                    var filePaths = fixture.SourceFilePaths.Select(x => x.FullPath);

                    // When
                    var result = Record.Exception(() =>
                                                  FileAliases.CopyFiles(fixture.Context, filePaths, null));

                    // Then
                    Assert.IsArgumentNullException(result, "targetDirectoryPath");
                }
            public void Should_Return_Absolute_Directory_Path()
            {
                // Given
                var context = Substitute.For <ICakeContext>();

                context.Environment.WorkingDirectory.Returns(d => "/Working");

                // When
                var result = FileAliases.MakeAbsolute(context, "./build.txt");

                // Then
                Assert.Equal("/Working/build.txt", result.FullPath);
            }
            public void Should_Log_Verbose_Message_With_Correct_Target()
            {
                // Given
                var fixture = new FileCopyFixture();

                // When
                FileAliases.CopyFile(fixture.Context, "./file1.txt", "./target/file1.txt");

                // Then
                Assert.Contains(fixture.Log.Entries,
                                entry =>
                                entry.Level == LogLevel.Verbose && entry.Verbosity == Verbosity.Verbose &&
                                entry.Message == "Copying file file1.txt to /Working/target/file1.txt");
            }
Exemple #25
0
            public void Should_Return_False_If_Directory_Does_Not_Exist()
            {
                // Given
                var context    = Substitute.For <ICakeContext>();
                var fileSystem = new FakeFileSystem(false);

                context.FileSystem.Returns(fileSystem);

                // When
                var result = FileAliases.FileExists(context, "non-existent-file.txt");

                // Then
                Assert.False(result);
            }
Exemple #26
0
		// Ok, let's explain why this method uses the "new" keyword.
		// In the olden days (before September 2009) the user would call
		// FlatRedBallServices.Load<TypeToLoad> which would investigate whether
		// the user passed an assetName that had an extension or not.  Then the
		// FlatRedBallServices class would call LoadFromFile or LoadFromProject
		// depending on the presence of an extension.
		//
		// In an effort to reduce the responsibilities of the FlatRedBallServices
		// class, Vic decided to move the loading code (including the logic that branches
		// depending on whether an asset has an extension) into the ContentManager class.
		// To keep things simple, the FlatRedBallServices just has to call Load and the Load
		// method will do the branching inside the ContentManager class.  That all worked well,
		// except that the branching code also "standardizes" the name, which means it turns relative
		// paths into absolute paths.  The reason this is a problem is IF the user loads an object (such
		// as a .X file) which references another file, then the Load method will be called again on the referenced
		// asset name.
		//
		// The FRB ContentManager doesn't use relative directories - instead, it makes all assets relative to the .exe
		// by calling Standardize.  However, if Load is called by XNA code (such as when loading a .X file)
		// then any files referenced by the X will come in already made relative to the ContentManager.  
		// This means that if a .X file was "Content\myModel" and it referenced myTexture.png which was in the same
		// folder as the .X file, then Load would get called with "Content\myTexture" as the argument.  That is, the .X loading
		// code would already prepend "Content\" before "myTexture.  But the FRB content manager wouldn't know this, and it'd
		// try to standardize it as well, making the file "Content\Content\myTexture."
		//
		// So the solution?  We make Load a "new" method.  That means that if Load is called by XNA, then it'll call the
		// Load of XNA's ContentManager.  But if FRB calls it, it'll call the "new" version.  Problem solved.
		public new T Load<T>(string assetName)
		{
            var standardized = FileManager.Standardize(assetName);

            if(FileAliases.ContainsKey(standardized))
            {
                assetName = FileAliases[standardized];
            }

			// Assets can be loaded either from file or from assets referenced
			// in the project.
			string extension = FileManager.GetExtension(assetName);

            #region If there is an extension, loading from file or returning an already-loaded asset
			assetName = FileManager.Standardize(assetName);

			if (extension != String.Empty)
			{
				return LoadFromFile<T>(assetName);
			}

#endregion

            #region Else there is no extension, so the file is already part of the project.  Use a ContentManager
			else
			{
#if PROFILE
				bool exists = false;

				exists = IsAssetLoadedByName<T>(assetName);
				
				if (exists)
				{
					mHistory.Add(new ContentLoadHistory(
						TimeManager.CurrentTime, typeof(T).Name, assetName, ContentLoadDetail.Cached));
				}
				else
				{
					mHistory.Add(new ContentLoadHistory(
						TimeManager.CurrentTime, typeof(T).Name, assetName, ContentLoadDetail.HddFromContentPipeline));
				}
#endif



				return LoadFromProject<T>(assetName);
			}
#endregion

		}
        public static void ModifyUnicornSourceFolder(this ICakeContext context, string unicornSerializationFolder, string DevSettingsFile, string sourceFolderName)
        {
            var rootXPath         = "configuration/sitecore/sc.variable[@name='{0}']/@value";
            var directoryPath     = FileAliases.MakeAbsolute(context, unicornSerializationFolder).FullPath;
            var sourceFolderXPath = string.Format(rootXPath, sourceFolderName);

            var xmlSetting = new XmlPokeSettings
            {
                Namespaces = new Dictionary <string, string> {
                    { "patch", @"http://www.sitecore.net/xmlconfig/" }
                }
            };

            context.XmlPoke(DevSettingsFile, sourceFolderXPath, directoryPath, xmlSetting);
        }
Exemple #28
0
            public void Should_Return_True_If_Directory_Exist()
            {
                // Given
                var context    = Substitute.For <ICakeContext>();
                var fileSystem = new FakeFileSystem(false);

                fileSystem.GetCreatedFile("some file.txt");
                context.FileSystem.Returns(fileSystem);

                // When
                var result = FileAliases.FileExists(context, "some file.txt");

                // Then
                Assert.True(result);
            }
Exemple #29
0
            public void Should_Expand_Existing_Environment_Variables()
            {
                // Given
                var context     = Substitute.For <ICakeContext>();
                var environment = FakeEnvironment.CreateWindowsEnvironment();

                environment.SetEnvironmentVariable("FOO", "bar");
                context.Environment.Returns(environment);

                // When
                var result = FileAliases.ExpandEnvironmentVariables(context, "/%FOO%/baz.qux");

                // Then
                Assert.Equal("/bar/baz.qux", result.FullPath);
            }
            public void Should_Throw_If_File_Do_Not_Exist()
            {
                // Given
                var fixture = new FileCopyFixture();

                fixture.TargetFiles[0] = Substitute.For <IFile>();
                fixture.TargetFiles[0].Exists.Returns(false);

                // When
                var result = Record.Exception(() =>
                                              FileAliases.MoveFile(fixture.Context, "./file1.txt", "./target/file1.txt"));

                // Then
                Assert.IsType <FileNotFoundException>(result);
                Assert.Equal("The file '/Working/file1.txt' do not exist.", result.Message);
            }