Enable to initialize a project before restore
1. Check the lock file path first. 2. Update tests
This commit is contained in:
parent
7c5f505276
commit
68c0edff17
3 changed files with 53 additions and 14 deletions
|
@ -193,17 +193,21 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
{
|
||||
currentEntry = new FileModelEntry<LockFile>();
|
||||
}
|
||||
else if (!File.Exists(Path.Combine(projectDirectory, LockFile.FileName)))
|
||||
{
|
||||
currentEntry.Reset();
|
||||
return currentEntry;
|
||||
}
|
||||
|
||||
if (currentEntry.IsInvalid)
|
||||
{
|
||||
currentEntry.FilePath = Path.Combine(projectDirectory, LockFile.FileName);
|
||||
currentEntry.Model = LockFileReader.Read(currentEntry.FilePath);
|
||||
currentEntry.UpdateLastWriteTime();
|
||||
currentEntry.Reset();
|
||||
|
||||
if (!File.Exists(Path.Combine(projectDirectory, LockFile.FileName)))
|
||||
{
|
||||
return currentEntry;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentEntry.FilePath = Path.Combine(projectDirectory, LockFile.FileName);
|
||||
currentEntry.Model = LockFileReader.Read(currentEntry.FilePath);
|
||||
currentEntry.UpdateLastWriteTime();
|
||||
}
|
||||
}
|
||||
|
||||
return currentEntry;
|
||||
|
@ -241,7 +245,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
currentEntry.ProjectContexts.Add(builder.Build());
|
||||
}
|
||||
|
||||
|
||||
currentEntry.Project = project;
|
||||
currentEntry.ProjectFilePath = project.ProjectFilePath;
|
||||
currentEntry.LastProjectFileWriteTime = File.GetLastWriteTime(currentEntry.ProjectFilePath);
|
||||
|
|
|
@ -11,11 +11,11 @@ using Xunit;
|
|||
|
||||
namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
||||
{
|
||||
public class DthStartupTests : IClassFixture<TestHelper>
|
||||
public class DthTests : IClassFixture<TestHelper>
|
||||
{
|
||||
private readonly TestHelper _testHelper;
|
||||
|
||||
public DthStartupTests(TestHelper helper)
|
||||
public DthTests(TestHelper helper)
|
||||
{
|
||||
_testHelper = helper;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
|||
{
|
||||
// After restore the project is copied to another place so that
|
||||
// the relative path in project lock file is invalid.
|
||||
var movedProjectPath = _testHelper.MoveProject("BrokenProjectPathSample");
|
||||
var movedProjectPath = _testHelper.BuildProjectCopy("BrokenProjectPathSample");
|
||||
|
||||
client.Initialize(movedProjectPath);
|
||||
|
||||
|
@ -231,5 +231,30 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
|||
.AssertProperty("ErrorCode", "NU1010");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DthStartup_OpenProjectBeforeRestore()
|
||||
{
|
||||
var projectPath = _testHelper.BuildProjectCopy("EmptyConsoleApp");
|
||||
_testHelper.DeleteLockFile(projectPath);
|
||||
|
||||
using (var server = new DthTestServer(_testHelper.LoggerFactory))
|
||||
using (var client = new DthTestClient(server))
|
||||
{
|
||||
client.Initialize(projectPath);
|
||||
var messages = client.DrainAllMessages();
|
||||
Assert.False(messages.Any(msg => msg.MessageType == MessageTypes.Error));
|
||||
|
||||
var dependencyDiagnostics = messages.Where(msg => msg.MessageType == MessageTypes.DependencyDiagnostics);
|
||||
Assert.Equal(2, dependencyDiagnostics.Count());
|
||||
|
||||
foreach (var message in dependencyDiagnostics)
|
||||
{
|
||||
message.RetrievePayloadAs<JObject>()
|
||||
.RetrievePropertyAs<JArray>("Errors")
|
||||
.AssertJArrayContains<JObject>(error => error["ErrorCode"].Value<string>() == ErrorCodes.NU1009);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.DotNet.ProjectModel.Graph;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel.Server.Tests.Helpers
|
||||
|
@ -11,7 +12,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests.Helpers
|
|||
public TestHelper()
|
||||
{
|
||||
LoggerFactory = new LoggerFactory();
|
||||
|
||||
|
||||
var testVerbose = Environment.GetEnvironmentVariable("DOTNET_TEST_VERBOSE");
|
||||
if (testVerbose == "2")
|
||||
{
|
||||
|
@ -63,7 +64,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests.Helpers
|
|||
return target;
|
||||
}
|
||||
|
||||
public string MoveProject(string projectName)
|
||||
public string BuildProjectCopy(string projectName)
|
||||
{
|
||||
var projectPath = FindSampleProject(projectName);
|
||||
var movedProjectPath = Path.Combine(CreateTempFolder(), projectName);
|
||||
|
@ -72,6 +73,15 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests.Helpers
|
|||
return movedProjectPath;
|
||||
}
|
||||
|
||||
public void DeleteLockFile(string folder)
|
||||
{
|
||||
var lockFilePath = Path.Combine(folder, LockFile.FileName);
|
||||
if (File.Exists(lockFilePath))
|
||||
{
|
||||
File.Delete(lockFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
private static string FindRoot()
|
||||
{
|
||||
var solutionName = "Microsoft.DotNet.Cli.sln";
|
||||
|
|
Loading…
Reference in a new issue