Exemplo n.º 1
0
            public void WhenGivenExistingSiteMigrateData()
            {
                var newSiteOptions          = MockEnvironment.TableauSignInOptions("https://tableau-dev.traffk.com/#/site/TestMasterTenant").Object;
                var tableauAdminCredentials = ConfigurationHelpers.CreateOptions(TableauAdminCredentials);
                var httpClientOptions       = ConfigurationHelpers.CreateOptions(HttpClientOptions);
                var httpClientFactory       = new HttpClientFactory(httpClientOptions);

                var testAdminService =
                    new TableauAdminService(newSiteOptions, tableauAdminCredentials, httpClientFactory, Logger) as ITableauAdminService;

                var    dbUserName           = "******";
                var    dbPassword           = "******";
                var    testNewServerAddress = "traffkrdb-dev.database.windows.net/";
                var    testDbName           = "TraffkHip2";
                string path = Path.GetTempPath();

                path = path + @"TableauIntegrationTestFiles";

                var dataMigrationRequest = new TableauDataMigrationRequest("ExistingTestTenant", testNewServerAddress, testDbName, dbUserName, dbPassword, path);

                testAdminService.MigrateDataset(dataMigrationRequest);

                DirectoryInfo di = new DirectoryInfo(path);

                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in di.GetDirectories())
                {
                    dir.Delete(true);
                }
            }
Exemplo n.º 2
0
        public TypeCheckerTest()
        {
            var currentDirectory = Directory.GetParent(Directory.GetCurrentDirectory());
            var config           = new Dictionary <string, object>
            {
                {
                    ConfigurationManager.MetadataDirKey,
                    Path.Combine(currentDirectory.Parent?.Parent?.ToString(), "Resources")
                }
            };

            var configurationProvider = new MockConfigurationProvider(config);

            var environment = new MockEnvironment();

            var fileMetadataAccessor = new FileMetadataAccessor();

            fileMetadataAccessor.SetMetadataPath((string)config[ConfigurationManager.MetadataDirKey]);

            var cache = new MockCache();

            var configurationManager = new ConfigurationManager(configurationProvider, environment, cache);

            _metadataProvider = configurationManager.NewMetadataProvider();
        }
Exemplo n.º 3
0
        public async Task SearchOverrideCache_FailsWhenFileDoesntExist()
        {
            string searchFilePath = "do-not-exist";
            var    environment    = new MockEnvironment();

            environment.SetEnvironmentVariable("DOTNET_NEW_SEARCH_FILE_OVERRIDE", searchFilePath);

            IEngineEnvironmentSettings engineEnvironmentSettings = _environmentSettingsHelper.CreateEnvironment(hostIdentifier: this.GetType().Name, virtualize: true, environment: environment);

            engineEnvironmentSettings.Components.AddComponent(typeof(ITemplateSearchProviderFactory), new NuGetMetadataSearchProviderFactory());

            const string templateName = "foo";

            Func <TemplatePackageSearchData, IReadOnlyList <ITemplateInfo> > filter =
                templatePack => templatePack.Templates
                .Where(t => ((ITemplateInfo)t).Name.Contains(templateName, StringComparison.OrdinalIgnoreCase))
                .ToList();

            var searchCoordinator = new TemplateSearchCoordinator(engineEnvironmentSettings);
            var searchResult      = await searchCoordinator.SearchAsync(p => true, filter, default).ConfigureAwait(false);

            Assert.NotNull(searchResult);
            Assert.Equal(1, searchResult.Count);
            Assert.False(searchResult[0].Success);
            Assert.False(string.IsNullOrWhiteSpace(searchResult[0].ErrorMessage));
            Assert.True(searchResult[0].SearchHits.Count == 0);
            Assert.Equal("Local search cache 'do-not-exist' does not exist.", searchResult[0].ErrorMessage);

            //provider should not copy local file to settings
            Assert.False(engineEnvironmentSettings.Host.FileSystem.FileExists(Path.Combine(engineEnvironmentSettings.Paths.HostVersionSettingsDir, "nugetTemplateSearchInfo.json")));
        }
Exemplo n.º 4
0
        public async Task SearchReturnsErrorOnIncorrectVersionCache()
        {
            var    jsonObject     = JObject.FromObject(new { version = "3.0", TemplatePackages = Array.Empty <string>() });
            string searchFilePath = Path.Combine(TestUtils.CreateTemporaryFolder(), "searchCache.json");

            File.WriteAllText(searchFilePath, jsonObject.ToString());

            var environment = new MockEnvironment();

            environment.SetEnvironmentVariable("DOTNET_NEW_SEARCH_FILE_OVERRIDE", searchFilePath);

            IEngineEnvironmentSettings engineEnvironmentSettings = _environmentSettingsHelper.CreateEnvironment(hostIdentifier: this.GetType().Name, virtualize: true, environment: environment);

            engineEnvironmentSettings.Components.AddComponent(typeof(ITemplateSearchProviderFactory), new NuGetMetadataSearchProviderFactory());

            const string templateName = "foo";

            Func <TemplatePackageSearchData, IReadOnlyList <ITemplateInfo> > filter =
                templatePack => templatePack.Templates
                .Where(t => ((ITemplateInfo)t).Name.Contains(templateName, StringComparison.OrdinalIgnoreCase))
                .ToList();

            var searchCoordinator = new TemplateSearchCoordinator(engineEnvironmentSettings);
            var searchResult      = await searchCoordinator.SearchAsync(p => true, filter, default).ConfigureAwait(false);

            Assert.NotNull(searchResult);
            Assert.Equal(1, searchResult.Count);
            Assert.False(searchResult[0].Success);
            Assert.False(string.IsNullOrWhiteSpace(searchResult[0].ErrorMessage));
            Assert.True(searchResult[0].SearchHits.Count == 0);
            Assert.Equal("The template search cache data is not supported.", searchResult[0].ErrorMessage);

            //provider should not copy local file to settings
            Assert.False(engineEnvironmentSettings.Host.FileSystem.FileExists(Path.Combine(engineEnvironmentSettings.Paths.HostVersionSettingsDir, "nugetTemplateSearchInfo.json")));
        }
Exemplo n.º 5
0
        public async Task SearchLocalCache()
        {
            var environment = new MockEnvironment();

            environment.SetEnvironmentVariable("DOTNET_NEW_LOCAL_SEARCH_FILE_ONLY", "true");

            IEngineEnvironmentSettings engineEnvironmentSettings = _environmentSettingsHelper.CreateEnvironment(hostIdentifier: this.GetType().Name, virtualize: true, environment: environment);

            engineEnvironmentSettings.Components.AddComponent(typeof(ITemplateSearchProviderFactory), new NuGetMetadataSearchProviderFactory());

            const string templateName = "api";

            Func <TemplatePackageSearchData, IReadOnlyList <ITemplateInfo> > filter =
                templatePack => templatePack.Templates
                .Where(t => ((ITemplateInfo)t).Name.Contains(templateName, StringComparison.OrdinalIgnoreCase))
                .ToList();

            var searchCoordinator = new TemplateSearchCoordinator(engineEnvironmentSettings);
            Func <Task <IReadOnlyList <SearchResult> > > search = async() =>
            {
                var result = await searchCoordinator.SearchAsync(p => true, filter, default).ConfigureAwait(false);

                if (result != null && result.Count > 0 && !string.IsNullOrWhiteSpace(result[0].ErrorMessage))
                {
                    var errorMessage = result[0].ErrorMessage;
                    if (errorMessage !.Contains("The SSL connection could not be established"))
                    {
                        throw new HttpRequestException(errorMessage);
                    }
                }
                return(result !);
            };
            var searchResult = await TestUtils.AttemptSearch <IReadOnlyList <SearchResult>, HttpRequestException>(3, TimeSpan.FromSeconds(10), search);

            Assert.NotNull(searchResult);
            Assert.Equal(1, searchResult.Count);
            Assert.False(searchResult[0].Success);
            Assert.False(string.IsNullOrWhiteSpace(searchResult[0].ErrorMessage));
            Assert.True(searchResult[0].SearchHits.Count == 0);
            Assert.Equal($"Local search cache '{Path.Combine(engineEnvironmentSettings.Paths.HostVersionSettingsDir, "nugetTemplateSearchInfo.json")}' does not exist.", searchResult[0].ErrorMessage);

            environment.SetEnvironmentVariable("DOTNET_NEW_LOCAL_SEARCH_FILE_ONLY", null);
            searchResult = await TestUtils.AttemptSearch <IReadOnlyList <SearchResult>, HttpRequestException>(3, TimeSpan.FromSeconds(10), search);

            Assert.NotNull(searchResult);
            Assert.Equal(1, searchResult.Count);
            Assert.True(searchResult[0].Success);
            Assert.True(string.IsNullOrWhiteSpace(searchResult[0].ErrorMessage));
            Assert.True(searchResult[0].SearchHits.Count > 0);

            environment.SetEnvironmentVariable("DOTNET_NEW_LOCAL_SEARCH_FILE_ONLY", "true");
            searchResult = await TestUtils.AttemptSearch <IReadOnlyList <SearchResult>, HttpRequestException>(3, TimeSpan.FromSeconds(10), search);

            Assert.NotNull(searchResult);
            Assert.Equal(1, searchResult.Count);
            Assert.True(searchResult[0].Success);
            Assert.True(string.IsNullOrWhiteSpace(searchResult[0].ErrorMessage));
            Assert.True(searchResult[0].SearchHits.Count > 0);
        }
Exemplo n.º 6
0
            public void WhenGivenUserWithNoPermissionThrowException()
            {
                TestClient.DefaultRequestHeaders.Remove("Authorization");

                var accessToken = MockEnvironment.GetBearerToken(TestClient, @"*****@*****.**", "", true);

                TestClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", $"Bearer {accessToken}");

                Assert.ThrowsException <InvalidOperationException>(() => TestClient.GetAsync("/api/v1/Plans").ExecuteSynchronously());
            }
Exemplo n.º 7
0
        public TableauRestServiceTests()
        {
            Options             = MockEnvironment.TableauSignInOptions().Object;
            TableauTenantFinder = MockEnvironment.TableauTenantFinder().Object;
            var tableauAdminCredentials = MockEnvironment.TableauAdminCredentials().Object;

            TableauAdminCredentials = new TableauAdminCredentials
            {
                Username = tableauAdminCredentials.UserName,
                Password = tableauAdminCredentials.Password
            };
            TableauUserCredentials = MockEnvironment.TableauUserCredentials().Object;
            Logger = MockEnvironment.CreateTestLogger();
        }
Exemplo n.º 8
0
        public void TestValidateAndGetImageWithEnvVariableInHostAddress(string image, string result, Type expectedException, string variableName, string value)
        {
            MockEnvironment mock_env = new MockEnvironment();

            mock_env.SetVariable(variableName, value);

            if (expectedException != null)
            {
                Assert.Throws(expectedException, () => DockerConfig.ValidateAndGetImage(image, mock_env));
            }
            else
            {
                string updatedImage = DockerConfig.ValidateAndGetImage(image, mock_env);
                Assert.Equal(result, updatedImage);
            }
        }
        public static ConfigurationManager BuildAs(bool isProd)
        {
            var currentDirectory = Directory.GetParent(Directory.GetCurrentDirectory());
            var config           = new Dictionary <string, object>
            {
                {
                    ConfigurationManager.MetadataDirKey,
                    Path.Combine(currentDirectory.Parent?.Parent?.ToString(), "Resources", "provider_metadatas")
                }
            };

            var configurationProvider = new MockConfigurationProvider(config);

            var environment = new MockEnvironment(isProd);

            var fileMetadataAccessor = new FileMetadataAccessor();

            fileMetadataAccessor.SetMetadataPath((string)config[ConfigurationManager.MetadataDirKey]);

            var cache = new MockProdCache(fileMetadataAccessor);

            return(new ConfigurationManager(configurationProvider, environment, cache));
        }
Exemplo n.º 10
0
        private static NSerializer GetSerializerAs(FieldFormatterType type, FieldAccessType accessType,
                                                   DateFormatType dateFormatType, bool withNulls)
        {
            var currentDirectory = Directory.GetParent(Directory.GetCurrentDirectory());
            var config           = new Dictionary <string, object>
            {
                { ConfigurationManager.MetadataDirKey, Path.Combine(currentDirectory.Parent?.Parent?.ToString(), "Resources") },
                { ConfigurationManager.IncludeNullValuesKey, withNulls },
                { ConfigurationManager.FieldFormattingMethodKey, type.ToString() },
                { ConfigurationManager.FieldAccessTypeKey, accessType.ToString() },
                { ConfigurationManager.DateFormatKey, dateFormatType.ToString() }
            };

            var configurationProvider = new MockConfigurationProvider(config);
            var environment           = new MockEnvironment();
            var cache = new MockCache();

            return(NSerializerBuilder.Build()
                   .WithCache(cache)
                   .WithConfigurationProvider(configurationProvider)
                   .WithEnvironment(environment)
                   .Get());
        }
Exemplo n.º 11
0
 public void WhenGivenNullDbContextThrowException()
 {
     Assert.ThrowsException <ArgumentNullException>(() => new HomeController(null, null, MockEnvironment.CreateTestLogger()));
 }
Exemplo n.º 12
0
 public override void Context()
 {
     base.Context();
     MockEnvironment.Setup(e => e.OSVersion).Returns(new OperatingSystem(PlatformID.MacOSX, new Version(2, 1, 0, 0)));
 }
Exemplo n.º 13
0
 public override void Context()
 {
     base.Context();
     MockEnvironment.Setup(e => e.OSVersion).Returns(new OperatingSystem(PlatformID.Unix, new Version(2, 1, 0, 0)));
     MockFileSystem.Setup(f => f.directory_exists(It.IsAny <string>())).Returns(true);
 }