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 Microsoft.Build.Framework; 20 using Microsoft.Build.Utilities; 21 using Moq; 22 using NUnit.Framework; 23 24 namespace Grpc.Tools.Tests 25 { 26 public class GeneratorTest 27 { 28 protected Mock<IBuildEngine> _mockEngine; 29 protected TaskLoggingHelper _log; 30 31 [SetUp] SetUp()32 public void SetUp() 33 { 34 _mockEngine = new Mock<IBuildEngine>(); 35 _log = new TaskLoggingHelper(_mockEngine.Object, "dummy"); 36 } 37 38 [TestCase("csharp")] 39 [TestCase("CSharp")] 40 [TestCase("cpp")] ValidLanguages(string lang)41 public void ValidLanguages(string lang) 42 { 43 Assert.IsNotNull(GeneratorServices.GetForLanguage(lang, _log)); 44 _mockEngine.Verify(me => me.LogErrorEvent(It.IsAny<BuildErrorEventArgs>()), Times.Never); 45 } 46 47 [TestCase("")] 48 [TestCase("COBOL")] InvalidLanguages(string lang)49 public void InvalidLanguages(string lang) 50 { 51 Assert.IsNull(GeneratorServices.GetForLanguage(lang, _log)); 52 _mockEngine.Verify(me => me.LogErrorEvent(It.IsAny<BuildErrorEventArgs>()), Times.Once); 53 } 54 }; 55 } 56