public async Task CanAssignToWhenParameterIsDoubleAndArgumentIsInt32()
        {
            var values = await AttributeArgumentSyntaxExtensionsTests.GetAttributeSyntaxAsync(
                $"{AttributeArgumentSyntaxExtensionsTests.BasePath}{(nameof(this.CanAssignToWhenParameterIsDoubleAndArgumentIsInt32))}.cs");

            Assert.That(values.Item1.CanAssignTo(values.Item2, values.Item3), Is.True);
        }
        public async Task CanAssignToWhenParameterIsTimeSpanAndArgumentIsInvalidString()
        {
            var values = await AttributeArgumentSyntaxExtensionsTests.GetAttributeSyntaxAsync(
                $"{AttributeArgumentSyntaxExtensionsTests.BasePath}{(nameof(this.CanAssignToWhenParameterIsTimeSpanAndArgumentIsInvalidString))}.cs");

            Assert.That(values.Item1.CanAssignTo(values.Item2, values.Item3), Is.False);
        }
        public async Task CanAssignToWhenArgumentIsNotAssignable()
        {
            var values = await AttributeArgumentSyntaxExtensionsTests.GetAttributeSyntaxAsync(
                $"{AttributeArgumentSyntaxExtensionsTests.BasePath}{(nameof(this.CanAssignToWhenArgumentIsNotAssignable))}.cs");

            Assert.That(values.Item1.CanAssignTo(values.Item2, values.Item3), Is.False);
        }
        public async Task CanAssignToWhenArgumentIsNullAndTargetIsReferenceType()
        {
            var values = await AttributeArgumentSyntaxExtensionsTests.GetAttributeSyntaxAsync(
                $"{AttributeArgumentSyntaxExtensionsTests.BasePath}{(nameof(this.CanAssignToWhenArgumentIsNullAndTargetIsReferenceType))}.cs");

            Assert.That(values.Item1.CanAssignTo(values.Item2, values.Item3), Is.True);
        }
Пример #5
0
        public async Task CanAssignToTests(string arguments, string methodParameterType,
                                           string attributeParameterType, Constraint expectedResult)
        {
            var testCode = $@"
using System;

namespace NUnit.Analyzers.Tests.Targets.Extensions
{{
    public sealed class CanAssignToWhenArgumentIsNullAndTargetIsReferenceType
    {{
        [Arguments({arguments})]
        public void Foo({methodParameterType} a) {{ }}

        [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
        public sealed class ArgumentsAttribute : Attribute
        {{
            public ArgumentsAttribute({attributeParameterType} x) {{ }}
        }}
    }}
}}";
            var values   = await AttributeArgumentSyntaxExtensionsTests.GetAttributeSyntaxAsync(testCode);

            Assert.That(values.Syntax.CanAssignTo(values.TypeSymbol, values.Model), expectedResult);
        }