public static GetProjectRoot ( ) : string | ||
Результат | string |
void when_migrating() { var dir = TestExtensions.GetProjectRoot() + "/Tests/Tests/Tests/Entitas.Migration/Fixtures/M0360"; IMigration m = null; before = () => { m = new M0360_2(); }; it["finds all reactive system"] = () => { var updatedFiles = m.Migrate(dir); updatedFiles.Length.should_be(1); updatedFiles.Any(file => file.fileName == Path.Combine(dir, "AddViewFromObjectPoolSystem.cs")).should_be_true(); }; xit["migrates to new api"] = () => { //var updatedFiles = m.Migrate(dir); //var systemFile = updatedFiles.Single(file => file.fileName == Path.Combine(dir, "AddViewFromObjectPoolSystem.cs")); //if(systemFile.fileContent != expected) { //System.Console.WriteLine(systemFile.fileContent); //} //systemFile.fileContent.should_be(expected); }; }
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_migrating() { var dir = TestExtensions.GetProjectRoot() + "/Tests/Tests/Tests/Entitas.Migration/Fixtures/M0300"; IMigration m = null; before = () => { m = new M0300(); }; it["finds all files"] = () => { var updatedFiles = m.Migrate(dir); updatedFiles.Length.should_be(1); updatedFiles.Any(file => file.fileName == Path.Combine(dir, "Entitas.properties")).should_be_true(); }; it["updates Entitas.properties"] = () => { var updatedFiles = m.Migrate(dir); var file = updatedFiles[0]; file.fileContent.Contains("ComponentsGenerator").should_be_false(); file.fileContent.Contains("ComponentExtensionsGenerator").should_be_true(); file.fileContent.Contains("PoolAttributeGenerator").should_be_false(); file.fileContent.Contains("PoolAttributesGenerator").should_be_true(); }; }
void when_migrating() { var dir = TestExtensions.GetProjectRoot() + "/Tests/Tests/Tests/Entitas.Migration/Fixtures/M0190"; IMigration m = null; before = () => { m = new M0190(); }; it["finds all reactive system"] = () => { var updatedFiles = m.Migrate(dir); updatedFiles.Length.should_be(3); updatedFiles.Any(file => file.fileName == Path.Combine(dir, "RenderPositionSystem.cs")).should_be_true(); updatedFiles.Any(file => file.fileName == Path.Combine(dir, "RenderRotationSystem.cs")).should_be_true(); updatedFiles.Any(file => file.fileName == Path.Combine(dir, Path.Combine("SubFolder", "RenderSelectedSystem.cs"))).should_be_true(); }; it["migrates to new api"] = () => { var updatedFiles = m.Migrate(dir); var reactiveSystemFile = updatedFiles.Where(file => file.fileName == Path.Combine(dir, "RenderRotationSystem.cs")).First(); reactiveSystemFile.fileContent.should_be(@"using Entitas; public class RenderRotationSystem : IReactiveSystem { public IMatcher trigger { get { return Matcher.AllOf(CoreMatcher.Rotation, CoreMatcher.View); } } public GroupEventType eventType { get { return GroupEventType.OnEntityAdded; } } public void Execute(System.Collections.Generic.List<Entity> entities) { // Do sth } } "); }; }
void when_migrating() { var dir = TestExtensions.GetProjectRoot() + "/Tests/Tests/Entitas.Migration/Fixtures/M0220"; IMigration m = null; before = () => { m = new M0220(); }; it["finds all reactive system"] = () => { var updatedFiles = m.Migrate(dir); updatedFiles.Length.should_be(1); updatedFiles.Any(file => file.fileName == Path.Combine(dir, "RenderPositionSystem.cs")).should_be_true(); }; it["migrates to new api"] = () => { var updatedFiles = m.Migrate(dir); var reactiveSystemFile = updatedFiles.Single(file => file.fileName == Path.Combine(dir, "RenderPositionSystem.cs")); reactiveSystemFile.fileContent.should_be(@"using System.Collections.Generic; using Entitas; public class RenderPositionSystem : IReactiveSystem { public TriggerOnEvent trigger { get { return Matcher.AllOf(Matcher.Position, Matcher.View).OnEntityAdded(); } } public void Execute(List<Entity> entities) { } } "); }; }
void when_checking_namespaces() { var projectRoot = TestExtensions.GetProjectRoot(); var sourceFiles = TestExtensions.GetSourceFiles(projectRoot); it["processes roughly the correct number of files"] = () => { sourceFiles.Count.should_be_greater_than(80); sourceFiles.Count.should_be_less_than(150); }; const string namespacePattern = @"(?:^namespace)\s.*\b"; string expectedNamespacePattern = string.Format(@"[^\{0}]*", Path.DirectorySeparatorChar); var entitasSourceDir = dir("Entitas", "Entitas"); var entitasUnitySourceDir = dir("Entitas.Unity", "Assets", "Entitas", "Unity"); var each = new Each <string, string, string>(); foreach (var file in sourceFiles) { string expectedNamespace; var fileName = file.Key .Replace(dir(projectRoot), string.Empty) .Replace(entitasSourceDir + "CodeGenerator", "Entitas.CodeGenerator") .Replace(entitasSourceDir + dir("Serialization", "Blueprints"), "Entitas.Serialization.Blueprints/") .Replace(entitasSourceDir + dir("Serialization", "Configuration"), "Entitas.Serialization.Configuration/") .Replace(entitasSourceDir + "Serialization", "Entitas.Serialization") .Replace(entitasUnitySourceDir + "CodeGenerator", "Entitas.Unity.CodeGenerator") .Replace(entitasUnitySourceDir + "VisualDebugging", "Entitas.Unity.VisualDebugging") .Replace(entitasUnitySourceDir + dir("Serialization", "Blueprints"), "Entitas.Unity.Serialization.Blueprints/") .Replace(entitasUnitySourceDir + "Migration", "Entitas.Unity.Migration"); if (file.Key.Contains(typeof(Entitas.Feature).Name) || file.Key.Contains("BlueprintEntityExtension")) { expectedNamespace = "Entitas"; } else { expectedNamespace = Regex.Match(fileName, expectedNamespacePattern) .ToString() .Replace("namespace ", string.Empty) .Trim(); } var foundNamespace = Regex.Match(file.Value, namespacePattern, RegexOptions.Multiline) .ToString() .Replace("namespace ", string.Empty) .Trim(); each.Add(new NSpecTuple <string, string, string>(fileName, foundNamespace, expectedNamespace)); } each.Do((fileName, given, expected) => it["{0} namespace should be {2}".With(fileName, given, expected)] = () => given.should_be(expected) ); }
void when_checking_namespaces() { var projectRoot = TestExtensions.GetProjectRoot(); var sourceFiles = TestExtensions.GetSourceFiles(projectRoot); it["processes roughly the correct number of files"] = () => { sourceFiles.Count.should_be_greater_than(80); sourceFiles.Count.should_be_less_than(200); }; System.Console.WriteLine("sourceFiles: " + sourceFiles.Count); const string namespacePattern = @"(?:^namespace)\s.*\b"; string expectedNamespacePattern = string.Format(@"[^\{0}]*", Path.DirectorySeparatorChar); var addonsDir = dir("Addons"); var each = new Each <string, string, string>(); foreach (var file in sourceFiles) { var fileName = file.Key .Replace(dir(projectRoot), string.Empty) .Replace(addonsDir, string.Empty); string expectedNamespace; if (file.Key.Contains(typeof(Entitas.Feature).Name)) { expectedNamespace = "Entitas"; } else if (file.Key.Contains("EntityLink.cs")) { expectedNamespace = "Entitas.Unity"; } else { expectedNamespace = Regex.Match(fileName, expectedNamespacePattern) .ToString() .Replace("namespace ", string.Empty) .Trim(); } var foundNamespace = Regex.Match(file.Value, namespacePattern, RegexOptions.Multiline) .ToString() .Replace("namespace ", string.Empty) .Trim(); each.Add(new NSpecTuple <string, string, string>(fileName, foundNamespace, expectedNamespace)); } each.Do((fileName, given, expected) => it["{0} namespace should be {2}".With(fileName, given, expected)] = () => given.should_be(expected) ); }
void when_migrating() { var dir = TestExtensions.GetProjectRoot() + "/Tests/Tests/Entitas.Migration/Fixtures/M0180"; it["gets only *.cs source files"] = () => { var files = MigrationUtils.GetFiles(dir); files.Length.should_be(6); files.Any(file => file.fileName == Path.Combine(dir, "SourceFile.cs")).should_be_true(); files.Any(file => file.fileName == Path.Combine(dir, Path.Combine("SubFolder", "SourceFile2.cs"))).should_be_true(); files.Any(file => file.fileName == Path.Combine(dir, "RenderPositionSystem.cs")).should_be_true(); files.Any(file => file.fileName == Path.Combine(dir, "RenderRotationSystem.cs")).should_be_true(); files.Any(file => file.fileName == Path.Combine(dir, Path.Combine("SubFolder", "RenderSelectedSystem.cs"))).should_be_true(); files.Any(file => file.fileName == Path.Combine(dir, Path.Combine("SubFolder", "MoveSystem.cs"))).should_be_true(); }; }
void when_post_processing() { xit["manual test"] = () => { var p = new UpdateCSProjPostProcessor(); p.Configure(new Properties( "Entitas.CodeGeneration.Plugins.ProjectPath = " + TestExtensions.GetProjectRoot() + "/../Match-One/Assembly-CSharp.csproj" + "\n" + "Entitas.CodeGeneration.Plugins.TargetDirectory = Assets/Sources" )); var files = new [] { new CodeGenFile("My/Generated/Folder/File1.cs", "Hello, world!", "Test"), new CodeGenFile("My/Generated/Folder/File2.cs", "Hello, world!", "Test") }; p.PostProcess(files); }; }
void when_resolving() { xcontext["when no dependencies"] = () => { string dllPath = null; Type[] types = null; before = () => { dllPath = TestExtensions.GetProjectRoot() + "/Tests/Tests.Fixtures/TestDependenyBase/bin/Release/TestDependenyBase.dll"; var resolver = new AssemblyResolver(AppDomain.CurrentDomain, new string[0]); resolver.Load(dllPath); types = resolver.GetTypes(); }; it["loads dll"] = () => { types.Length.should_be(1); types[0].FullName.should_be("TestDependenyBase.Point"); }; it["instantiates type"] = () => { Activator.CreateInstance(types[0]); }; }; xcontext["when dependencies"] = () => { string dllPath = null; Type[] types = null; before = () => { dllPath = TestExtensions.GetProjectRoot() + "/Tests/Tests.Fixtures/TestDependency/bin/Release/TestDependency.dll"; var resolver = new AssemblyResolver(AppDomain.CurrentDomain, new string[0]); resolver.Load(dllPath); types = resolver.GetTypes(); }; it["loads dll with all dependencies"] = () => { types.Length.should_be(1); types[0].FullName.should_be("TestDependency.PositionComponent"); }; it["instantiates type"] = () => { Activator.CreateInstance(types[0]); }; }; }
void when_migrating() { var dir = TestExtensions.GetProjectRoot() + "/Tests/Tests/Entitas.Migration/Fixtures/M0320"; IMigration m = null; before = () => { m = new M0320(); }; it["finds all files"] = () => { var updatedFiles = m.Migrate(dir); updatedFiles.Length.should_be(2); updatedFiles.Any(file => file.fileName == Path.Combine(dir, "Entitas.properties")).should_be_true(); updatedFiles.Any(file => file.fileName == Path.Combine(dir, "Systems.cs")).should_be_true(); }; it["updates Entitas.properties"] = () => { var updatedFiles = m.Migrate(dir); var file = updatedFiles[0]; file.fileContent.Contains("Entitas.Unity.CodeGenerator.GeneratedFolderPath").should_be_false(); file.fileContent.Contains("Entitas.CodeGenerator.GeneratedFolderPath").should_be_true(); file.fileContent.Contains("Entitas.Unity.CodeGenerator.Pools").should_be_false(); file.fileContent.Contains("Entitas.CodeGenerator.Pools").should_be_true(); file.fileContent.Contains("Entitas.Unity.CodeGenerator.EnabledCodeGenerators").should_be_false(); file.fileContent.Contains("Entitas.CodeGenerator.EnabledCodeGenerators").should_be_true(); // Ignores Entitas.Unity.VisualDebugging file.fileContent.Contains("Entitas.Unity.VisualDebugging.DefaultInstanceCreatorFolderPath").should_be_true(); file.fileContent.Contains("Entitas.Unity.VisualDebugging.TypeDrawerFolderPath").should_be_true(); }; it["updates pool.CreateSystem(instance)"] = () => { var updatedFiles = m.Migrate(dir); var file = updatedFiles[1]; file.fileContent.should_be("pool.CreateSystem(new MySystem1());\npool.CreateSystem(new MySystem2());\n"); }; }
void when_migrating() { var dir = TestExtensions.GetProjectRoot() + "/Tests/Tests/Tests/Entitas.Migration/Fixtures/M0450"; IMigration m = null; before = () => { m = new M0450(); }; it["finds all files"] = () => { var updatedFiles = m.Migrate(dir); updatedFiles.Length.should_be(1); updatedFiles.Any(file => file.fileName == Path.Combine(dir, "Entitas.properties")).should_be_true(); }; it["updates Entitas.properties"] = () => { var updatedFiles = m.Migrate(dir); var file = updatedFiles[0]; file.fileContent.Contains("Entitas.CodeGeneration.CodeGenerator.SearchPaths").should_be_false(); file.fileContent.Contains("CodeGenerator.SearchPaths").should_be_true(); file.fileContent.Contains("Entitas.CodeGeneration.CodeGenerator.Plugins").should_be_false(); file.fileContent.Contains("CodeGenerator.Plugins").should_be_true(); file.fileContent.Contains("Entitas.CodeGeneration.CodeGenerator.DataProviders").should_be_false(); file.fileContent.Contains("CodeGenerator.DataProviders").should_be_true(); file.fileContent.Contains("Entitas.CodeGeneration.CodeGenerator.CodeGenerators").should_be_false(); file.fileContent.Contains("CodeGenerator.CodeGenerators").should_be_true(); file.fileContent.Contains("Entitas.CodeGeneration.CodeGenerator.PostProcessors").should_be_false(); file.fileContent.Contains("CodeGenerator.PostProcessors").should_be_true(); file.fileContent.Contains("Entitas.CodeGeneration.CodeGenerator.CLI.Ignore.UnusedKeys").should_be_false(); file.fileContent.Contains("CodeGenerator.CLI.Ignore.UnusedKeys").should_be_true(); }; }
void when_migrating() { var dir = TestExtensions.GetProjectRoot() + "/Tests/Tests/Entitas.Migration/Fixtures/M0260"; IMigration m = null; before = () => { m = new M0260(); }; it["finds all files"] = () => { var updatedFiles = m.Migrate(dir); updatedFiles.Length.should_be(2); updatedFiles.Any(file => file.fileName == Path.Combine(dir, "Pools.cs")).should_be_true(); updatedFiles.Any(file => file.fileName == Path.Combine(dir, "ScoreComponentGeneratedExtension.cs")).should_be_true(); }; it["deactivates code in Pools.cs"] = () => { var updatedFiles = m.Migrate(dir); var poolsFile = updatedFiles.Single(file => file.fileName == Path.Combine(dir, "Pools.cs")); poolsFile.fileContent.should_be(@"using Entitas; public static class Pools { static Pool[] _allPools; public static Pool[] allPools { get { if(_allPools == null) { _allPools = new [] { meta, core }; } return _allPools; } } static Pool _meta; public static Pool meta { get { if(_meta == null) { _meta = new Pool(MetaComponentIds.TotalComponents); #if(!ENTITAS_DISABLE_VISUAL_DEBUGGING && UNITY_EDITOR) //var poolObserver = new Entitas.Unity.VisualDebugging.PoolObserver(_meta, MetaComponentIds.componentNames, MetaComponentIds.componentTypes, ""Meta Pool""); //UnityEngine.Object.DontDestroyOnLoad(poolObserver.entitiesContainer); #endif } return _meta; } } static Pool _core; public static Pool core { get { if(_core == null) { _core = new Pool(CoreComponentIds.TotalComponents); #if(!ENTITAS_DISABLE_VISUAL_DEBUGGING && UNITY_EDITOR) //var poolObserver = new Entitas.Unity.VisualDebugging.PoolObserver(_core, CoreComponentIds.componentNames, CoreComponentIds.componentTypes, ""Core Pool""); //UnityEngine.Object.DontDestroyOnLoad(poolObserver.entitiesContainer); #endif } return _core; } } } "); }; it["deactivates code in components"] = () => { var updatedFiles = m.Migrate(dir); var poolsFile = updatedFiles.Single(file => file.fileName == Path.Combine(dir, "ScoreComponentGeneratedExtension.cs")); poolsFile.fileContent.should_be(@"using System.Collections.Generic; namespace Entitas { public partial class Entity { public ScoreComponent score { get { return (ScoreComponent)GetComponent(ComponentIds.Score); } } public bool hasScore { get { return HasComponent(ComponentIds.Score); } } static readonly Stack<ScoreComponent> _scoreComponentPool = new Stack<ScoreComponent>(); public static void ClearScoreComponentPool() { _scoreComponentPool.Clear(); } public Entity AddScore(int newValue) { var component = _scoreComponentPool.Count > 0 ? _scoreComponentPool.Pop() : new ScoreComponent(); component.value = newValue; return AddComponent(ComponentIds.Score, component); } public Entity ReplaceScore(int newValue) { var previousComponent = hasScore ? score : null; var component = _scoreComponentPool.Count > 0 ? _scoreComponentPool.Pop() : new ScoreComponent(); component.value = newValue; ReplaceComponent(ComponentIds.Score, component); if(previousComponent != null) { _scoreComponentPool.Push(previousComponent); } return this; } public Entity RemoveScore() { var component = score; RemoveComponent(ComponentIds.Score); _scoreComponentPool.Push(component); return this; } } public partial class Pool { public Entity scoreEntity { get { return GetGroup(Matcher.Score).GetSingleEntity(); } } public ScoreComponent score { get { return scoreEntity.score; } } public bool hasScore { get { return scoreEntity != null; } } public Entity SetScore(int newValue) { if(hasScore) { //throw new SingleEntityException(Matcher.Score); } var entity = CreateEntity(); entity.AddScore(newValue); return entity; } public Entity ReplaceScore(int newValue) { var entity = scoreEntity; if(entity == null) { entity = SetScore(newValue); } else { entity.ReplaceScore(newValue); } return entity; } public void RemoveScore() { DestroyEntity(scoreEntity); } } public partial class Matcher { static IMatcher _matcherScore; public static IMatcher Score { get { if(_matcherScore == null) { _matcherScore = Matcher.AllOf(ComponentIds.Score); } return _matcherScore; } } } } "); }; }