private void AssertAction(string original, KeyValuePair <string, UpdateAction> action, string expected)
        {
            // Arrange
            var syntaxTree   = CSharpSyntaxTree.ParseText(original);
            var assemblyName = Path.GetRandomFileName();
            var references   = new MetadataReference[]
            {
                MetadataReference.CreateFromFile(typeof(object).Assembly.Location)
            };

            var compilation = CSharpCompilation.Create(
                assemblyName,
                syntaxTrees: new[] { syntaxTree, AttributeSyntax },
                references: references,
                options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
            var semanticModel = compilation.GetSemanticModel(syntaxTree, false);

            var actions = new Dictionary <string, UpdateAction>()
            {
                { action.Key, action.Value }
            };

            var target = new SourceUpdater(actions, semanticModel);

            // Act
            var result = target.Visit(syntaxTree.GetRoot());

            // Assert
            Assert.True(action.Value.Actioned);

            var text = result.ToFullString();

            Assert.Equal(expected, text);
        }
Esempio n. 2
0
 public void Initialise()
 {
     _cache   = new Cache <Person, string>();
     _updater = new SourceUpdater <Person, string>(_cache, new KeySelector <Person, string>(p => p.Name));
 }
 public void Initialise()
 {
     _cache = new Cache<Person, string>();
     _updater = new SourceUpdater<Person, string>(_cache,new KeySelector<Person, string>( p => p.Name));
 }