// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Runtime.InteropServices; using Cli.FunctionalTests.Templates; using Cli.FunctionalTests.Util; using NuGet.Versioning; using NUnit.Framework; namespace Cli.FunctionalTests { [TestFixture] public class TemplateTests { [Test] [TestCaseSource(nameof(RestoreData))] public void _1_Restore(Template template) { var expected = template.ExpectedObjFilesAfterRestore; var actual = template.ObjFilesAfterRestore; CollectionAssert.AreEquivalent(expected, actual); } [Test] [TestCaseSource(nameof(RestoreData))] public void _2_RestoreIncremental(Template template) { var expected = template.ExpectedObjFilesAfterRestore; var actual = template.ObjFilesAfterRestoreIncremental; CollectionAssert.AreEquivalent(expected, actual); } [Test] [TestCaseSource(nameof(BuildData))] public void _3_Build(Template template) { var expectedObj = template.ExpectedObjFilesAfterBuild; var actualObj = template.ObjFilesAfterBuild; CollectionAssert.AreEquivalent(expectedObj, actualObj); var expectedBin = template.ExpectedBinFilesAfterBuild; var actualBin = template.BinFilesAfterBuild; CollectionAssert.AreEquivalent(expectedBin, actualBin); } [Test] [TestCaseSource(nameof(BuildData))] public void _4_BuildIncremental(Template template) { var expectedObj = template.ExpectedObjFilesAfterBuild; var actualObj = template.ObjFilesAfterBuildIncremental; CollectionAssert.AreEquivalent(expectedObj, actualObj); var expectedBin = template.ExpectedBinFilesAfterBuild; var actualBin = template.BinFilesAfterBuildIncremental; CollectionAssert.AreEquivalent(expectedBin, actualBin); } [Test] [TestCaseSource(nameof(RunData))] public void _5_Run(Template template) { var statusCode = template.HttpResponseAfterRun.StatusCode; Assert.AreEqual(HttpStatusCode.OK, statusCode, GetMessage(statusCode, template.ServerOutputAfterRun, template.ServerErrorAfterRun)); statusCode = template.HttpsResponseAfterRun.StatusCode; Assert.AreEqual(HttpStatusCode.OK, statusCode, GetMessage(statusCode, template.ServerOutputAfterRun, template.ServerErrorAfterRun)); } [NonParallelizable] [Test] [TestCaseSource(nameof(RunNonParallelizableData))] public void _5_RunNonParallelizable(Template template) { _5_Run(template); } [Test] [TestCaseSource(nameof(PublishData))] public void _6_Publish(Template template) { var expected = template.ExpectedFilesAfterPublish; var actual = template.FilesAfterPublish; CollectionAssert.AreEquivalent(expected, actual); } [Test] [TestCaseSource(nameof(PublishData))] public void _7_PublishIncremental(Template template) { var expected = template.ExpectedFilesAfterPublish; var actual = template.FilesAfterPublishIncremental; CollectionAssert.AreEquivalent(expected, actual); } [Test] [TestCaseSource(nameof(ExecData))] public void _8_Exec(Template template) { var statusCode = template.HttpResponseAfterExec.StatusCode; Assert.AreEqual(HttpStatusCode.OK, statusCode, GetMessage(statusCode, template.ServerOutputAfterExec, template.ServerErrorAfterExec)); statusCode = template.HttpsResponseAfterExec.StatusCode; Assert.AreEqual(HttpStatusCode.OK, statusCode, GetMessage(statusCode, template.ServerOutputAfterExec, template.ServerErrorAfterExec)); } private static string GetMessage(HttpStatusCode statusCode, string serverOutput, string serverError) { return String.Join(Environment.NewLine, $"StatusCode: {statusCode}", string.Empty, "ServerOutput", "------------", serverOutput, string.Empty, "ServerError", "------------", serverError); } private static IEnumerable