public void PropertyWithOverride_WriteSyntax_OverrideImplementedInChild() { WithSourceFiles(Files.NotCompilable, Files.Name); var person = CreateClass("PersonFromAbstractName"); var name = CreateMixinReference(person, "_name"); // create a worker method with an override keyword var properties = name.Class.Properties.Select(x => x.Clone(true)); var includeWriter = new IncludeMixinSyntaxWriter(properties, name, Semantic); var newPersonClassSource = includeWriter.Visit(person.SourceCode); // check that generated class code has exactly one indexer declaration var propertyDeclaration = newPersonClassSource.DescendantNodes() .OfType<PropertyDeclarationSyntax>() .Single() .NormalizeWhitespace() .GetText() .ToString(); Assert.IsTrue(propertyDeclaration.Contains("override")); }
public void OverrideMethodToImplement_WriteSyntax_MethodHasOverrideModifier() { WithSourceFiles(Files.Person, Files.Worker); var person = CreateClass(nameof(PersonWithToString)); var worker = CreateMixinReference(person, "_toString"); var includeWriter = new IncludeMixinSyntaxWriter(worker.Class.Methods, worker, Semantic); var newPersonClassSource = includeWriter.Visit(person.SourceCode); // check that new person class has a method that is overriden var methodDeclaration = newPersonClassSource.DescendantNodes() .OfType<MethodDeclarationSyntax>() .Single() .NormalizeWhitespace() .GetText() .ToString(); Assert.IsTrue(methodDeclaration.Contains("override")); }
public void MixinWithIndexer_WriteSyntax_IndexerImplementedInChild() { WithSourceFiles(Files.Person, Files.Collection); var person = CreateClass(nameof(PersonWithIndexer)); var collection = CreateMixinReference(person, "_collection"); var includeWriter = new IncludeMixinSyntaxWriter(collection.Class.Properties, collection, Semantic); var newPersonClassSource = includeWriter.Visit(person.SourceCode); // check that generated class code has exactly one indexer declaration var indexerDeclaration = newPersonClassSource.DescendantNodes() .OfType<IndexerDeclarationSyntax>().SingleOrDefault(); Assert.IsNotNull(indexerDeclaration); }