forked from dotnet/msbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigCache_Tests.cs
More file actions
135 lines (111 loc) · 5.63 KB
/
Copy pathConfigCache_Tests.cs
File metadata and controls
135 lines (111 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Linq;
using Microsoft.Build.BackEnd;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Internal;
using Shouldly;
using Xunit;
#nullable disable
namespace Microsoft.Build.UnitTests.BackEnd
{
public class ConfigCache_Tests
{
public static IEnumerable<object[]> CacheSerializationTestData
{
get
{
yield return new[] { new ConfigCache() };
var brq1 = new BuildRequestConfiguration(
1,
new BuildRequestData("path1", new Dictionary<string, string> { ["a1"] = "b1" }, Constants.defaultToolsVersion, new[] { "target1" }, null),
Constants.defaultToolsVersion);
var configCache1 = new ConfigCache();
configCache1.AddConfiguration(brq1.ShallowCloneWithNewId(1));
yield return new[] { configCache1 };
var brq2 = new BuildRequestConfiguration(
2,
new BuildRequestData("path2", new Dictionary<string, string> { ["a2"] = "b2" }, Constants.defaultToolsVersion, new[] { "target2" }, null),
Constants.defaultToolsVersion);
var configCache2 = new ConfigCache();
configCache2.AddConfiguration(brq1.ShallowCloneWithNewId(1));
configCache2.AddConfiguration(brq2.ShallowCloneWithNewId(2));
var brq3 = new BuildRequestConfiguration(
3,
new BuildRequestData("path3", new Dictionary<string, string> { ["a3"] = "b3" }, Constants.defaultToolsVersion, new[] { "target3" }, null),
Constants.defaultToolsVersion);
brq3.ProjectDefaultTargets = new List<string> { "target3" };
brq3.ProjectInitialTargets = new List<string> { "targetInitial" };
var configCache3 = new ConfigCache();
configCache3.AddConfiguration(brq3.ShallowCloneWithNewId(3));
yield return new[] { configCache3 };
}
}
public static IEnumerable<object[]> CacheSerializationTestDataNoConfigs
{
get
{
yield return new[] { new ConfigCache() };
}
}
public static IEnumerable<object[]> CacheSerializationTestDataMultipleConfigs
{
get
{
var configCache = new ConfigCache();
var brq1 = new BuildRequestConfiguration(
1,
new BuildRequestData("path1", new Dictionary<string, string> { ["a1"] = "b1" }, Constants.defaultToolsVersion, new[] { "target1" }, null),
Constants.defaultToolsVersion);
var brq2 = new BuildRequestConfiguration(
2,
new BuildRequestData("path2", new Dictionary<string, string> { ["a2"] = "b2" }, Constants.defaultToolsVersion, new[] { "target2" }, null),
Constants.defaultToolsVersion);
var brq3 = new BuildRequestConfiguration(
3,
new BuildRequestData("path3", new Dictionary<string, string> { ["a3"] = "b3" }, Constants.defaultToolsVersion, new[] { "target3" }, null),
Constants.defaultToolsVersion);
configCache.AddConfiguration(brq1.ShallowCloneWithNewId(1));
configCache.AddConfiguration(brq2.ShallowCloneWithNewId(2));
configCache.AddConfiguration(brq3.ShallowCloneWithNewId(3));
yield return new[] { configCache };
}
}
[Theory]
[MemberData(nameof(CacheSerializationTestData))]
public void ConfigCacheShouldBeTranslatable(object obj)
{
var initial = (ConfigCache)obj;
TranslationHelpers.GetWriteTranslator().Translate(ref initial);
ConfigCache copy = null;
TranslationHelpers.GetReadTranslator().Translate(ref copy);
// test _configurations
var initialConfigurations = initial.ToArray();
var copiedConfigurations = copy.ToArray();
Assert.Equal(copiedConfigurations, initialConfigurations, EqualityComparer<BuildRequestConfiguration>.Default);
// test _configurationIdsByMetadata
copiedConfigurations.ShouldAllBe(config => initial.GetMatchingConfiguration(new ConfigurationMetadata(config)).Equals(config));
initialConfigurations.ShouldAllBe(config => copy.GetMatchingConfiguration(new ConfigurationMetadata(config)).Equals(config));
// test relevant fields not covered by BuildRequestConfiguration.Equals
foreach (var initialConfiguration in initial)
{
copy[initialConfiguration.ConfigurationId].ProjectDefaultTargets.ShouldBe(initialConfiguration.ProjectDefaultTargets);
copy[initialConfiguration.ConfigurationId].ProjectInitialTargets.ShouldBe(initialConfiguration.ProjectInitialTargets);
}
}
[Theory]
[MemberData(nameof(CacheSerializationTestDataNoConfigs))]
public void GetSmallestConfigIdThrows(object obj)
{
Assert.Throws<InternalErrorException>(() => ((ConfigCache)obj).GetSmallestConfigId());
}
[Theory]
[MemberData(nameof(CacheSerializationTestDataMultipleConfigs))]
public void HappyGetSmallestConfigId(object obj)
{
Assert.Equal(1, ((ConfigCache)obj).GetSmallestConfigId());
}
}
}