Esempio n. 1
0
 public ProtoAttributeService(Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp,
                              ProtoAttributeAdder adder, ProtoAttributeRemover remover, ProtoAttributeRewriter rewriter)
 {
     _serviceProvider = sp;
     //TODO: move to an injection
     _adder    = adder;
     _remover  = remover;
     _rewriter = rewriter;
 }
        public void RewritesEnumAttributesFileHasProtoIgnores()
        {
            var tree          = CSharpSyntaxTree.ParseText(_fixture.LoadTestFile(@"./Mocks/TestEnumWithProtoIgnore.cs"));
            var rewriter      = new ProtoAttributeRewriter();
            var rewrittenRoot = rewriter.Visit(tree.GetRoot());

            var output = rewrittenRoot.GetText().ToString();
            var source = output.Split(new string[] { " ", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            output.Should().Contain("ProtoBuf");
            output.Should().Contain("[ProtoContract]");
            _fixture.AssertOutputContainsCount(source, "[ProtoIgnore]", 2);
            _fixture.AssertOutputContainsCount(source, "[ProtoEnum]", 3);
        }
        public void RewritesAttributesWithCorrectOrderWhenAttributesAlreadyExists()
        {
            var tree     = CSharpSyntaxTree.ParseText(_codeWithAttributes);
            var rewriter = new ProtoAttributeRewriter();

            var rewrittenRoot = rewriter.Visit(tree.GetRoot());

            var output = rewrittenRoot.GetText().ToString();

            output.Should().Contain("ProtoBuf");
            output.Should().Contain("[ProtoContract]");
            output.Should().Contain(@"[ProtoMember(1, Name=""Test"")]");
            output.Should().Contain("[ProtoMember(2)]");
            output.Should().Contain("[ProtoMember(3)]");
            output.Should().Contain("[ProtoMember(4)]");
        }