public static void run_executes_the_expected_file_operations_when_running_an_unrealcommandjob() { var mockFileSystem = GenerateMockFileSystem(); mockFileSystem.GetFileInfoMock = (path) => { var file = new MockFileWrapper(path, Path.GetDirectoryName(path), new DateTime(1, 1, 1)); file.ExistsMock = () => { return(false); }; return(file); }; mockFileSystem.GetFilesInDirectoryMock = (path, searchpattern, recursive) => { return(new List <IFile>()); }; var unrealPackageDetails = new UnrealPackageDetails("improbable.codegen.TestComponent", TestSchemaPath, "improbable.codegen"); var responseTypeReference = new UnrealBuiltInTypeReference(GenerateTypeReferenceRaw()); var requestTypeReference = new UnrealBuiltInTypeReference(GenerateTypeReferenceRaw()); var unrealCommandDetails = new UnrealCommandDetails(GenerateCommandDefinition(), "TestCommand", "improbable.codegen.TestComponent", "TestComponent", requestTypeReference, responseTypeReference, unrealPackageDetails); var commandJob = new UnrealCommandJob(unrealCommandDetails, Path.Combine("OutputDir", "test"), mockFileSystem); var jobRunner = new JobRunner(mockFileSystem); jobRunner.Run(new List <ICodegenJob>() { commandJob }, new List <string>() { OutputDirectory }); Assert.That(mockFileSystem.DirectoryExistsCallCount == 2); Assert.That(mockFileSystem.WriteToFileCallCount == 2); Assert.That(mockFileSystem.WrittenFiles.Count == 2); Assert.That(mockFileSystem.WrittenFiles.Contains(Path.Combine(OutputDirectory, "TestCommandCommandResponder.h"))); Assert.That(mockFileSystem.WrittenFiles.Contains(Path.Combine(OutputDirectory, "TestCommandCommandResponder.cpp"))); }
public static void run_writes_the_expected_output_files_to_disk() { var fileSystem = GenerateMockFileSystem(); fileSystem.GetFileInfoMock = (path) => { var fileWrapper = new MockFileWrapper(path, Path.GetDirectoryName(path), new DateTime(1, 1, 1)); fileWrapper.ExistsMock = () => { return(true); }; fileWrapper.DeleteMock = () => { }; return(fileWrapper); }; var schemaFileRaw = TestUtils.GetRawJsonDataFromResource <SchemaFileRaw>("Improbable.CodeGeneration.Resources.json.test.command.json"); var schemaFileProcessor = new UnrealSchemaProcessor(new List <SchemaFileRaw>() { schemaFileRaw }); var job = new UnrealCommandJob(schemaFileProcessor.unrealCommandDetails.First(), outputDir, fileSystem); job.Run(); Assert.That(fileSystem.WrittenFiles.Count == 2, "UnrealCommandJob did not write the expected number of files"); var fullOutputDir = Path.Combine("Codegen", "Test"); Assert.That(fileSystem.WrittenFiles.Contains(Path.Combine(fullOutputDir, "ExampleCommandCommandResponder.h")), "UnrealCommandJob did not write the expected files"); Assert.That(fileSystem.WrittenFiles.Contains(Path.Combine(fullOutputDir, "ExampleCommandCommandResponder.cpp")), "UnrealCommandJob did not write the expected files"); }
public static void clean_removes_the_expected_files() { var fileSystem = GenerateMockFileSystem(); var fileWrapperList = new List <MockFileWrapper>(); fileSystem.GetFileInfoMock = (path) => { var fileWrapper = new MockFileWrapper(path, Path.GetDirectoryName(path), new DateTime(1, 1, 1)); fileWrapper.ExistsMock = () => { return(true); }; fileWrapper.DeleteMock = () => { }; fileWrapperList.Add(fileWrapper); return(fileWrapper); }; fileSystem.GetFilesInDirectoryMock = (path, searchpattern, recursive) => { return(new List <IFile>() { new MockFileWrapper(path, Path.GetDirectoryName(path), new DateTime(1, 1, 1)) }); }; var schemaFileRaw = TestUtils.GetRawJsonDataFromResource <SchemaFileRaw>("Improbable.CodeGeneration.Resources.json.test.command.json"); var schemaFileProcessor = new UnrealSchemaProcessor(new List <SchemaFileRaw>() { schemaFileRaw }); var job = new UnrealCommandJob(schemaFileProcessor.unrealCommandDetails.First(), outputDir, fileSystem); job.Clean(); Assert.That(fileWrapperList.Count == 2, "clean did not scan for the expected files to be deleted"); foreach (var fileWrapper in fileWrapperList) { Assert.That(fileWrapper.DeleteCallCount == 1, "Did not call Delete the expected number of times for a filewrapper"); Assert.That(fileWrapper.ExistsCallCount == 1, "Did not call Exists the expected number of times for a filewrapper"); } var fullOutputDir = Path.Combine("Codegen", "Test"); Assert.That(fileWrapperList.Exists((fileWrapper) => fileWrapper.CompletePath == Path.Combine(fullOutputDir, "ExampleCommandCommandResponder.h"))); Assert.That(fileWrapperList.Exists((fileWrapper) => fileWrapper.CompletePath == Path.Combine(fullOutputDir, "ExampleCommandCommandResponder.cpp"))); }