|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using Microsoft.EntityFrameworkCore.Tools.Commands; |
| 5 | + |
| 6 | +namespace Microsoft.EntityFrameworkCore.Tools; |
| 7 | + |
| 8 | +public class OutputPathTest |
| 9 | +{ |
| 10 | + private static readonly string Root = Path.GetFullPath(Path.Combine(Path.GetTempPath(), "efroot")); |
| 11 | + |
| 12 | + [Fact] |
| 13 | + public void Relative_output_is_resolved_from_the_working_directory() |
| 14 | + => Assert.Equal( |
| 15 | + Path.Combine(Root, "src", "Startup", "Scripts", "Idempotent.sql"), |
| 16 | + ProjectCommandBase.ResolveOutputPath(Path.Combine("Scripts", "Idempotent.sql"), Path.Combine(Root, "src", "Startup"))); |
| 17 | + |
| 18 | + [Fact] |
| 19 | + public void Absolute_output_ignores_the_working_directory() |
| 20 | + { |
| 21 | + var output = Path.Combine(Root, "out", "script.sql"); |
| 22 | + |
| 23 | + Assert.Equal(output, ProjectCommandBase.ResolveOutputPath(output, Path.Combine(Root, "src", "Startup"))); |
| 24 | + } |
| 25 | + |
| 26 | + [Fact] |
| 27 | + public void Relative_output_without_working_directory_is_resolved_from_the_current_directory() |
| 28 | + => Assert.Equal(Path.GetFullPath("script.sql"), ProjectCommandBase.ResolveOutputPath("script.sql", workingDir: null)); |
| 29 | + |
| 30 | + [Fact] |
| 31 | + public void Dot_segments_are_normalized() |
| 32 | + => Assert.Equal( |
| 33 | + Path.Combine(Root, "src", "Migrations", "script.sql"), |
| 34 | + ProjectCommandBase.ResolveOutputPath(Path.Combine("..", "Migrations", "script.sql"), Path.Combine(Root, "src", "Startup"))); |
| 35 | +} |
0 commit comments