dotnet-installer/test/Microsoft.DotNet.Cli.Utils.Tests/GivenThatWeWantToReadLockFilesQuickly.cs
Livar 9862fbb4d7 Checking that the lock file exists before trying to acquire the lock for it. (#4797)
* Checking that the lock file exists before trying to acquire a lock for it, which takes up to 30 seconds.

* Adding a test for failing when reading the lock file and it does not exists.
2016-11-23 22:59:54 -08:00

49 lines
No EOL
1.6 KiB
C#

// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics;
using System.IO;
using FluentAssertions;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
using NuGet.ProjectModel;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests
{
public class GivenThatWeWantToReadLockFilesQuickly : TestBase
{
[Fact]
public void ItFailsInLessThanOneSecondWhenTheProjectAssetsJsonDoesNotExist()
{
var testInstance = TestAssets.Get("TestAppWithProjDepTool")
.CreateInstance()
.WithSourceFiles();
var assetsFile = testInstance.Root.GetDirectory("obj").GetFile("project.assets.json").FullName;
var expectedMessage = string.Join(
Environment.NewLine,
$"File not found `{assetsFile}`.",
"The project may not have been restored or restore failed - run `dotnet restore`");
Action action = () =>
{
var lockFile = new LockFileFormat()
.ReadWithLock(assetsFile)
.Result;
};
var stopWatch = Stopwatch.StartNew();
action.ShouldThrow<GracefulException>().WithMessage(expectedMessage);
stopWatch.Stop();
stopWatch.ElapsedMilliseconds.Should().BeLessThan(1000);
}
}
}