using Perforce.P4; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Diagnostics; namespace p4api.net.unit.test { /// ///This is a test class for RepositoryTest and is intended ///to contain RepositoryTest Unit Tests /// public partial class RepositoryTest { /// ///A test for CreateLabel /// [TestMethod()] public void CreateLabelTest() { bool unicode = false; string uri = "localhost:6666"; string user = "admin"; string pass = string.Empty; string ws_client = "admin_space"; for (int i = 0; i < 2; i++) // run once for ascii, once for unicode { Process p4d = new Process(); p4d = Utilities.DeployP4TestServer(TestDir, 9, unicode); Server server = new Server(new ServerAddress(uri)); try { Repository rep = new Repository(server); using (Connection con = rep.Connection) { con.UserName = user; con.Client = new Client(); con.Client.Name = ws_client; bool connected = con.Connect(null); Assert.IsTrue(connected); Assert.AreEqual(con.Status, ConnectionStatus.Connected); Label l = new Label(); l.Id = "newLabel"; l.Owner = "admin"; l.Description = "created by admin"; #pragma warning disable 618 l.Options = "locked"; #pragma warning restore 618 l.ViewMap = new ViewMap(); string v0 = "//depot/main/..."; string v1 = "//depot/rel1/..."; string v2 = "//depot/rel2/..."; string v3 = "//depot/dev/..."; l.ViewMap.Add(v0); l.ViewMap.Add(v1); l.ViewMap.Add(v2); l.ViewMap.Add(v3); Label newLabel = rep.CreateLabel(l, null); Assert.IsNotNull(newLabel); Assert.AreEqual("newLabel", newLabel.Id); string v4 = "\"//depot/rel2/a file with spaces\""; newLabel.ViewMap.Add(v4); newLabel = rep.UpdateLabel(newLabel); Assert.IsNotNull(newLabel); Assert.AreEqual(newLabel.ViewMap.Count,5); Label l2 = new Label(); l2.Id = "newLabel2"; // create a label from a template Label newLabel2 = rep.CreateLabel(newLabel, new LabelCmdOptions(LabelCmdFlags.None, newLabel.Id)); Assert.IsNotNull(newLabel2); Assert.AreEqual(newLabel2.ViewMap.Count, 5); } } finally { Utilities.RemoveTestServer(p4d, TestDir); } unicode = !unicode; } } /// ///A test for UpdateLabelascii /// [TestMethod()] public void UpdateLabelTestjob096467A() { UpdateLabelTestjob096467(false); } /// ///A test for UpdateLabelunicode /// [TestMethod()] public void UpdateLabelTestjob096467U() { UpdateLabelTestjob096467(true); } /// ///A test for UpdateLabel /// public void UpdateLabelTestjob096467(bool unicode) { string uri = "localhost:6666"; string user = "admin"; string pass = string.Empty; string ws_client = "admin_space"; Process p4d = Utilities.DeployP4TestServer(TestDir, 8, unicode); Server server = new Server(new ServerAddress(uri)); try { Repository rep = new Repository(server); using (Connection con = rep.Connection) { con.UserName = user; con.Client = new Client(); con.Client.Name = ws_client; bool connected = con.Connect(null); Assert.IsTrue(connected); Assert.AreEqual(con.Status, ConnectionStatus.Connected); string targetLabel = "admin_label"; Label l = rep.GetLabel(targetLabel); // change the viewmap to have an exclusionary line ViewMap vm = l.ViewMap; MapEntry original = vm[0]; MapEntry newExclude = new MapEntry(MapType.Exclude, original.Left, original.Right); l.ViewMap.Remove(original); l.ViewMap.Add(newExclude); l = rep.UpdateLabel(l); // now update the label without any changes, to // confirm that the exclusionary line does not break // the attempted update l = rep.GetLabel(targetLabel); l = rep.UpdateLabel(l); Assert.IsNotNull(l); Assert.AreEqual(targetLabel, l.Id); Assert.AreEqual(l.ViewMap.Count, 1); Assert.IsTrue(l.ViewMap[0].Type.Equals(MapType.Exclude)); Assert.IsTrue(l.ViewMap[0].Left.Path.Equals("//depot/...")); } } finally { Utilities.RemoveTestServer(p4d, TestDir); } } /// /// A test for DeleteLabel /// [TestMethod()] public void DeleteLabelTest() { bool unicode = false; string uri = "localhost:6666"; string user = "admin"; string pass = string.Empty; string ws_client = "admin_space"; for (int i = 0; i < 2; i++) // run once for ascii, once for unicode { Process p4d = Utilities.DeployP4TestServer(TestDir, 8, unicode); Server server = new Server(new ServerAddress(uri)); try { Repository rep = new Repository(server); using (Connection con = rep.Connection) { con.UserName = user; con.Client = new Client(); con.Client.Name = ws_client; bool connected = con.Connect(null); Assert.IsTrue(connected); Assert.AreEqual(con.Status, ConnectionStatus.Connected); IList