static void generates <T>(string expectedFileName = null) { var entitasDir = new DirectoryInfo(Directory.GetCurrentDirectory()); var fixturesDir = entitasDir + "/Tests/Tests/Entitas/CodeGenerator/Fixtures/Generated/"; expectedFileName = (expectedFileName ?? typeof(T).FullName) + "GeneratedExtension"; var path = fixturesDir + expectedFileName + ".cs"; var expectedFileContent = File.ReadAllText(path); var info = TypeReflectionProvider.GetComponentInfos(typeof(T)).Single(); var codeGenFiles = new ComponentExtensionsGenerator().Generate(new [] { info }); codeGenFiles.Length.should_be(1); var codeGenFile = codeGenFiles.Single(); #pragma warning disable if (logResults) { Console.WriteLine("should:\n" + expectedFileContent); Console.WriteLine("was:\n" + codeGenFile.fileContent); } codeGenFile.fileName.should_be(expectedFileName); codeGenFile.fileContent.should_be(expectedFileContent); }
void when_generating() { it["component without fields"] = () => generates <MovableComponent>(); it["component with fields"] = () => generates <PersonComponent>(); it["single component without fields"] = () => generates <AnimatingComponent>(); it["single component with fields"] = () => generates <UserComponent>(); it["component for custom pool"] = () => generates <OtherPoolComponent>(); it["supports properties"] = () => generates <ComponentWithFieldsAndProperties>(); it["ignores [DontGenerate]"] = () => { var info = TypeReflectionProvider.GetComponentInfos(typeof(DontGenerateComponent))[0]; var files = new ComponentExtensionsGenerator().Generate(new [] { info }); files.Length.should_be(0); }; it["works with namespaces"] = () => generates <NamespaceComponent>(); it["generates matchers for each pool"] = () => generates <CComponent>(); it["generates custom prefix"] = () => generates <CustomPrefixComponent>(); it["generates component with default pool"] = () => generates <DefaultPoolComponent>(); it["generates component with default pool and others"] = () => generates <MultiplePoolAndDefaultPoolComponent>(); it["generates component for class"] = () => generates <SomeClass>("SomeClassComponent"); it["generates component for struct"] = () => generates <SomeStruct>("SomeStructComponent"); it["generates component for class with HideInBlueprintInspectorAttribute"] = () => generates <SomeClassHideInBlueprintInspector>("SomeClassHideInBlueprintInspectorComponent"); }
static void generates <T>(string expectedFileName = null) { var projectRoot = TestExtensions.GetProjectRoot(); var fixturesDir = projectRoot + "/Tests/Tests/Entitas/CodeGenerator/Fixtures/Generated/"; expectedFileName = (expectedFileName ?? typeof(T).FullName) + "GeneratedExtension"; var path = fixturesDir + expectedFileName + ".cs"; var expectedFileContent = File.ReadAllText(path); var info = TypeReflectionProvider.GetComponentInfos(typeof(T)).Single(); var codeGenFiles = new ComponentExtensionsGenerator().Generate(new [] { info }); codeGenFiles.Length.should_be(1); var codeGenFile = codeGenFiles.Single(); #pragma warning disable if (logResults) { Console.WriteLine("should:\n" + expectedFileContent); Console.WriteLine("was:\n" + codeGenFile.fileContent); } codeGenFile.fileName.should_be(expectedFileName); var header = string.Format(CodeGenerator.AUTO_GENERATED_HEADER_FORMAT, typeof(ComponentExtensionsGenerator)); (header + codeGenFile.fileContent).should_be(expectedFileContent); }
void when_generating() { it["component without fields"] = () => generates(typeof(MovableComponent), MovableComponent.extensions); it["component with fields"] = () => generates(typeof(PersonComponent), PersonComponent.extensions); it["single singleton component"] = () => generates(typeof(AnimatingComponent), AnimatingComponent.extensions); it["single component with fields"] = () => generates(typeof(UserComponent), UserComponent.extensions); it["can handle dictionary"] = () => generates(typeof(DictionaryComponent), DictionaryComponent.extensions); it["ignores [DontGenerate]"] = () => { var type = typeof(DontGenerateComponent); var generator = new ComponentExtensionsGenerator(); var extensions = generator.GenerateComponentExtensions(new[] { type }); extensions.Count.should_be(0); }; }
void when_generating() { it["component without fields"] = () => generates(typeof(MovableComponent), MovableComponent.extensions); it["component with fields"] = () => generates(typeof(PersonComponent), PersonComponent.extensions); it["single singleton component"] = () => generates(typeof(AnimatingComponent), AnimatingComponent.extensions); it["single component with fields"] = () => generates(typeof(UserComponent), UserComponent.extensions); it["component for custom pool"] = () => generates(typeof(OtherPoolComponent), OtherPoolComponent.extensions); it["ignores [DontGenerate]"] = () => { var type = typeof(DontGenerateComponent); var files = new ComponentExtensionsGenerator().Generate(new[] { type }); files.Length.should_be(0); }; it["works with namespaces"] = () => generates(typeof(NamespaceComponent), NamespaceComponent.extensions); }
void generates(Type type, string code) { var generator = new ComponentExtensionsGenerator(); var extensions = generator.GenerateComponentExtensions(new[] { type }); var filePath = type + ComponentExtensionsGenerator.classSuffix; extensions.Count.should_be(1); extensions.ContainsKey(filePath).should_be_true(); if (logResults) { Console.WriteLine("should:\n" + code); Console.WriteLine("was:\n" + extensions[filePath]); } extensions[filePath].should_be(code); }
void generates(Type type, string code) { var files = new ComponentExtensionsGenerator().Generate(new[] { type }); var filePath = type + classSuffix; files.Length.should_be(1); var file = files[0]; if (logResults) { Console.WriteLine("should:\n" + code); Console.WriteLine("was:\n" + file.fileContent); } file.fileName.should_be(filePath); file.fileContent.should_be(code); }
void when_generating() { it["component without fields"] = () => generates(MovableComponent.componentInfo, MovableComponent.extensions); it["component with fields"] = () => generates(PersonComponent.componentInfo, PersonComponent.extensions); it["single component without fields"] = () => generates(AnimatingComponent.componentInfo, AnimatingComponent.extensions); it["single component with fields"] = () => generates(UserComponent.componentInfo, UserComponent.extensions); it["component for custom pool"] = () => generates(OtherPoolComponent.componentInfo, OtherPoolComponent.extensions); it["supports properties"] = () => generates(ComponentWithFieldsAndProperties.componentInfo, ComponentWithFieldsAndProperties.extensions); it["ignores [DontGenerate]"] = () => { var componentInfo = DontGenerateComponent.componentInfo; var files = new ComponentExtensionsGenerator().Generate(new[] { componentInfo }); files.Length.should_be(0); }; it["works with namespaces"] = () => generates(NamespaceComponent.componentInfo, NamespaceComponent.extensions); it["generates matchers for each pool"] = () => generates(CComponent.componentInfo, CComponent.extensions); it["generates custom prefix"] = () => generates(CustomPrefixComponent.componentInfo, CustomPrefixComponent.extensions); }
void generates(Type type, string expectedFileContent) { expectedFileContent = expectedFileContent.ToUnixLineEndings(); var files = new ComponentExtensionsGenerator().Generate(new[] { type }); var expectedFilePath = type + classSuffix; files.Length.should_be(1); var file = files[0]; if (logResults) { Console.WriteLine("should:\n" + expectedFileContent); Console.WriteLine("was:\n" + file.fileContent); } file.fileName.should_be(expectedFilePath); file.fileContent.should_be(expectedFileContent); }
void generates(ComponentInfo componentInfo, string expectedFileContent) { expectedFileContent = expectedFileContent.ToUnixLineEndings(); var files = new ComponentExtensionsGenerator().Generate(new[] { componentInfo }); var expectedFilePath = componentInfo.fullTypeName + classSuffix; files.Length.should_be(1); var file = files[0]; #pragma warning disable if (logResults) { Console.WriteLine("should:\n" + expectedFileContent); Console.WriteLine("was:\n" + file.fileContent); } file.fileName.should_be(expectedFilePath); file.fileContent.should_be(expectedFileContent); }