public void AddProtobufReference_DoesNotOverwriteReference(string path, string altPath, string normalizedPath) { // Arrange var commandBase = new CommandBase(new TestConsole(), new Project()); var referencePath = Path.Combine(Directory.GetCurrentDirectory(), "TestAssets", "EmptyProject", path); var altReferencePath = Path.Combine(Directory.GetCurrentDirectory(), "TestAssets", "EmptyProject", altPath); var normalizedReferencePath = Path.GetFullPath( Path.Combine( Directory.GetCurrentDirectory(), "TestAssets", "EmptyProject", normalizedPath.Replace('\\', '/'))) .Replace('/', '\\'); // Act commandBase.AddProtobufReference(Services.Server, "ImportDir", Access.Internal, referencePath, SourceUrl); commandBase.AddProtobufReference(Services.Client, "ImportDir2", Access.Public, altReferencePath, SourceUrl + ".proto"); commandBase.Project.ReevaluateIfNecessary(); // Assert var protoRefs = commandBase.Project.GetItems(CommandBase.ProtobufElement); Assert.AreEqual(1, protoRefs.Count); var protoRef = protoRefs.Single(); Assert.AreEqual(normalizedReferencePath, protoRef.UnevaluatedInclude); Assert.AreEqual("Server", protoRef.GetMetadataValue(CommandBase.GrpcServicesElement)); Assert.AreEqual("ImportDir", protoRef.GetMetadataValue(CommandBase.AdditionalImportDirsElement)); Assert.AreEqual("Internal", protoRef.GetMetadataValue(CommandBase.AccessElement)); Assert.AreEqual(SourceUrl, protoRef.GetMetadataValue(CommandBase.SourceUrlElement)); }
public void AddProtobufReference_AdditionalImportDirs(string additionalImportDir, string normalizedAdditionalImportDir) { // Arrange var commandBase = new CommandBase( new TestConsole(), CreateIsolatedProject(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets", "EmptyProject", "test.csproj"))); const string proto = "Proto/a.proto"; // Act commandBase.AddProtobufReference(Services.Server, "ImportDir", Access.Internal, proto, SourceUrl); commandBase.Project.ReevaluateIfNecessary(); // Assert var protoRefs = commandBase.Project.GetItems(CommandBase.ProtobufElement); Assert.AreEqual(1, protoRefs.Count); var protoRef = protoRefs.Single(); Assert.AreEqual(proto.Replace('/', '\\'), protoRef.UnevaluatedInclude); Assert.AreEqual("Server", protoRef.GetMetadataValue(CommandBase.GrpcServicesElement)); Assert.AreEqual("ImportDir", protoRef.GetMetadataValue(CommandBase.AdditionalImportDirsElement)); Assert.AreEqual("Internal", protoRef.GetMetadataValue(CommandBase.AccessElement)); Assert.AreEqual(SourceUrl, protoRef.GetMetadataValue(CommandBase.SourceUrlElement)); Assert.False(protoRef.HasMetadata(CommandBase.LinkElement)); }
public void AddProtobufReference_AddsAbsoluteReference(string path, string normalizedPath, string link) { // Arrange var commandBase = new CommandBase( new TestConsole(), CreateIsolatedProject(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets", "EmptyProject", "test.csproj"))); var referencePath = Path.Combine(Directory.GetCurrentDirectory(), "TestAssets", "EmptyProject", path); var normalizedReferencePath = Path.GetFullPath( Path.Combine( Directory.GetCurrentDirectory(), "TestAssets", "EmptyProject", normalizedPath.Replace('\\', Path.DirectorySeparatorChar))) .Replace('/', '\\'); // Act commandBase.AddProtobufReference(Services.Server, "ImportDir", Access.Internal, referencePath, SourceUrl); commandBase.Project.ReevaluateIfNecessary(); // Assert var protoRefs = commandBase.Project.GetItems(CommandBase.ProtobufElement); Assert.AreEqual(1, protoRefs.Count); var protoRef = protoRefs.Single(); Assert.AreEqual(normalizedReferencePath, protoRef.UnevaluatedInclude); Assert.AreEqual("Server", protoRef.GetMetadataValue(CommandBase.GrpcServicesElement)); Assert.AreEqual("ImportDir", protoRef.GetMetadataValue(CommandBase.AdditionalImportDirsElement)); Assert.AreEqual("Internal", protoRef.GetMetadataValue(CommandBase.AccessElement)); Assert.AreEqual(SourceUrl, protoRef.GetMetadataValue(CommandBase.SourceUrlElement)); Assert.AreEqual(link, protoRef.GetMetadataValue(CommandBase.LinkElement)); }
public void AddProtobufReference_ThrowsIfFileNotFound() { // Arrange var commandBase = new CommandBase(new TestConsole(), new Project()); // Act, Assert Assert.Throws <CLIToolException>(() => commandBase.AddProtobufReference(Services.Both, string.Empty, Access.Public, "NonExistentFile", string.Empty)); }
public void AddProtobufReference_AddsAbsoluteReference() { // Arrange var commandBase = new CommandBase(new TestConsole(), new Project()); var referencePath = Path.Combine(Directory.GetCurrentDirectory(), "TestAssets", "EmptyProject", "Proto", "a.proto"); // Act commandBase.AddProtobufReference(Services.Server, "ImportDir", Access.Internal, referencePath, SourceUrl); commandBase.Project.ReevaluateIfNecessary(); // Assert var protoRefs = commandBase.Project.GetItems(CommandBase.ProtobufElement); Assert.AreEqual(1, protoRefs.Count); var protoRef = protoRefs.Single(); Assert.AreEqual(referencePath, protoRef.UnevaluatedInclude); Assert.AreEqual("Server", protoRef.GetMetadataValue(CommandBase.GrpcServicesElement)); Assert.AreEqual("ImportDir", protoRef.GetMetadataValue(CommandBase.AdditionalImportDirsElement)); Assert.AreEqual("Internal", protoRef.GetMetadataValue(CommandBase.AccessElement)); Assert.AreEqual(SourceUrl, protoRef.GetMetadataValue(CommandBase.SourceUrlElement)); Assert.False(protoRef.HasMetadata(CommandBase.LinkElement)); }
public void AddProtobufReference_AddsLinkElementIfFileOutsideProject(string reference) { // Arrange var commandBase = new CommandBase( new TestConsole(), CreateIsolatedProject(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets", "EmptyProject", "test.csproj"))); // Act commandBase.AddProtobufReference(Services.Server, "ImportDir", Access.Internal, reference, SourceUrl); commandBase.Project.ReevaluateIfNecessary(); // Assert var protoRefs = commandBase.Project.GetItems(CommandBase.ProtobufElement); Assert.AreEqual(1, protoRefs.Count); var protoRef = protoRefs.Single(); Assert.AreEqual(reference, protoRef.UnevaluatedInclude); Assert.AreEqual("Server", protoRef.GetMetadataValue(CommandBase.GrpcServicesElement)); Assert.AreEqual("ImportDir", protoRef.GetMetadataValue(CommandBase.AdditionalImportDirsElement)); Assert.AreEqual("Internal", protoRef.GetMetadataValue(CommandBase.AccessElement)); Assert.AreEqual(SourceUrl, protoRef.GetMetadataValue(CommandBase.SourceUrlElement)); Assert.AreEqual(Path.Combine(CommandBase.ProtosFolder, "a.proto"), protoRef.GetMetadataValue(CommandBase.LinkElement)); }