dotnet-installer/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Transforms/GivenAConditionalTransform.cs

46 lines
1.5 KiB
C#
Raw Normal View History

2016-08-22 19:24:10 +00:00
using Microsoft.DotNet.ProjectJsonMigration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using Microsoft.Build.Construction;
2016-08-23 20:50:05 +00:00
using Microsoft.DotNet.ProjectJsonMigration.Transforms;
2016-08-22 19:24:10 +00:00
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
public class GivenAConditionalTransform
{
[Fact]
public void It_returns_null_when_condition_is_false()
{
var conditionalTransform = new TestConditionalTransform(t => false);
conditionalTransform.Transform("astring").Should().BeNull();
}
[Fact]
public void It_returns_result_of_ConditionallyTransform_when_condition_is_true()
{
var conditionalTransform = new TestConditionalTransform(t => true);
var property = conditionalTransform.Transform("astring");
property.Should().NotBeNull();
property.Name.Should().Be("astring");
property.Value.Should().Be("astring");
}
private class TestConditionalTransform : ConditionalTransform<string, ProjectPropertyElement>
{
public TestConditionalTransform(Func<string, bool> condition) : base(condition) { }
public override ProjectPropertyElement ConditionallyTransform(string source)
{
var property = ProjectRootElement.Create().CreatePropertyElement(source);
property.Value = source;
return property;
}
}
}
}