public void RuleSet_FileChangingOnDiskRefreshes() { string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0""> <IncludeAll Action=""Error"" /> </RuleSet> "; using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { File.WriteAllText(ruleSetFile.Path, ruleSetSource); var project = CSharpHelpers.CreateCSharpProject(environment, "Test"); ((IAnalyzerHost)project).SetRuleSetFile(ruleSetFile.Path); var options = (CSharpCompilationOptions)environment.GetUpdatedCompilationOptionOfSingleProject(); // Assert the value exists now Assert.Equal(expected: ReportDiagnostic.Error, actual: options.GeneralDiagnosticOption); // Modify the file and raise a mock file change File.WriteAllText(ruleSetFile.Path, ruleSetSource.Replace("Error", "Warning")); environment.RaiseFileChange(ruleSetFile.Path); var listenerProvider = environment.ExportProvider.GetExportedValue <AsynchronousOperationListenerProvider>(); var waiter = listenerProvider.GetWaiter(FeatureAttribute.RuleSetEditor); waiter.CreateWaitTask().JoinUsingDispatcher(CancellationToken.None); options = (CSharpCompilationOptions)environment.GetUpdatedCompilationOptionOfSingleProject(); Assert.Equal(expected: ReportDiagnostic.Warn, actual: options.GeneralDiagnosticOption); } }
public void RuleSet_ProjectSettingsOverrideSpecificOptions() { string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0""> <IncludeAll Action=""Warning"" /> <Rules AnalyzerId=""Microsoft.Analyzers.ManagedCodeAnalysis"" RuleNamespace=""Microsoft.Rules.Managed""> <Rule Id=""CS1014"" Action=""None"" /> </Rules> </RuleSet> "; using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { File.WriteAllText(ruleSetFile.Path, ruleSetSource); var project = CSharpHelpers.CreateCSharpProject(environment, "Test"); ((IAnalyzerHost)project).SetRuleSetFile(ruleSetFile.Path); project.SetOption(CompilerOptions.OPTID_WARNASERRORLIST, "1014"); var options = (CSharpCompilationOptions)environment.GetUpdatedCompilationOptionOfSingleProject(); var ca1014DiagnosticOption = options.SpecificDiagnosticOptions["CS1014"]; Assert.Equal(expected: ReportDiagnostic.Error, actual: ca1014DiagnosticOption); } }
public void RuleSet_GeneralOption() { string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0""> <IncludeAll Action=""Error"" /> </RuleSet> "; using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { File.WriteAllText(ruleSetFile.Path, ruleSetSource); var project = CSharpHelpers.CreateCSharpProject(environment, "Test"); var options = (CSharpCompilationOptions)environment.GetUpdatedCompilationOptionOfSingleProject(); Assert.Equal(expected: ReportDiagnostic.Default, actual: options.GeneralDiagnosticOption); ((IAnalyzerHost)project).SetRuleSetFile(ruleSetFile.Path); options = (CSharpCompilationOptions)environment.GetUpdatedCompilationOptionOfSingleProject(); Assert.Equal(expected: ReportDiagnostic.Error, actual: options.GeneralDiagnosticOption); } }
public void RuleSet_SpecificOptions() { string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0""> <IncludeAll Action=""Warning"" /> <Rules AnalyzerId=""Microsoft.Analyzers.ManagedCodeAnalysis"" RuleNamespace=""Microsoft.Rules.Managed""> <Rule Id=""CA1012"" Action=""Error"" /> </Rules> </RuleSet> "; using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { File.WriteAllText(ruleSetFile.Path, ruleSetSource); var project = CSharpHelpers.CreateCSharpProject(environment, "Test"); project.SetRuleSetFile(ruleSetFile.Path); var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single(); var options = (CSharpCompilationOptions)workspaceProject.CompilationOptions; var ca1012DiagnosticOption = options.SpecificDiagnosticOptions["CA1012"]; Assert.Equal(expected: ReportDiagnostic.Error, actual: ca1012DiagnosticOption); } }
public void RuleSet_ProjectSettingOverridesGeneralOption() { string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0""> <IncludeAll Action=""Warning"" /> </RuleSet> "; using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { File.WriteAllText(ruleSetFile.Path, ruleSetSource); var project = CSharpHelpers.CreateCSharpProject(environment, "Test"); project.SetRuleSetFile(ruleSetFile.Path); var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single(); var options = (CSharpCompilationOptions)workspaceProject.CompilationOptions; Assert.Equal(expected: ReportDiagnostic.Warn, actual: options.GeneralDiagnosticOption); project.SetOptionWithMarshaledValue(CompilerOptions.OPTID_WARNINGSAREERRORS, true); workspaceProject = environment.Workspace.CurrentSolution.Projects.Single(); options = (CSharpCompilationOptions)workspaceProject.CompilationOptions; Assert.Equal(expected: ReportDiagnostic.Error, actual: options.GeneralDiagnosticOption); } }
public void RuleSet_ProjectNoWarnOverridesOtherSettings() { string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0""> <IncludeAll Action=""Warning"" /> <Rules AnalyzerId=""Microsoft.Analyzers.ManagedCodeAnalysis"" RuleNamespace=""Microsoft.Rules.Managed""> <Rule Id=""CS1014"" Action=""Info"" /> </Rules> </RuleSet> "; using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { File.WriteAllText(ruleSetFile.Path, ruleSetSource); var project = CSharpHelpers.CreateCSharpProject(environment, "Test"); project.SetRuleSetFile(ruleSetFile.Path); project.SetOptionWithMarshaledValue(CompilerOptions.OPTID_NOWARNLIST, "1014"); project.SetOptionWithMarshaledValue(CompilerOptions.OPTID_WARNASERRORLIST, "1014"); var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single(); var options = (CSharpCompilationOptions)workspaceProject.CompilationOptions; var ca1014DiagnosticOption = options.SpecificDiagnosticOptions["CS1014"]; Assert.Equal(expected: ReportDiagnostic.Suppress, actual: ca1014DiagnosticOption); } }
public void CreateBlankScript_file_should_contain_template_tags_in_correct_order() { // arrange _configManager.AppSettings[AppSettingKeys.VersionStrategy] = VersionStrategyFactory.UtcTime; const string migrationName = "my first script"; const string setupStartTag = "BEGIN_SETUP:"; const string setupEndTag = "END_SETUP:"; const string teardownStartTag = "BEGIN_TEARDOWN:"; const string teardownEndTag = "END_TEARDOWN:"; // act string path = _subject.CreateBlankScript(migrationName); using (DisposableFile file = DisposableFile.Watch(path)) { // assert string contents = File.ReadAllText(file.FullName); int index1 = contents.IndexOf(setupStartTag, StringComparison.Ordinal); int index2 = contents.IndexOf(setupEndTag, StringComparison.Ordinal); int index3 = contents.IndexOf(teardownStartTag, StringComparison.Ordinal); int index4 = contents.IndexOf(teardownEndTag, StringComparison.Ordinal); Assert.IsTrue(index1 != -1 && index1 < index2); Assert.IsTrue(index2 != -1 && index2 < index3); Assert.IsTrue(index3 != -1 && index3 < index4); Assert.IsTrue(index4 != -1); } }
public void RuleSet_SpecificOptions_CPS() { string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0""> <IncludeAll Action=""Warning"" /> <Rules AnalyzerId=""Microsoft.Analyzers.ManagedCodeAnalysis"" RuleNamespace=""Microsoft.Rules.Managed""> <Rule Id=""CA1012"" Action=""Error"" /> </Rules> </RuleSet> "; using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { File.WriteAllText(ruleSetFile.Path, ruleSetSource); var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test"); project.SetRuleSetFile(ruleSetFile.Path); CSharpHelpers.SetCommandLineArguments(project, commandLineArguments: $"/ruleset:{ruleSetFile.Path}"); var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single(); var options = (CSharpCompilationOptions)workspaceProject.CompilationOptions; var ca1012DiagnosticOption = options.SpecificDiagnosticOptions["CA1012"]; Assert.Equal(expected: ReportDiagnostic.Error, actual: ca1012DiagnosticOption); } }
public void RuleSet_GeneralOption_CPS() { string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0""> <IncludeAll Action=""Error"" /> </RuleSet> "; using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { File.WriteAllText(ruleSetFile.Path, ruleSetSource); var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test"); var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single(); var options = (CSharpCompilationOptions)workspaceProject.CompilationOptions; Assert.Equal(expected: ReportDiagnostic.Default, actual: options.GeneralDiagnosticOption); project.SetRuleSetFile(ruleSetFile.Path); CSharpHelpers.SetCommandLineArguments(project, commandLineArguments: $"/ruleset:{ruleSetFile.Path}"); workspaceProject = environment.Workspace.CurrentSolution.Projects.Single(); options = (CSharpCompilationOptions)workspaceProject.CompilationOptions; Assert.Equal(expected: ReportDiagnostic.Error, actual: options.GeneralDiagnosticOption); } }
internal async Task ExecuteAsync(string consoleParameter, DisposableFile jsonFile, string zipName) { var result = await dotNetTool.RunAsync(dotnetToolBuilderSettings.BaseCommand, $"-ff {jsonFile.FileInfo.FullName} {consoleParameter} -az {zipName}").ConfigureAwait(false); if (result.ExitCode != 0) { throw new ProblemDetailsException(StatusCodes.Status500InternalServerError, "Dotnet Toolbuilder failed", $"Exitcode {result.ExitCode}"); } }
public void CanSaveAndLoadTrainingSet() { using (var file = new DisposableFile()) { var set = GetTrainingSet(); var loaded = file.WriteAndReadData(set, LinearDataSet <float> .Load); CheckTestSetsEqual(loaded, set); } }
public async Task ExceptionOnDisposeThenClose() { using var dbInfo = DisposableFile.GenerateInTemp("db"); await using var duckDBConnection = new DuckDBConnection(dbInfo.ConnectionString); await duckDBConnection.OpenAsync(); await duckDBConnection.DisposeAsync(); await duckDBConnection.CloseAsync(); }
public void RuleSet_CanBeFetchedFromWorkspace() { using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { var project = CSharpHelpers.CreateCSharpProject(environment, "Test"); ((IAnalyzerHost)project).SetRuleSetFile(ruleSetFile.Path); var projectId = environment.Workspace.CurrentSolution.ProjectIds.Single(); Assert.Equal(ruleSetFile.Path, environment.Workspace.TryGetRuleSetPathForProject(projectId)); } }
public void CanSaveAndLoadMatrix() { var matrix = MatrixFactory.ParseString <T>(@"1.0 2.0 3.0 4.0 5.0 6.0"); matrix.ShouldHaveSize(2, 3); using (var file = new DisposableFile()) { var read = file.WriteAndReadData(stream => matrix.Save(stream), MatrixFactory.Load <T>); read.AsColumnMajorArray().ShouldArrayEqualWithinError(MathProvider.Array(1.0f, 4.0f, 2.0f, 5.0f, 3.0f, 6.0f)); } }
public void CreateBlankScript_should_create_file() { // arrange _configManager.AppSettings[AppSettingKeys.VersionStrategy] = VersionStrategyFactory.UtcTime; const string migrationName = "my first script"; // act string path = _subject.CreateBlankScript(migrationName); using (DisposableFile.Watch(path)) { // assert Assert.IsTrue(File.Exists(path)); } }
public void SetRuleSetFile_RemoveExtraBackslashes() { using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { var project = CSharpHelpers.CreateCSharpProject(environment, "Test"); var pathWithExtraBackslashes = ruleSetFile.Path.Replace(@"\", @"\\"); project.SetRuleSetFile(pathWithExtraBackslashes); var projectRuleSetFile = project.RuleSetFile; Assert.Equal(expected: ruleSetFile.Path, actual: projectRuleSetFile.FilePath); } }
public void SetRuleSetFile_RemoveExtraBackslashes() { using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { var project = CSharpHelpers.CreateCSharpProject(environment, "Test"); var pathWithExtraBackslashes = ruleSetFile.Path.Replace(@"\", @"\\"); ((IAnalyzerHost)project).SetRuleSetFile(pathWithExtraBackslashes); var projectRuleSetFile = project.VisualStudioProjectOptionsProcessor.ExplicitRuleSetFilePath; Assert.Equal(expected: ruleSetFile.Path, actual: projectRuleSetFile); } }
internal static MetadataReference CreateReflectionEmitAssembly(Action <ModuleBuilder> create) { using (var file = new DisposableFile(extension: ".dll")) { var name = Path.GetFileName(file.Path); var appDomain = AppDomain.CurrentDomain; var assembly = appDomain.DefineDynamicAssembly(new AssemblyName(name), AssemblyBuilderAccess.Save, Path.GetDirectoryName(file.Path)); var module = assembly.DefineDynamicModule(CommonTestBase.GetUniqueName(), name); create(module); assembly.Save(name); var image = CommonTestBase.ReadFromFile(file.Path); return(MetadataReference.CreateFromImage(image)); } }
public void GeraDanfe() { using (var file = new DisposableFile(".pdf")) using (var stream = new FileStream(file.Path, FileMode.Create)) using (var danfe = new Danfe()) { var nfeProc = MockData.NFeProcessada.Value; danfe.Pdf(stream, nfeProc.NFe, nfeProc.protNFe, "cscId", "cscToken"); stream.Close(); Process.Start(file.Path); //time to load temp file Thread.Sleep(3000); } }
public Task <PutResult> PutFileAsync( Context context, ContentHash contentHash, DisposableFile disposableFile, CancellationToken cts) { return(PutFileAsync(context, contentHash, disposableFile.Path, FileRealizationMode.Copy, cts, UrgencyHint.Low).ContinueWith(p => { disposableFile.Dispose(); if (p.Result.Succeeded) { PushContentToRemoteLocations(context, p.Result, cts); } return p.Result; })); }
public static void TestReferenceResolutionWithMissingTargets(bool isProjectJsonBased, string errorResourceName) { using (var tempRoot = new TempRoot()) using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path)) { var exception = Assert.Throws <ExceptionFromResource>(() => NuGetTestHelpers.ResolvePackagesWithJsonFileContents( Encoding.UTF8.GetString(Json.Json.WithoutTargets_assets, 0, Json.Json.WithoutTargets_assets.Length), targetMoniker: "MissingFrameworkMoniker,Version=v42.0", runtimeIdentifier: "", allowFallbackOnTargetSelection: true, isLockFileProjectJsonBased: isProjectJsonBased)); Assert.Equal(errorResourceName, exception.ResourceName); } }
public void Read_should_preserve_whitespace_in_scripts() { // arrange var tempFilePath = Path.GetTempFileName(); using (DisposableFile.Watch(tempFilePath)) { File.WriteAllText(tempFilePath, @" BEGIN_SETUP: this is the setup END_SETUP: BEGIN_TEARDOWN: one two three four END_TEARDOWN: "); var file = new MigrationScriptFile(tempFilePath); // act var contents = file.Read(); // we are normalizing \r\n to just \n because for some reason // some \r\n's are returned as just \n from the regex matching // assert Assert.AreEqual(@" this is the setup ".Replace("\r\n", "\n"), contents.Setup.Replace("\r\n", "\n"), "setup not parsed correctly"); Assert.AreEqual(@" one two three four ".Replace("\r\n", "\n"), contents.Teardown.Replace("\r\n", "\n"), "teardown should be empty"); } }
public static void TestReferenceResolutionWithAliases() { using (var tempRoot = new TempRoot()) using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path)) { var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents( Encoding.UTF8.GetString(Json.Json.WithTargets_assets, 0, Json.Json.WithTargets_assets.Length), targetMoniker: ".NETFramework,Version=v4.5", runtimeIdentifier: "", allowFallbackOnTargetSelection: true, isLockFileProjectJsonBased: false); // We should still have references. Since we have no runtime ID, we should have no copy local items AssertHelpers.AssertCountOf(1, result.References); Assert.Equal("Core", result.References.Single().GetMetadata("Aliases")); } }
public static void TestReferenceResolutionWithMissingTargetFrameworkAndNoFallbackInProjectCsproj() { using (var tempRoot = new TempRoot()) using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path)) { var exception = Assert.Throws <ExceptionFromResource>(() => NuGetTestHelpers.ResolvePackagesWithJsonFileContents( Encoding.UTF8.GetString(Json.Json.WithoutTargets_assets, 0, Json.Json.WithoutTargets_assets.Length), targetMoniker: "Missing,Version=1.0", runtimeIdentifier: "missing-runtime-identifier", allowFallbackOnTargetSelection: false, isLockFileProjectJsonBased: false)); Assert.Equal(nameof(Strings.MissingFrameworkInProjectFile), exception.ResourceName); Assert.Equal(new[] { "Missing,Version=1.0" }, exception.MessageArgs); } }
public static void TestReferenceResolutionWithMissingTargetFrameworkAndFallbackInProjectCsproj() { using (var tempRoot = new TempRoot()) using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path)) { var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents( Encoding.UTF8.GetString(Json.Json.WithTargets_assets, 0, Json.Json.WithTargets_assets.Length), targetMoniker: "MissingFrameworkMoniker,Version=v42.0", runtimeIdentifier: "", allowFallbackOnTargetSelection: true, isLockFileProjectJsonBased: false); // We should still have references. Since we have no runtime ID, we should have no copy local items AssertHelpers.AssertCountOf(1, result.References); AssertHelpers.AssertCountOf(0, result.CopyLocalItems); } }
public void Push_And_Pull() { SnapshotRepository repo = new DirectorySnapshotRepository(this.TestFolder); string testContent = "Hello 123456 0815 4711"; string testkey = "xxyy"; using (DisposableFile sourceFile = DisposableFile.GetTempFile()) { using (DisposableFile destFile = DisposableFile.GetTempFile()) { System.IO.File.WriteAllText(sourceFile.Path, testContent); repo.Push(testkey, sourceFile.Path); Assert.True(repo.TryPull(testkey, destFile.Path)); Assert.Equal(testContent, File.ReadAllText(destFile.Path)); } } }
public TStats WriteToDirectory(IEnumerable <TRecord> records, string directory) { using (var tempFile = new DisposableFile()) { var stats = this.Write(records, tempFile.Path); var destination = Path.Combine(directory, this.GetFilenameFromStats(stats)); if (File.Exists(destination)) { File.Delete(destination); } File.Move(tempFile.Path, destination); return(stats); } }
/// <summary> /// Loads the supplied spreadsheet file and returns its contents as a dataset. /// </summary> /// <param name="settingsFilePath">Excel spreadsheet file to load.</param> /// <returns>Dataset containing the spreadsheet contents, with a seperate datatable for each worksheet.</returns> /// <exception cref="NotSupportedException">Thrown if the file extension of the spreadsheet is not .xls or .xlsx.</exception> /// <exception cref="ArgumentNullException">Thrown if the supplied settings file path string is null.</exception> /// <exception cref="ArgumentException">Thown if the supplied settings file path string is zero length.</exception> public virtual DataSet GetSettingsDataSet(string settingsFilePath) { if (settingsFilePath == null) { throw new ArgumentNullException(nameof(settingsFilePath)); } if (settingsFilePath.Length == 0) { throw new ArgumentException("The supplied settings file path string cannot be zero length"); } var settingsFile = new FileInfo(settingsFilePath); if (!settingsFile.Exists) { throw new FileNotFoundException("The specified settings file path was not found: " + settingsFile.FullName, settingsFile.FullName); } var tempCopyPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + "." + settingsFile.Name); using (var tempCopyOfSettingsFile = new DisposableFile(settingsFile.CopyTo(tempCopyPath))) { var tempCopyFileInfo = new FileInfo(tempCopyOfSettingsFile.FullName); tempCopyFileInfo.Attributes &= ~FileAttributes.ReadOnly; using (var settingsFileStream = tempCopyFileInfo.OpenRead()) { if (!string.IsNullOrEmpty(tempCopyFileInfo.Extension)) { if (settingsFile.Extension.Equals(".xls", StringComparison.OrdinalIgnoreCase)) { return(ExcelReaderFactory.CreateBinaryReader(settingsFileStream).AsDataSet()); } if (settingsFile.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)) { return(ExcelReaderFactory.CreateOpenXmlReader(settingsFileStream).AsDataSet()); } } throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "The file extension '{0}' is not supported by the ExcelFileLoader", settingsFile.Extension)); } } }
public void CreateBlankScript_file_name_should_include_migration_name_with_whitespace_trimmed() { // arrange _configManager.AppSettings[AppSettingKeys.VersionStrategy] = VersionStrategyFactory.UtcTime; const string migrationName = " my first script "; // act string path = _subject.CreateBlankScript(migrationName); using (DisposableFile file = DisposableFile.Watch(path)) { // assert string nameMinusVersion = file.NameWithoutExtension.Substring(file.NameWithoutExtension.IndexOf('_') + 1); const string expectedName = "my_first_script"; Assert.AreEqual(expectedName, nameMinusVersion); } }
public void Read_should_assume_entire_script_is_the_setup_if_no_tags_are_present() { // arrange var tempFilePath = Path.GetTempFileName(); using (DisposableFile.Watch(tempFilePath)) { File.WriteAllText(tempFilePath, "this is the setup"); var file = new MigrationScriptFile(tempFilePath); // act var contents = file.Read(); // assert Assert.AreEqual("this is the setup", contents.Setup, "setup not parsed correctly"); Assert.AreEqual(string.Empty, contents.Teardown, "teardown should be empty"); } }
CreateBlankScript_file_name_should_include_migration_name_with_whitespace_replaced_with_an_underscore() { // arrange _configManager.AppSettings[AppSettingKeys.VersionStrategy] = VersionStrategyFactory.UtcTime; const string migrationName = "my first script"; // act string path = _subject.CreateBlankScript(new DotNetMigrations.Commands.GenerateScriptCommandArgs() { MigrationName = migrationName }); using (DisposableFile file = DisposableFile.Watch(path)) { // assert string nameMinusVersion = file.NameWithoutExtension.Substring(file.NameWithoutExtension.IndexOf('_') + 1); const string expectedName = "my_first_script"; Assert.AreEqual(expectedName, nameMinusVersion); } }
public void Read_should_parse_file_contents_correctly() { // arrange var tempFilePath = Path.GetTempFileName(); using (DisposableFile.Watch(tempFilePath)) { var file = new MigrationScriptFile(tempFilePath); const string setupText = "my setup text"; const string teardownText = "my teardown text"; file.Write(new MigrationScriptContents(setupText, teardownText)); // act var contents = file.Read(); // assert Assert.AreEqual(setupText, contents.Setup.Trim(), "setup does not match"); Assert.AreEqual(teardownText, contents.Teardown.Trim(), "teardown does not match"); } }
public void RuleSet_ProjectSettingsOverrideSpecificOptionsAndRestore() { string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0""> <IncludeAll Action=""Warning"" /> <Rules AnalyzerId=""Microsoft.Analyzers.ManagedCodeAnalysis"" RuleNamespace=""Microsoft.Rules.Managed""> <Rule Id=""CS1014"" Action=""None"" /> </Rules> </RuleSet> "; using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) { File.WriteAllText(ruleSetFile.Path, ruleSetSource); var project = CSharpHelpers.CreateCSharpProject(environment, "Test"); project.SetRuleSetFile(ruleSetFile.Path); project.SetOptionWithMarshaledValue(CompilerOptions.OPTID_WARNASERRORLIST, "1014"); var options = environment.GetUpdatedCompilationOptionOfSingleProject(); Assert.Equal(expected: ReportDiagnostic.Error, actual: options.SpecificDiagnosticOptions["CS1014"]); project.SetOptionWithMarshaledValue(CompilerOptions.OPTID_WARNNOTASERRORLIST, "1014"); options = environment.GetUpdatedCompilationOptionOfSingleProject(); Assert.Equal(expected: ReportDiagnostic.Suppress, actual: options.SpecificDiagnosticOptions["CS1014"]); project.SetOptionWithMarshaledValue(CompilerOptions.OPTID_WARNNOTASERRORLIST, null); options = environment.GetUpdatedCompilationOptionOfSingleProject(); Assert.Equal(expected: ReportDiagnostic.Error, actual: options.SpecificDiagnosticOptions["CS1014"]); project.SetOptionWithMarshaledValue(CompilerOptions.OPTID_WARNASERRORLIST, null); options = environment.GetUpdatedCompilationOptionOfSingleProject(); Assert.Equal(expected: ReportDiagnostic.Suppress, actual: options.SpecificDiagnosticOptions["CS1014"]); } }