Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using FluentAssertions;
using Microsoft.Build.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit;
Expand All @@ -15,27 +17,9 @@ public class GivenAResolvePackageAssetsTask
[Fact]
public void ItHashesAllParameters()
{
var inputProperties = typeof(ResolvePackageAssets)
.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public)
.Where(p => !p.IsDefined(typeof(OutputAttribute)) &&
p.Name != nameof(ResolvePackageAssets.DesignTimeBuild))
.OrderBy(p => p.Name, StringComparer.Ordinal);
IEnumerable<PropertyInfo> inputProperties;

var requiredProperties = inputProperties
.Where(p => p.IsDefined(typeof(RequiredAttribute)));

var task = new ResolvePackageAssets();

// Initialize all required properties as a genuine task invocation would. We do this
// because HashSettings need not defend against required parameters being null.
foreach (var property in requiredProperties)
{
property.PropertyType.Should().Be(
typeof(string),
because: $"this test hasn't been updated to handle non-string required task parameters like {property.Name}");

property.SetValue(task, "_");
}
var task = InitializeTask(out inputProperties);

byte[] oldHash;
try
Expand Down Expand Up @@ -80,6 +64,50 @@ public void ItHashesAllParameters()
oldHash = newHash;
}
}

[Fact]
public void ItDoesNotHashDesignTimeBuild()
{
var task = InitializeTask(out _);

task.DesignTimeBuild = false;

byte[] oldHash = task.HashSettings();

task.DesignTimeBuild = true;

byte[] newHash = task.HashSettings();

newHash.Should().BeEquivalentTo(oldHash,
because: $"{nameof(task.DesignTimeBuild)} should not be included in hash.");
}

private ResolvePackageAssets InitializeTask(out IEnumerable<PropertyInfo> inputProperties)
{
inputProperties = typeof(ResolvePackageAssets)
.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public)
.Where(p => !p.IsDefined(typeof(OutputAttribute)) &&
p.Name != nameof(ResolvePackageAssets.DesignTimeBuild))
.OrderBy(p => p.Name, StringComparer.Ordinal);

var requiredProperties = inputProperties
.Where(p => p.IsDefined(typeof(RequiredAttribute)));

var task = new ResolvePackageAssets();

// Initialize all required properties as a genuine task invocation would. We do this
// because HashSettings need not defend against required parameters being null.
foreach (var property in requiredProperties)
{
property.PropertyType.Should().Be(
typeof(string),
because: $"this test hasn't been updated to handle non-string required task parameters like {property.Name}");

property.SetValue(task, "_");
}

return task;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ internal byte[] HashSettings()
{
using (var writer = new BinaryWriter(stream, TextEncoding, leaveOpen: true))
{
writer.Write(DesignTimeBuild);
writer.Write(DisablePackageAssetsCache);
writer.Write(DisableFrameworkAssemblies);
writer.Write(CopyLocalRuntimeTargetAssets);
Expand Down