public void ObjectCreationConditionForUndefinedSymbol() { const string testInput = @" public class Base { private void Usage(string notAConst) { new Undefined(true); } }"; var context = CreateContext <CSharpSyntax.ObjectCreationExpressionSyntax>(testInput, AnalyzerLanguage.CSharp); var tracker = new CSharpObjectCreationTracker(); tracker.ArgumentAtIndexIs(0, KnownType.System_Boolean)(context).Should().BeFalse(); tracker.WhenDerivesFrom(KnownType.System_Exception)(context).Should().BeFalse(); tracker.WhenImplements(KnownType.System_IDisposable)(context).Should().BeFalse(); tracker.WhenDerivesOrImplementsAny(KnownType.System_Boolean)(context).Should().BeFalse(); tracker.MatchConstructor(KnownType.System_Boolean)(context).Should().BeFalse(); }
public void ObjectCreationConditionForNonconstructorSymbols() { const string testInput = @" using System; public class Base : Exception, IDisposable { private void Method(bool b) { } public void Dispose() { } public void Usage() { Method(true); } }"; var context = CreateContext <CSharpSyntax.InvocationExpressionSyntax>(testInput, AnalyzerLanguage.CSharp); // Created with wrong syntax var tracker = new CSharpObjectCreationTracker(); tracker.ArgumentAtIndexIs(0, KnownType.System_Boolean)(context).Should().BeTrue(); // Doesn't care about symbol type tracker.WhenDerivesFrom(KnownType.System_Exception)(context).Should().BeFalse(); tracker.WhenImplements(KnownType.System_IDisposable)(context).Should().BeFalse(); tracker.WhenDerivesOrImplementsAny(KnownType.System_Exception)(context).Should().BeFalse(); tracker.MatchConstructor(KnownType.System_Boolean)(context).Should().BeFalse(); }