2016-12-01 00:08:28 +00:00
|
|
|
// 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.IO;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Xunit;
|
|
|
|
using Microsoft.DotNet.Cli.Sln.Internal;
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Sln.Internal.Tests
|
|
|
|
{
|
|
|
|
public class GivenAnSlnFile : TestBase
|
|
|
|
{
|
|
|
|
[Fact]
|
2016-12-14 23:53:11 +00:00
|
|
|
public void WhenGivenAValidPathItReadsAnSlnFile()
|
2016-12-01 00:08:28 +00:00
|
|
|
{
|
|
|
|
var solutionDirectory =
|
|
|
|
TestAssetsManager.CreateTestInstance("TestAppWithSln", callingMethod: "p").Path;
|
|
|
|
|
|
|
|
var solutionFullPath = Path.Combine(solutionDirectory, "TestAppWithSln.sln");
|
|
|
|
|
2016-12-13 16:45:00 +00:00
|
|
|
var slnFile = SlnFile.Read(solutionFullPath);
|
2016-12-01 00:08:28 +00:00
|
|
|
|
|
|
|
slnFile.FormatVersion.Should().Be("12.00");
|
|
|
|
slnFile.ProductDescription.Should().Be("Visual Studio 14");
|
|
|
|
slnFile.VisualStudioVersion.Should().Be("14.0.25420.1");
|
|
|
|
slnFile.MinimumVisualStudioVersion.Should().Be("10.0.40219.1");
|
|
|
|
slnFile.BaseDirectory.Should().Be(solutionDirectory);
|
2016-12-13 16:45:00 +00:00
|
|
|
slnFile.FullPath.Should().Be(solutionFullPath);
|
2016-12-01 00:08:28 +00:00
|
|
|
|
|
|
|
slnFile.Projects.Count.Should().Be(1);
|
|
|
|
var project = slnFile.Projects[0];
|
|
|
|
project.Id.Should().Be("{0138CB8F-4AA9-4029-A21E-C07C30F425BA}");
|
|
|
|
project.TypeGuid.Should().Be("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}");
|
|
|
|
project.Name.Should().Be("TestAppWithSln");
|
|
|
|
project.FilePath.Should().Be("TestAppWithSln.xproj");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2016-12-14 23:53:11 +00:00
|
|
|
public void WhenGivenAValidPathItReadsModifiesThenWritesAnSln()
|
2016-12-01 00:08:28 +00:00
|
|
|
{
|
|
|
|
var solutionDirectory =
|
|
|
|
TestAssetsManager.CreateTestInstance("TestAppWithSln", callingMethod: "p").Path;
|
|
|
|
|
|
|
|
var solutionFullPath = Path.Combine(solutionDirectory, "TestAppWithSln.sln");
|
|
|
|
|
2016-12-13 16:45:00 +00:00
|
|
|
var slnFile = SlnFile.Read(solutionFullPath);
|
|
|
|
slnFile.FullPath.Should().Be(solutionFullPath);
|
2016-12-01 00:08:28 +00:00
|
|
|
|
|
|
|
slnFile.Projects.Count.Should().Be(1);
|
|
|
|
var project = slnFile.Projects[0];
|
|
|
|
project.Name.Should().Be("TestAppWithSln");
|
|
|
|
project.Name = "New Project Name";
|
|
|
|
project.FilePath.Should().Be("TestAppWithSln.xproj");
|
|
|
|
project.FilePath = "New File Path";
|
|
|
|
|
|
|
|
var newSolutionFullPath = Path.Combine(solutionDirectory, "TestAppWithSln_modified.sln");
|
|
|
|
slnFile.Write(newSolutionFullPath);
|
|
|
|
|
2016-12-13 16:45:00 +00:00
|
|
|
slnFile = SlnFile.Read(newSolutionFullPath);
|
2016-12-01 00:08:28 +00:00
|
|
|
slnFile.FormatVersion.Should().Be("12.00");
|
|
|
|
slnFile.ProductDescription.Should().Be("Visual Studio 14");
|
|
|
|
slnFile.VisualStudioVersion.Should().Be("14.0.25420.1");
|
|
|
|
slnFile.MinimumVisualStudioVersion.Should().Be("10.0.40219.1");
|
|
|
|
slnFile.BaseDirectory.Should().Be(solutionDirectory);
|
2016-12-13 16:45:00 +00:00
|
|
|
slnFile.FullPath.Should().Be(newSolutionFullPath);
|
2016-12-01 00:08:28 +00:00
|
|
|
slnFile.Projects.Count.Should().Be(1);
|
|
|
|
project = slnFile.Projects[0];
|
|
|
|
project.Id.Should().Be("{0138CB8F-4AA9-4029-A21E-C07C30F425BA}");
|
|
|
|
project.TypeGuid.Should().Be("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}");
|
|
|
|
project.Name.Should().Be("New Project Name");
|
|
|
|
project.FilePath.Should().Be("New File Path");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|