예제 #1
0
        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 UnrealCommanderJob(schemaFileProcessor.unrealCommandDetails, new HashSet <string>(), outputDir, fileSystem);

            job.Run();

            Assert.That(fileSystem.WrittenFiles.Count == 2, "UnrealCommanderJob did not write the expected number of files");

            var fullOutputDir = Path.Combine("Codegen", "Test");

            Assert.That(fileSystem.WrittenFiles.Contains(Path.Combine(fullOutputDir, "Commander.h")), "UnrealCommanderJob did not write the expected files");
            Assert.That(fileSystem.WrittenFiles.Contains(Path.Combine(fullOutputDir, "Commander.cpp")), "UnrealCommanderJob did not write the expected files");
        }
예제 #2
0
        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.enum.json");

            var schemaFileProcessor = new UnrealSchemaProcessor(new List <SchemaFileRaw>()
            {
                schemaFileRaw
            });
            var job = new UnrealCommanderJob(schemaFileProcessor.unrealCommandDetails, new HashSet <string>(), 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, "Commander.h")));
            Assert.That(fileWrapperList.Exists((fileWrapper) => fileWrapper.CompletePath == Path.Combine(fullOutputDir, "Commander.cpp")));
        }
예제 #3
0
        public static void run_executes_the_expected_file_operations_when_running_an_unrealcommanderjob()
        {
            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 commanderJob          = new UnrealCommanderJob(new List <UnrealCommandDetails> {
                unrealCommandDetails
            }, new HashSet <string>(), Path.Combine("OutputDir", "test"), mockFileSystem);

            var jobRunner = new JobRunner(mockFileSystem);

            jobRunner.Run(new List <ICodegenJob>()
            {
                commanderJob
            }, 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, "Commander.h")));
            Assert.That(mockFileSystem.WrittenFiles.Contains(Path.Combine(OutputDirectory, "Commander.cpp")));
        }