Debian Codegraph @

src/csharp/Grpc.Tools.Tests/CSharpGeneratorTest.cs

raw
1 #region Copyright notice and license
2
3 // Copyright 2018 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 #endregion
18
19 using NUnit.Framework;
20
21 namespace Grpc.Tools.Tests
22 {
23 public class CSharpGeneratorTest : GeneratorTest
24 {
25 GeneratorServices _generator;
26
27 [SetUp]
28 public new void SetUp()
29 {
30 _generator = GeneratorServices.GetForLanguage("CSharp", _log);
31 }
32
33 [TestCase("foo.proto", "Foo.cs", "FooGrpc.cs")]
34 [TestCase("sub/foo.proto", "Foo.cs", "FooGrpc.cs")]
35 [TestCase("one_two.proto", "OneTwo.cs", "OneTwoGrpc.cs")]
36 [TestCase("ONE_TWO.proto", "ONETWO.cs", "ONETWOGrpc.cs")]
37 [TestCase("one.two.proto", "OneTwo.cs", "One.twoGrpc.cs")]
38 [TestCase("one123two.proto", "One123Two.cs", "One123twoGrpc.cs")]
39 [TestCase("__one_two!.proto", "OneTwo.cs", "OneTwo!Grpc.cs")]
40 [TestCase("one(two).proto", "OneTwo.cs", "One(two)Grpc.cs")]
41 [TestCase("one_(two).proto", "OneTwo.cs", "One(two)Grpc.cs")]
42 [TestCase("one two.proto", "OneTwo.cs", "One twoGrpc.cs")]
43 [TestCase("one_ two.proto", "OneTwo.cs", "One twoGrpc.cs")]
44 [TestCase("one .proto", "One.cs", "One Grpc.cs")]
45 public void NameMangling(string proto, string expectCs, string expectGrpcCs)
46 {
47 var poss = _generator.GetPossibleOutputs(Utils.MakeItem(proto, "grpcservices", "both"));
48 Assert.AreEqual(2, poss.Length);
49 Assert.Contains(expectCs, poss);
50 Assert.Contains(expectGrpcCs, poss);
51 }
52
53 [Test]
54 public void NoGrpcOneOutput()
55 {
56 var poss = _generator.GetPossibleOutputs(Utils.MakeItem("foo.proto"));
57 Assert.AreEqual(1, poss.Length);
58 }
59
60 [TestCase("none")]
61 [TestCase("")]
62 public void GrpcNoneOneOutput(string grpc)
63 {
64 var item = Utils.MakeItem("foo.proto", "grpcservices", grpc);
65 var poss = _generator.GetPossibleOutputs(item);
66 Assert.AreEqual(1, poss.Length);
67 }
68
69 [TestCase("client")]
70 [TestCase("server")]
71 [TestCase("both")]
72 public void GrpcEnabledTwoOutputs(string grpc)
73 {
74 var item = Utils.MakeItem("foo.proto", "grpcservices", grpc);
75 var poss = _generator.GetPossibleOutputs(item);
76 Assert.AreEqual(2, poss.Length);
77 }
78
79 [Test]
80 public void OutputDirMetadataRecognized()
81 {
82 var item = Utils.MakeItem("foo.proto", "OutputDir", "out");
83 var poss = _generator.GetPossibleOutputs(item);
84 Assert.AreEqual(1, poss.Length);
85 Assert.That(poss[0], Is.EqualTo("out/Foo.cs") | Is.EqualTo("out\\Foo.cs"));
86 }
87
88 [Test]
89 public void OutputDirPatched()
90 {
91 var item = Utils.MakeItem("sub/foo.proto", "OutputDir", "out");
92 var output = _generator.PatchOutputDirectory(item);
93 var poss = _generator.GetPossibleOutputs(output);
94 Assert.AreEqual(1, poss.Length);
95 Assert.That(poss[0], Is.EqualTo("out/sub/Foo.cs") | Is.EqualTo("out\\sub\\Foo.cs"));
96 }
97 };
98 }