public async void EntityInvoker_InvalidDetectorId(string idValue)
        {
            Definition def = new Definition()
            {
                Id = idValue
            };
            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = await ScriptTestDataHelper.GetDetectorScript(def, ResourceType.App);

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                Assert.False(invoker.IsCompilationSuccessful);
                Assert.NotEmpty(invoker.CompilationOutput);
            }
        }
        public async void EntityInvoker_TestResourceAttributeResolution(ResourceType resType, Type filterType)
        {
            Definition definitonAttribute = new Definition()
            {
                Id = "TestId"
            };

            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = await ScriptTestDataHelper.GetDetectorScript(definitonAttribute, resType);

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                Assert.Equal <Definition>(definitonAttribute, invoker.EntryPointDefinitionAttribute);
                Assert.Equal(filterType, invoker.ResourceFilter.GetType());
            }
        }
        public async void EntityInvoker_TestSaveAssemblyToInvalidPath()
        {
            Definition definitonAttribute = new Definition()
            {
                Id = "TestId"
            };

            string         assemblyPath = string.Empty;
            EntityMetadata metadata     = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = await ScriptTestDataHelper.GetDetectorScript(definitonAttribute);

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                await Assert.ThrowsAsync <ArgumentNullException>(async() =>
                {
                    await invoker.SaveAssemblyToDiskAsync(assemblyPath);
                });
            }
        }
        public async void EntityInvoker_TestSaveAssemblyToDisk()
        {
            Definition definitonAttribute = new Definition()
            {
                Id = "TestId"
            };

            string         assemblyPath = $@"{Directory.GetCurrentDirectory()}\{Guid.NewGuid().ToString()}";
            EntityMetadata metadata     = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = await ScriptTestDataHelper.GetDetectorScript(definitonAttribute);

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                await invoker.SaveAssemblyToDiskAsync(assemblyPath);

                Assert.True(File.Exists($"{assemblyPath}.dll"));
                Assert.True(File.Exists($"{assemblyPath}.pdb"));
            }
        }
        public async void EntityInvoker_TestInitializationUsingAssembly()
        {
            // First Create and Save a assembly for test purposes.
            Definition definitonAttribute = new Definition()
            {
                Id = "TestId"
            };

            string         assemblyPath = $@"{Directory.GetCurrentDirectory()}/{Guid.NewGuid().ToString()}";
            EntityMetadata metadata     = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = await ScriptTestDataHelper.GetDetectorScript(definitonAttribute);

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                await invoker.SaveAssemblyToDiskAsync(assemblyPath);

                Assert.True(File.Exists($"{assemblyPath}.dll"));
                Assert.True(File.Exists($"{assemblyPath}.pdb"));
            }

            // Now test initializing Entry Point of Invoker using assembly
            Assembly asm = Assembly.LoadFrom($"{assemblyPath}.dll");

            using (EntityInvoker invoker = new EntityInvoker(metadata))
            {
                Exception ex = Record.Exception(() =>
                {
                    invoker.InitializeEntryPoint(asm);
                });

                Assert.Null(ex);
                Assert.True(invoker.IsCompilationSuccessful);
                Assert.Equal(definitonAttribute.Id, invoker.EntryPointDefinitionAttribute.Id);
            }
        }
        public async void EntityInvoker_TestGetAssemblyBytes()
        {
            Definition definitonAttribute = new Definition()
            {
                Id = "TestId"
            };

            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = await ScriptTestDataHelper.GetDetectorScript(definitonAttribute);

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                Tuple <string, string> asmPair = await invoker.GetAssemblyBytesAsync();

                string assemblyBytes = asmPair.Item1;
                string pdbBytes      = asmPair.Item2;

                Assert.False(string.IsNullOrWhiteSpace(assemblyBytes));
                Assert.False(string.IsNullOrWhiteSpace(pdbBytes));
            }
        }