Add copy constructor to `TagHelperAttribute`.

- Added test to validate copy constructor does its job.

#492
This commit is contained in:
N. Taylor Mullen 2015-08-20 17:00:36 -07:00
parent f7d42ebe80
commit 55760b4fcb
2 changed files with 48 additions and 0 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
@ -19,6 +20,17 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
}
/// <summary>
/// Instantiates a new instance of <see cref="TagHelperAttribute" /> with values provided by the given
/// <paramref name="attribute"/>.
/// </summary>
/// <param name="attribute">A <see cref="IReadOnlyTagHelperAttribute"/> whose values should be copied.</param>
public TagHelperAttribute([NotNull] IReadOnlyTagHelperAttribute attribute)
: this (attribute?.Name, attribute?.Value)
{
Minimized = attribute.Minimized;
}
/// <summary>
/// Instantiates a new instance of <see cref="TagHelperAttribute"/> with the specified <paramref name="name"/>
/// and <paramref name="value"/>.

View File

@ -0,0 +1,36 @@
// 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 Xunit;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
public class TagHelperAttributeTest
{
public static TheoryData CopyConstructorData
{
get
{
return new TheoryData<IReadOnlyTagHelperAttribute>
{
new TagHelperAttribute("hello", "world") { Minimized = false },
new TagHelperAttribute("checked", value: null) { Minimized = true },
};
}
}
[Theory]
[MemberData(nameof(CopyConstructorData))]
public void CopyConstructorCopiesValuesAsExpected(IReadOnlyTagHelperAttribute readOnlyTagHelperAttribute)
{
// Act
var tagHelperAttribute = new TagHelperAttribute(readOnlyTagHelperAttribute);
// Assert
Assert.Equal(
readOnlyTagHelperAttribute,
tagHelperAttribute,
CaseSensitiveTagHelperAttributeComparer.Default);
}
}
}