public async void EntityInvoker_InvalidSupportTopicId(string supportTopicId, string pesId, bool isInternal)
        {
            Definition definitonAttribute = new Definition()
            {
                Id     = "TestId",
                Name   = "Test",
                Author = "User"
            };

            SupportTopic topic1 = new SupportTopic()
            {
                Id = supportTopicId, PesId = pesId
            };
            SupportTopic topic2 = new SupportTopic()
            {
                Id = "5678", PesId = "14878"
            };

            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = await ScriptTestDataHelper.GetDetectorScriptWithMultipleSupportTopics(definitonAttribute, isInternal, topic1, topic2);

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

                Assert.False(invoker.IsCompilationSuccessful);
                Assert.NotEmpty(invoker.CompilationOutput);
            }
        }
Exemplo n.º 2
0
        public void CompilationServiceFactory_GetServiceBasedOnType(EntityType type, object value)
        {
            EntityMetadata metaData = ScriptTestDataHelper.GetRandomMetadata(type);
            var            compilationServiceInstance = CompilationServiceFactory.CreateService(metaData, ScriptOptions.Default);

            Assert.Equal(compilationServiceInstance.GetType(), value);
        }
Exemplo n.º 3
0
        public async void E2E_Test_RuntimeSlotMapData()
        {
            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            //read a sample csx file from local directory
            metadata.ScriptText = await File.ReadAllTextAsync("GetRuntimeSiteSlotMapData.csx");

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config));

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

                var appResource = new App(string.Empty, string.Empty, "my-api")
                {
                    Stamp = new HostingEnvironment(string.Empty, string.Empty, "waws-prod-bn1-71717c45")
                    {
                        Name = "waws-prod-bn1-71717c45"
                    }
                };

                var operationContext = new OperationContext <App>(appResource, string.Empty, string.Empty, true, string.Empty);
                var response         = new Response();

                Response result = (Response)await invoker.Invoke(new object[] { dataProviders, operationContext, response });

                Assert.Equal("my-api__a88nf", result.Dataset.First().Table.Rows[1][1]);
            }
        }
        public async void EntityInvoker_TestSupportTopicAttributeResolution()
        {
            Definition definitonAttribute = new Definition()
            {
                Id     = "TestId",
                Name   = "Test",
                Author = "User"
            };

            SupportTopic topic1 = new SupportTopic()
            {
                Id = "1234", PesId = "14878"
            };
            SupportTopic topic2 = new SupportTopic()
            {
                Id = "5678", PesId = "14878"
            };

            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = await ScriptTestDataHelper.GetDetectorScriptWithMultipleSupportTopics(definitonAttribute, false, topic1, topic2);

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

                Assert.True(invoker.IsCompilationSuccessful);
                Assert.Contains <SupportTopic>(topic1, invoker.EntryPointDefinitionAttribute.SupportTopicList);
                Assert.Contains <SupportTopic>(topic2, invoker.EntryPointDefinitionAttribute.SupportTopicList);
            }
        }
Exemplo n.º 5
0
 public void CompilationServiceFactory_TestNullScriptOptions()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var instance = CompilationServiceFactory.CreateService(ScriptTestDataHelper.GetRandomMetadata(), null);
     });
 }
Exemplo n.º 6
0
        public async void TestMdmGetDimensionValuesAsync()
        {
            var metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = @"
                public async static Task<IEnumerable<string>> Run(DataProviders dataProviders) {
                    var filter = new List<Tuple<string, IEnumerable<string>>>
                    {
                        new Tuple<string, IEnumerable<string>>(""StampName"", new List<string>())
                    };

                    return await dataProviders.Mdm.GetDimensionValuesAsync(""Microsoft/Web/WebApps"", ""CpuTime"", filter, ""ServerName"", DateTime.UtcNow.AddMinutes(-30), DateTime.UtcNow);
                }";

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, Guid.NewGuid().ToString()));

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

                var result = await invoker.Invoke(new object[] { dataProviders }) as IEnumerable <string>;

                Assert.NotNull(result);
                Assert.True(result.Count() == 3);
            }
        }
Exemplo n.º 7
0
        public async void CompilationService_TestScriptCompilation()
        {
            var          serviceInstance = CompilationServiceFactory.CreateService(ScriptTestDataHelper.GetRandomMetadata(), ScriptOptions.Default);
            ICompilation compilation     = await serviceInstance.GetCompilationAsync();

            ImmutableArray <Diagnostic> diagnostics = await compilation.GetDiagnosticsAsync();

            Assert.Empty(diagnostics.Select(d => d.Severity == DiagnosticSeverity.Error));
        }
        public async void EntityInvoker_TestInvokeMethod()
        {
            using (EntityInvoker invoker = new EntityInvoker(ScriptTestDataHelper.GetRandomMetadata(), ImmutableArray.Create <string>()))
            {
                await invoker.InitializeEntryPointAsync();

                int result = (int)await invoker.Invoke(new object[] { 3 });

                Assert.Equal(9, result);
            }
        }
Exemplo n.º 9
0
        public async void CompilationService_TestVaildEntryPointResolution()
        {
            var          serviceInstance = CompilationServiceFactory.CreateService(ScriptTestDataHelper.GetRandomMetadata(), ScriptOptions.Default);
            ICompilation compilation     = await serviceInstance.GetCompilationAsync();

            Exception ex = Record.Exception(() =>
            {
                EntityMethodSignature methodSignature = compilation.GetEntryPointSignature();
            });

            Assert.Null(ex);
        }
Exemplo n.º 10
0
        public async void CompilationService_TestScriptCompilationFailure()
        {
            EntityMetadata metaData = ScriptTestDataHelper.GetRandomMetadata(EntityType.Detector);

            metaData.ScriptText = ScriptTestDataHelper.GetInvalidCsxScript(ScriptErrorType.CompilationError);

            var          serviceInstance = CompilationServiceFactory.CreateService(metaData, ScriptOptions.Default);
            ICompilation compilation     = await serviceInstance.GetCompilationAsync();

            ImmutableArray <Diagnostic> diagnostics = await compilation.GetDiagnosticsAsync();

            Assert.NotEmpty(diagnostics.Select(d => d.Severity == DiagnosticSeverity.Error));
        }
Exemplo n.º 11
0
        public async void CompilationService_TestDuplicateEntryPoints(ScriptErrorType errorType)
        {
            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = ScriptTestDataHelper.GetInvalidCsxScript(errorType);

            var          serviceInstance = CompilationServiceFactory.CreateService(metadata, ScriptOptions.Default);
            ICompilation compilation     = await serviceInstance.GetCompilationAsync();

            ScriptCompilationException ex = Assert.Throws <ScriptCompilationException>(() =>
            {
                EntityMethodSignature methodSignature = compilation.GetEntryPointSignature();
            });

            Assert.NotEmpty(ex.CompilationOutput);
        }
        public async void EntityInvoker_TestInvokeWithCompilationError(ScriptErrorType errorType)
        {
            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = ScriptTestDataHelper.GetInvalidCsxScript(errorType);

            using (EntityInvoker invoker = new EntityInvoker(metadata, ImmutableArray.Create <string>()))
            {
                ScriptCompilationException ex = await Assert.ThrowsAsync <ScriptCompilationException>(async() =>
                {
                    await invoker.InitializeEntryPointAsync();
                    int result = (int)await invoker.Invoke(new object[] { 3 });
                    Assert.Equal(9, result);
                });

                Assert.NotEmpty(ex.CompilationOutput);
            }
        }
        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);
            }
        }
Exemplo n.º 14
0
        public async Task E2E_Test_WAWSObserverAsync()
        {
            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            //read a sample csx file from local directory
            metadata.ScriptText = await File.ReadAllTextAsync("BackupCheckDetector.csx");

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config));

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

                var appResource = new App(string.Empty, string.Empty, "my-api")
                {
                    Stamp = new HostingEnvironment(string.Empty, string.Empty, "waws-prod-bn1-71717c45")
                };

                appResource.Stamp.TenantIdList = new List <string>()
                {
                    Guid.NewGuid().ToString()
                };

                var operationContext = new OperationContext <App>(appResource, null, null, true, null);

                var response = new Response();

                try
                {
                    Response result = (Response)await invoker.Invoke(new object[] { dataProviders, operationContext, response });
                }
                catch (ScriptCompilationException ex)
                {
                    foreach (var output in ex.CompilationOutput)
                    {
                        Trace.WriteLine(output);
                    }
                }
            }
        }
        public async void EntityInvoker_TestGistResourceAttributeResolution(ResourceType resType, Type filterType)
        {
            Definition definitonAttribute = new Definition()
            {
                Id = "TestId"
            };

            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata(EntityType.Gist);

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

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

                Assert.Equal(definitonAttribute, invoker.EntryPointDefinitionAttribute);
                Assert.Equal(filterType, invoker.ResourceFilter.GetType());
            }
        }
Exemplo n.º 16
0
        public async void DataProvders_TestKusto()
        {
            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = GetDataProviderScript("TestA");

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, Guid.NewGuid().ToString()));

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

                DataTable result = (DataTable)await invoker.Invoke(new object[] { dataProviders });

                Assert.NotNull(result);
            }
        }
        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_TestSystemFilterAttributeResolution()
        {
            Definition definitonAttribute = new Definition()
            {
                Id     = "TestId",
                Name   = "Test",
                Author = "User"
            };

            SystemFilter   filter   = new SystemFilter();
            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

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

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

                Assert.True(invoker.IsCompilationSuccessful);
                Assert.NotNull(invoker.SystemFilter);
                Assert.Equal(filter, invoker.SystemFilter);
            }
        }
Exemplo n.º 21
0
        public async void DataProvders_TestKusto()
        {
            var metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = @"
                public async static Task<DataTable> Run(DataProviders dataProviders) {
                    return await dataProviders.Kusto.ExecuteQuery(""TestA"", ""waws-prod-mockstamp"");
                }";

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, Guid.NewGuid().ToString()));

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

                var result = (DataTable)await invoker.Invoke(new object[] { dataProviders });

                Assert.NotNull(result);
            }
        }
Exemplo n.º 22
0
        public async void TestMdmGetTimeSeriesValuesAsync()
        {
            var metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = @"
                public async static Task<IEnumerable<DataTable>> Run(DataProviders dataProviders) {
                    var dimensions = new Dictionary<string, string> { { ""StampName"", ""kudu1"" } };
                    return await dataProviders.Mdm.GetTimeSeriesAsync(DateTime.UtcNow.AddMinutes(-10), DateTime.UtcNow, Sampling.Average | Sampling.Max | Sampling.Count, ""Microsoft/Web/WebApps"", ""CpuTime"", dimensions);
                }";

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, Guid.NewGuid().ToString()));

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

                var result = await invoker.Invoke(new object[] { dataProviders }) as IEnumerable <DataTable>;

                Assert.NotNull(result);
            }
        }
Exemplo n.º 23
0
        public async void TestMdmGetMetricNamesAsync()
        {
            var metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = @"
                public async static Task<IEnumerable<string>> Run(DataProviders dataProviders) {
                    return await dataProviders.Mdm.GetMetricNamesAsync(""Microsoft/Web/WebApps"");
                }";

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, Guid.NewGuid().ToString()));

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

                var result = await invoker.Invoke(new object[] { dataProviders }) as IEnumerable <string>;

                Assert.NotNull(result);
                Assert.True(result.Count() == 3);
            }
        }
        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));
            }
        }