public void ReturnsTrue_When_HasNoConstraints() { IDynamicTypeSymbol type = GetSymbol(); Mock <ITypeParameterSymbol> parameter = new(); parameter.SetupGet(p => p.Name).Returns("T"); parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>()); Assert.True(type.IsValidForTypeParameter(parameter.Object)); }
public void ThrowsArgumentNullException_When_DynamicTypelIsNull() { IDynamicTypeSymbol type = null !; Mock <ITypeParameterSymbol> parameter = new(); parameter.SetupGet(p => p.Name).Returns("T"); parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>()); Assert.Throws <ArgumentNullException>(() => type.IsValidForTypeParameter(parameter.Object)); }
public void ReturnsFalse_When_ConstrainedToAnyType() { IDynamicTypeSymbol type = GetSymbol(); Mock <ITypeParameterSymbol> parameter = new(); parameter.SetupGet(p => p.Name).Returns("T"); parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>(Compilation.CurrentCompilation.GetTypeByMetadataName("System.Collections.IList") !)); Assert.False(type.IsValidForTypeParameter(parameter.Object)); }
public void ReturnsFalse_When_HasUnmanagedConstraint() { IDynamicTypeSymbol type = GetSymbol(); Mock <ITypeParameterSymbol> parameter = new(); parameter.SetupGet(p => p.Name).Returns("T"); parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>()); parameter.SetupGet(p => p.HasUnmanagedTypeConstraint).Returns(true); Assert.False(type.IsValidForTypeParameter(parameter.Object)); }
public void ReturnsTrue_When_HasNullableReferenceTypeConstraint() { IDynamicTypeSymbol type = GetSymbol(); Mock <ITypeParameterSymbol> parameter = new(); parameter.SetupGet(p => p.Name).Returns("T"); parameter.SetupGet(p => p.ConstraintTypes).Returns(ImmutableArray.Create <ITypeSymbol>()); parameter.SetupGet(p => p.HasReferenceTypeConstraint).Returns(true); parameter.SetupGet(p => p.ReferenceTypeConstraintNullableAnnotation).Returns(NullableAnnotation.Annotated); Assert.True(type.IsValidForTypeParameter(parameter.Object)); }