Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split tests in Workflow.cpp into multiple files #2773

Merged
merged 10 commits into from
Dec 16, 2022
34 changes: 17 additions & 17 deletions src/AppInstallerCLITests/ARPChanges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ struct TestTelemetry : public TelemetryTraceLogger
mutable bool WasLogSuccessfulInstallARPChangeCalled = false;
};

struct TestContext : public Context
struct ARPTestContext : public Context
{
TestContext(Manifest::InstallerTypeEnum installerType = Manifest::InstallerTypeEnum::Exe) :
ARPTestContext(Manifest::InstallerTypeEnum installerType = Manifest::InstallerTypeEnum::Exe) :
Context(OStream, IStream), SourceFactory([this](const SourceDetails&) { return Source; })
{
// Put installer in to control whether arp change code cares to run
Expand Down Expand Up @@ -117,7 +117,7 @@ struct TestContext : public Context
AddEverythingResult("Id2", "Name2", "Publisher2", "2.0");
}

~TestContext()
~ARPTestContext()
{
TestHook_ClearSourceFactoryOverrides();
TestHook_SetTelemetryOverride({});
Expand Down Expand Up @@ -227,7 +227,7 @@ struct TestHeuristicOverride
TEST_CASE("ARPChanges_MSIX_Ignored", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context(Manifest::InstallerTypeEnum::Msix);
ARPTestContext context(Manifest::InstallerTypeEnum::Msix);

context << SnapshotARPEntries;

Expand All @@ -241,7 +241,7 @@ TEST_CASE("ARPChanges_MSIX_Ignored", "[ARPChanges][workflow]")
TEST_CASE("ARPChanges_CheckSnapshot", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;

Expand Down Expand Up @@ -276,7 +276,7 @@ TEST_CASE("ARPChanges_CheckSnapshot", "[ARPChanges][workflow]")
TEST_CASE("ARPChanges_NoChange_NoMatch", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -288,7 +288,7 @@ TEST_CASE("ARPChanges_NoChange_NoMatch", "[ARPChanges][workflow]")
TEST_CASE("ARPChanges_NoChange_SingleMatch", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -302,7 +302,7 @@ TEST_CASE("ARPChanges_NoChange_SingleMatch", "[ARPChanges][workflow]")
TEST_CASE("ARPChanges_NoChange_MultiMatch", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -317,7 +317,7 @@ TEST_CASE("ARPChanges_NoChange_MultiMatch", "[ARPChanges][workflow]")
TEST_CASE("ARPChanges_SingleChange_NoMatch", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -331,7 +331,7 @@ TEST_CASE("ARPChanges_SingleChange_NoMatch", "[ARPChanges][workflow]")
TEST_CASE("ARPChanges_SingleChange_SingleMatch", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -346,7 +346,7 @@ TEST_CASE("ARPChanges_SingleChange_SingleMatch", "[ARPChanges][workflow]")
TEST_CASE("ARPChanges_SingleChange_MultiMatch", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -362,7 +362,7 @@ TEST_CASE("ARPChanges_SingleChange_MultiMatch", "[ARPChanges][workflow]")
TEST_CASE("ARPChanges_MultiChange_NoMatch", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -377,7 +377,7 @@ TEST_CASE("ARPChanges_MultiChange_NoMatch", "[ARPChanges][workflow]")
TEST_CASE("ARPChanges_MultiChange_SingleMatch_NoOverlap", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -393,7 +393,7 @@ TEST_CASE("ARPChanges_MultiChange_SingleMatch_NoOverlap", "[ARPChanges][workflow
TEST_CASE("ARPChanges_MultiChange_SingleMatch_Overlap", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -409,7 +409,7 @@ TEST_CASE("ARPChanges_MultiChange_SingleMatch_Overlap", "[ARPChanges][workflow]"
TEST_CASE("ARPChanges_MultiChange_MultiMatch_NoOverlap", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -426,7 +426,7 @@ TEST_CASE("ARPChanges_MultiChange_MultiMatch_NoOverlap", "[ARPChanges][workflow]
TEST_CASE("ARPChanges_MultiChange_MultiMatch_SingleOverlap", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand All @@ -443,7 +443,7 @@ TEST_CASE("ARPChanges_MultiChange_MultiMatch_SingleOverlap", "[ARPChanges][workf
TEST_CASE("ARPChanges_MultiChange_MultiMatch_MultiOverlap", "[ARPChanges][workflow]")
{
TestHeuristicOverride heuristicOverride;
TestContext context;
ARPTestContext context;

context << SnapshotARPEntries;
REQUIRE(context.Contains(Data::ARPCorrelationData));
Expand Down
11 changes: 11 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
<ClInclude Include="TestHooks.h" />
<ClInclude Include="TestSettings.h" />
<ClInclude Include="TestSource.h" />
<ClInclude Include="WorkflowCommon.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AdminSettings.cpp" />
Expand All @@ -199,12 +200,16 @@
<ClCompile Include="Dependencies.cpp" />
<ClCompile Include="Downloader.cpp" />
<ClCompile Include="ExperimentalFeature.cpp" />
<ClCompile Include="ExportFlow.cpp" />
<ClCompile Include="Filesystem.cpp" />
<ClCompile Include="FolderFileWatcher.cpp" />
<ClCompile Include="GroupPolicy.cpp" />
<ClCompile Include="HashCommand.cpp" />
<ClCompile Include="HttpClientHelper.cpp" />
<ClCompile Include="ImportFlow.cpp" />
<ClCompile Include="InstallDependenciesFlow.cpp" />
<ClCompile Include="InstallerMetadataCollectionContext.cpp" />
<ClCompile Include="InstallFlow.cpp" />
<ClCompile Include="ManifestComparator.cpp" />
<ClCompile Include="JsonHelper.cpp" />
<ClCompile Include="MsiExecArguments.cpp" />
Expand All @@ -218,6 +223,7 @@
<ClCompile Include="PortableIndex.cpp" />
<ClCompile Include="PredefinedInstalledSource.cpp" />
<ClCompile Include="PreIndexedPackageSource.cpp" />
<ClCompile Include="PromptFlow.cpp" />
<ClCompile Include="Regex.cpp" />
<ClCompile Include="Registry.cpp" />
<ClCompile Include="Resources.cpp" />
Expand All @@ -228,11 +234,15 @@
<ClCompile Include="RestInterface_1_4.cpp" />
<ClCompile Include="Runtime.cpp" />
<ClCompile Include="SearchRequestSerializer.cpp" />
<ClCompile Include="ShowFlow.cpp" />
<ClCompile Include="SourceFlow.cpp" />
<ClCompile Include="SQLiteIndexSource.cpp" />
<ClCompile Include="Strings.cpp" />
<ClCompile Include="TestRestRequestHandler.cpp" />
<ClCompile Include="TestSettings.cpp" />
<ClCompile Include="TestSource.cpp" />
<ClCompile Include="UninstallFlow.cpp" />
<ClCompile Include="UpdateFlow.cpp" />
<ClCompile Include="UserSettings.cpp" />
<ClCompile Include="Versions.cpp" />
<ClCompile Include="WorkFlow.cpp" />
Expand All @@ -252,6 +262,7 @@
<ClCompile Include="SQLiteWrapper.cpp" />
<ClCompile Include="Synchronization.cpp" />
<ClCompile Include="TestCommon.cpp" />
<ClCompile Include="WorkflowCommon.cpp" />
<ClCompile Include="WorkflowGroupPolicy.cpp" />
<ClCompile Include="YamlManifest.cpp" />
</ItemGroup>
Expand Down
33 changes: 33 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<ClInclude Include="DependenciesTestSource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="WorkflowCommon.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
Expand Down Expand Up @@ -242,6 +245,36 @@
<ClCompile Include="AdminSettings.cpp">
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="InstallFlow.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
<ClCompile Include="ShowFlow.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
<ClCompile Include="UpdateFlow.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
<ClCompile Include="UninstallFlow.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
<ClCompile Include="ImportFlow.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
<ClCompile Include="ExportFlow.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
<ClCompile Include="InstallDependenciesFlow.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
<ClCompile Include="PromptFlow.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
<ClCompile Include="SourceFlow.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
<ClCompile Include="WorkflowCommon.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
Expand Down
103 changes: 103 additions & 0 deletions src/AppInstallerCLITests/ExportFlow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "WorkflowCommon.h"
#include <Commands/ExportCommand.h>

using namespace TestCommon;
using namespace AppInstaller::CLI;

TEST_CASE("ExportFlow_ExportAll", "[ExportFlow][workflow]")
{
TestCommon::TempFile exportResultPath("TestExport.json");

std::ostringstream exportOutput;
TestContext context{ exportOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
context.Args.AddArg(Execution::Args::Type::OutputFile, exportResultPath);

ExportCommand exportCommand({});
exportCommand.Execute(context);
INFO(exportOutput.str());

// Verify contents of exported collection
const auto& exportedCollection = context.Get<Execution::Data::PackageCollection>();
REQUIRE(exportedCollection.Sources.size() == 1);
REQUIRE(exportedCollection.Sources[0].Details.Identifier == "*TestSource");

const auto& exportedPackages = exportedCollection.Sources[0].Packages;
REQUIRE(exportedPackages.size() == 6);
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestMsixInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestMSStoreInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestPortableInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestZipInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeUnknownVersion" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
}

TEST_CASE("ExportFlow_ExportAll_WithVersions", "[ExportFlow][workflow]")
{
TestCommon::TempFile exportResultPath("TestExport.json");

std::ostringstream exportOutput;
TestContext context{ exportOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
context.Args.AddArg(Execution::Args::Type::OutputFile, exportResultPath);
context.Args.AddArg(Execution::Args::Type::IncludeVersions);

ExportCommand exportCommand({});
exportCommand.Execute(context);
INFO(exportOutput.str());

// Verify contents of exported collection
const auto& exportedCollection = context.Get<Execution::Data::PackageCollection>();
REQUIRE(exportedCollection.Sources.size() == 1);
REQUIRE(exportedCollection.Sources[0].Details.Identifier == "*TestSource");

const auto& exportedPackages = exportedCollection.Sources[0].Packages;
REQUIRE(exportedPackages.size() == 6);
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestMsixInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestMSStoreInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestPortableInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestZipInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeUnknownVersion" && p.VersionAndChannel.GetVersion().ToString() == "unknown";
}));
}
Loading