using Perforce.P4; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; namespace p4api.net.unit.test { /// ///This is a test class for FileMetaDataTest and is intended ///to contain all FileMetaDataTest Unit Tests /// [TestClass()] public class FileMetaDataTest { private TestContext testContextInstance; static FileResolveAction fileresolveaction = new FileResolveAction(ResolveAction.Unresolved,null,null,44,88); static FileType filetype = new FileType(BaseFileType.Apple, FileTypeModifier.ArchiveTrigger, 44); static int changelistid = 44; static DepotPath movedfile = new DepotPath ("//depot/main/movedfile"); static bool ismapped = true; static bool shelved = true; static FileAction headaction = FileAction.None ; static int headchange = 44; static int headrev = 44; static FileType headtype = filetype; static DateTime headtime = DateTime.MinValue; static DateTime headmodtime = DateTime.MinValue; static int movedrev = 44; static int haverev = 44; static string desc = "foo"; static string digest = "foo"; static int filesize = 44; static FileAction action = FileAction.None; static FileType type = filetype; static string actionowner = "foo"; static int change = 44; static bool resolved = true; static bool unresolved = true; static bool reresolvable = true; static int otheropen = -1; static List otheropenuserclients = new List{"john","mary"}; static bool otherlock = true; static List otherlockuserclients = new List { "john", "mary" }; static List otheractions = new List {FileAction.Add, FileAction.Delete}; static List otherchanges = new List {44}; static bool ourlock = true; static List resolverecords = new List {fileresolveaction}; static Dictionary attributes = new Dictionary(); static Dictionary attributedigests = new Dictionary(); static FileMetaData target = null; static void setTarget() { target = new FileMetaData (movedfile, ismapped, shelved, headaction, headchange, headrev, headtype, headtime, headmodtime, movedrev, haverev, desc, digest, filesize, action, type, actionowner, change, resolved, unresolved, reresolvable, otheropen, otheropenuserclients, otherlock, otherlockuserclients, otheractions, otherchanges, ourlock, resolverecords, attributes, attributedigests, null, null, null, -1, null ); } /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. /// public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } #region Additional test attributes // //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// ///A test for Action /// [TestMethod()] public void ActionTest() { FileAction expected = FileAction.Abandoned; setTarget(); Assert.AreEqual(target.Action, FileAction.None ); target.Action = expected; FileAction actual; actual = target.Action; Assert.AreEqual(expected, actual); } /// ///A test for ActionOwner /// [TestMethod()] public void ActionOwnerTest() { string expected = "action_owner_user"; setTarget(); Assert.AreEqual(target.ActionOwner, "foo"); target.ActionOwner = expected; string actual; actual = target.ActionOwner; Assert.AreEqual(expected , actual); } /// ///A test for Attributes /// [TestMethod()] public void AttributesTest() { setTarget(); target.Attributes.Add("foo", "bar"); Dictionary test = new Dictionary(); test.Add("foo", "bar"); CollectionAssert.AreEqual(target.Attributes, test); } /// ///A test for Change /// [TestMethod()] public void ChangeTest() { int expected = 12345; setTarget(); Assert.AreEqual(target.Change,44); target.Change = expected; int actual = target.Change; Assert.AreEqual(expected, actual); } /// ///A test for Desc /// [TestMethod()] public void DescTest() { string expected = "this is the description"; setTarget(); Assert.AreEqual(target.Desc, "foo"); target.Desc = expected; string actual = target.Desc; Assert.AreEqual(expected, actual); } /// ///A test for Digest /// [TestMethod()] public void DigestTest() { string expected = "this is the digest"; setTarget(); Assert.AreEqual(target.Digest, "foo"); target.Digest = expected; string actual = target.Digest; Assert.AreEqual(expected, actual); } /// ///A test for FileSize /// [TestMethod()] public void FileSizeTest() { int expected = 1024; setTarget(); Assert.AreEqual(target.FileSize, 44); target.FileSize = expected; long actual = target.FileSize; Assert.AreEqual(expected, actual); } /// ///A test for HaveRev /// [TestMethod()] public void HaveRevTest() { int expected = 24; setTarget(); Assert.AreEqual(target.HaveRev, 44); target.HaveRev = expected; int actual = target.HaveRev; Assert.AreEqual(expected, actual); } /// ///A test for HeadAction /// [TestMethod()] public void HeadActionTest() { FileAction expected = FileAction.Import; setTarget(); Assert.AreEqual(target.HeadAction, FileAction.None); target.HeadAction = expected; FileAction actual = target.HeadAction; Assert.AreEqual(expected, actual); } /// ///A test for HeadChange /// [TestMethod()] public void HeadChangeTest() { int expected = 8; setTarget(); Assert.AreEqual(target.HeadChange, 44); target.HeadChange = expected; int actual = target.HeadChange; Assert.AreEqual(expected, actual); } /// ///A test for HeadModTime /// [TestMethod()] public void HeadModTimeTest() { DateTime expected = new DateTime (2011,2,12); setTarget(); Assert.AreEqual(target.HeadModTime, DateTime.MinValue); target.HeadModTime = expected; DateTime actual = target.HeadModTime; Assert.AreEqual(expected, actual); } /// ///A test for HeadRev /// [TestMethod()] public void HeadRevTest() { int expected = 48; setTarget(); Assert.AreEqual(target.HeadRev, 44); target.HeadRev = expected; int actual = target.HeadRev; Assert.AreEqual(expected, actual); } /// ///A test for HeadTime /// [TestMethod()] public void HeadTimeTest() { DateTime expected = new DateTime(2011, 12, 21); setTarget(); Assert.AreEqual(target.HeadTime, DateTime.MinValue); target.HeadTime = expected; DateTime actual = target.HeadTime; Assert.AreEqual(expected, actual); } /// ///A test for HeadType /// [TestMethod()] public void HeadTypeTest() { FileType expected = new FileType(BaseFileType.Unicode, FileTypeModifier.None, 24); setTarget(); Assert.AreEqual(target.HeadType, filetype); target.HeadType = expected; FileType actual = target.HeadType; Assert.AreEqual(expected, actual); } /// ///A test for IsMapped /// [TestMethod()] public void IsMappedTest() { bool expected = false; setTarget(); Assert.AreEqual(target.IsMapped, true); target.IsMapped = expected; bool actual = target.IsMapped; Assert.AreEqual(expected, actual); } /// ///A test for MovedFile /// [TestMethod()] public void MovedFileTest() { DepotPath expected = new DepotPath("//depot/main/file2"); setTarget(); Assert.AreEqual(target.MovedFile, new DepotPath("//depot/main/movedfile")); target.MovedFile = expected; DepotPath actual = target.MovedFile; Assert.AreEqual(expected, actual); } /// ///A test for MovedRev /// [TestMethod()] public void MovedRevTest() { int expected = 28; setTarget(); Assert.AreEqual(target.MovedRev, 44); target.MovedRev = expected; int actual = target.MovedRev; Assert.AreEqual(expected, actual); } /// ///A test for OtherActions /// [TestMethod()] public void OtherActionsTest() { DepotPath movedfile = new DepotPath("//depot/main/movedfile"); bool ismapped=true; bool shelved=true; FileAction headaction = new FileAction(); int headchange= 0; int headrev= 0; FileType headtype = null; DateTime headtime = new DateTime(); DateTime headmodtime= new DateTime(); int movedrev= 0; int haverev= 0; string desc =""; string digest=""; int filesize= 0; FileAction action = FileAction.Abandoned; FileType type= null; string actionowner=""; int change= 0; bool resolved=true; bool unresolved=true; bool reresolvable = true; int otheropen=-1; List otheropenuserclients=null; bool otherlock=true; List otherlockuserclients = null; List otheractions=new List(); FileAction Act1 = FileAction.Abandoned; FileAction Act2 = FileAction.Branch; List otherchanges=null; bool ourlock=true; List resolverecords=null; Dictionary attributes = null; Dictionary attributedigests = null; FileMetaData target = new FileMetaData (movedfile, ismapped, shelved, headaction, headchange, headrev, headtype, headtime, headmodtime, movedrev, haverev, desc, digest, filesize, action, type, actionowner, change, resolved, unresolved, reresolvable, otheropen, otheropenuserclients, otherlock, otherlockuserclients, otheractions, otherchanges, ourlock, resolverecords, attributes, attributedigests, null, null, null, -1, null ); List expected = otheractions; target.OtherActions.Add(Act1); target.OtherActions.Add(Act2); Assert.AreEqual(Act1, target.OtherActions[0]); Assert.AreEqual(Act2, target.OtherActions[1]); IList actual; target.OtherActions = expected; actual = target.OtherActions; Assert.AreEqual(expected, actual); } /// ///A test for OtherChanges /// [TestMethod()] public void OtherChangesTest() { DepotPath movedfile = new DepotPath("//depot/main/movedfile"); bool ismapped = true; bool shelved = true; FileAction headaction = new FileAction(); int headchange = 0; int headrev = 0; FileType headtype = null; DateTime headtime = new DateTime(); DateTime headmodtime = new DateTime(); int movedrev = 0; int haverev = 0; string desc = ""; string digest = ""; int filesize = 0; FileAction action = FileAction.Abandoned; FileType type = null; string actionowner = ""; int change = 0; bool resolved = true; bool unresolved = true; bool reresolvable = true; int otheropen = -1; List otheropenuserclients = null; bool otherlock = true; List otherlockuserclients = null; List otheractions = null; List otherchanges = new List(); int Change1 = 12345; int Change2 = 67890; bool ourlock = true; List resolverecords = null; Dictionary attributes = null; Dictionary attributedigests = null; FileMetaData target = new FileMetaData (movedfile, ismapped, shelved, headaction, headchange, headrev, headtype, headtime, headmodtime, movedrev, haverev, desc, digest, filesize, action, type, actionowner, change, resolved, unresolved, reresolvable, otheropen, otheropenuserclients, otherlock, otherlockuserclients, otheractions, otherchanges, ourlock, resolverecords, attributes, attributedigests, null, null, null, -1, null ); IList expected = otherchanges; target.OtherChanges.Add(Change1); target.OtherChanges.Add(Change2); Assert.AreEqual(Change1, target.OtherChanges[0]); Assert.AreEqual(Change2, target.OtherChanges[1]); IList actual; target.OtherChanges = expected; actual = target.OtherChanges; Assert.AreEqual(expected, actual); } /// ///A test for OtherLock /// [TestMethod()] public void OtherLockTest() { bool expected = false; setTarget(); Assert.AreEqual(target.OtherLock, true); target.OtherLock = expected; bool actual = target.OtherLock; Assert.AreEqual(expected, actual); } /// ///A test for OtherLockUserClients /// [TestMethod()] public void OtherLockUserClientsTest() { DepotPath movedfile = new DepotPath("//depot/main/movedfile"); bool ismapped = true; bool shelved = true; FileAction headaction = new FileAction(); int headchange = 0; int headrev = 0; FileType headtype = null; DateTime headtime = new DateTime(); DateTime headmodtime = new DateTime(); int movedrev = 0; int haverev = 0; string desc = ""; string digest = ""; int filesize = 0; FileAction action = FileAction.Abandoned; FileType type = null; string actionowner = ""; int change = 0; bool resolved = true; bool unresolved = true; bool reresolvable = true; int otheropen = -1; List otheropenuserclients = null; bool otherlock = true; List otherlockuserclients = new List(); string Lock1 = "user1@client1"; string Lock2 = "user2@client2"; List otheractions = null; List otherchanges = null; bool ourlock = true; List resolverecords = null; Dictionary attributes = null; Dictionary attributedigests = null; FileMetaData target = new FileMetaData (movedfile, ismapped, shelved, headaction, headchange, headrev, headtype, headtime, headmodtime, movedrev, haverev, desc, digest, filesize, action, type, actionowner, change, resolved, unresolved, reresolvable, otheropen, otheropenuserclients, otherlock, otherlockuserclients, otheractions, otherchanges, ourlock, resolverecords, attributes, attributedigests, null, null, null, -1, null ); List expected = otherlockuserclients; target.OtherLockUserClients.Add(Lock1); target.OtherLockUserClients.Add(Lock2); Assert.AreEqual(Lock1, target.OtherLockUserClients[0]); Assert.AreEqual(Lock2, target.OtherLockUserClients[1]); IList actual; target.OtherLockUserClients = expected; actual = target.OtherLockUserClients; Assert.AreEqual(expected, actual); } /// ///A test for OtherOpen /// [TestMethod()] public void OtherOpenTest() { int expected = 2; setTarget(); Assert.AreEqual(target.OtherOpen, -1); target.OtherOpen = expected; int actual = target.OtherOpen; Assert.AreEqual(expected, actual); } /// ///A test for OtherOpenUserClients /// [TestMethod()] public void OtherOpenUserClientsTest() { DepotPath movedfile = new DepotPath("//depot/main/movedfile"); bool ismapped = true; bool shelved = true; FileAction headaction = new FileAction(); int headchange = 0; int headrev = 0; FileType headtype = null; DateTime headtime = new DateTime(); DateTime headmodtime = new DateTime(); int movedrev = 0; int haverev = 0; string desc = ""; string digest = ""; int filesize = 0; FileAction action = FileAction.Abandoned; FileType type = null; string actionowner = ""; int change = 0; bool resolved = true; bool unresolved = true; bool reresolvable = true; int otheropen = -1; List otheropenuserclients = new List(); string Open1 = "user1@client1"; string Open2 = "user2@client2"; bool otherlock = true; List otherlockuserclients = null; List otheractions = null; List otherchanges = null; bool ourlock = true; List resolverecords = null; Dictionary attributes = null; Dictionary attributedigests = null; FileMetaData target = new FileMetaData (movedfile, ismapped, shelved, headaction, headchange, headrev, headtype, headtime, headmodtime, movedrev, haverev, desc, digest, filesize, action, type, actionowner, change, resolved, unresolved, reresolvable, otheropen, otheropenuserclients, otherlock, otherlockuserclients, otheractions, otherchanges, ourlock, resolverecords, attributes, attributedigests, null, null, null, -1, null ); List expected = otheropenuserclients; target.OtherOpenUserClients.Add(Open1); target.OtherOpenUserClients.Add(Open2); Assert.AreEqual(Open1, target.OtherOpenUserClients[0]); Assert.AreEqual(Open2, target.OtherOpenUserClients[1]); IList actual; target.OtherOpenUserClients = expected; actual = target.OtherOpenUserClients; Assert.AreEqual(expected, actual); } /// ///A test for OurLock /// [TestMethod()] public void OurLockTest() { bool expected = false; setTarget(); Assert.AreEqual(target.OurLock, true); target.OurLock = expected; bool actual = target.OurLock; Assert.AreEqual(expected, actual); } /// ///A test for ResolveRecords /// [TestMethod()] public void ResolveRecordsTest() { DepotPath movedfile = new DepotPath("//depot/main/movedfile"); bool ismapped = true; bool shelved = true; FileAction headaction = new FileAction(); int headchange = 0; int headrev = 0; FileType headtype = null; DateTime headtime = new DateTime(); DateTime headmodtime = new DateTime(); int movedrev = 0; int haverev = 0; string desc = ""; string digest = ""; int filesize = 0; FileAction action = FileAction.Abandoned; FileType type = null; string actionowner = ""; int change = 0; bool resolved = true; bool unresolved = true; bool reresolvable = true; int otheropen = -1; List otheropenuserclients = null; bool otherlock = true; List otherlockuserclients = null; List otheractions = null; List otherchanges = null; bool ourlock = true; List resolverecords = new List(); FileResolveAction Rec1 = new FileResolveAction (ResolveAction.Ignored, new FileSpec(new DepotPath("main/file1"), new Revision(1)), new FileSpec(new DepotPath("dev/file1"), new Revision(1)), 24, 48); FileResolveAction Rec2 = new FileResolveAction (ResolveAction.CopyFrom, new FileSpec(new DepotPath("rel1/file3"), new Revision(3)), new FileSpec(new DepotPath("main/file3"), new Revision(2)), 24, 48); Dictionary attributes = null; Dictionary attributedigests = null; FileMetaData target = new FileMetaData (movedfile, ismapped, shelved, headaction, headchange, headrev, headtype, headtime, headmodtime, movedrev, haverev, desc, digest, filesize, action, type, actionowner, change, resolved, unresolved, reresolvable, otheropen, otheropenuserclients, otherlock, otherlockuserclients, otheractions, otherchanges, ourlock, resolverecords, attributes, attributedigests, null, null, null, -1, null ); List expected = resolverecords; target.ResolveRecords.Add(Rec1); target.ResolveRecords.Add(Rec2); Assert.AreEqual(Rec1, target.ResolveRecords[0]); Assert.AreEqual(Rec2, target.ResolveRecords[1]); IList actual; target.ResolveRecords = expected; actual = target.ResolveRecords; Assert.AreEqual(expected, actual); } /// ///A test for Resolved /// [TestMethod()] public void ResolvedTest() { bool expected = false; setTarget(); Assert.AreEqual(target.Resolved, true); target.Resolved = expected; bool actual = target.Resolved; Assert.AreEqual(expected, actual); } /// ///A test for Shelved /// [TestMethod()] public void ShelvedTest() { bool expected = false; setTarget(); Assert.AreEqual(target.Shelved, true); target.Shelved = expected; bool actual = target.Shelved; Assert.AreEqual(expected, actual); } /// ///A test for Unresolved /// [TestMethod()] public void UnresolvedTest() { bool expected = false; setTarget(); Assert.AreEqual(target.Unresolved, true); target.Unresolved = expected; bool actual = target.Unresolved; Assert.AreEqual(expected, actual); } /// ///A test for FromFstatCmdTaggedData /// [TestMethod()] public void FromFstatCmdTaggedDataTest() { FileMetaData target = new FileMetaData(); TaggedObject obj = new TaggedObject(); obj["clientFile"] = "c:\\source\\of\\the\\nile.loc"; obj["depotFile"] = "//depot/of/the/nile.loc"; obj["movedFile"] = "//depot/of/the/blue_nile.loc"; obj["isMapped"] = "1"; obj["shelved"] = "1"; obj["headAction"] = "edit"; obj["headChange"] = "12345"; obj["headRev"] = "123"; obj["headType"] = "text"; obj["headTime"] = "1305157570"; obj["headModTime"] = "1305049430"; obj["haveRev"] = "122"; obj["desc"] = "The change of time"; obj["digest"] = "12:12:12:12:12"; obj["fileSize"] = "1234567"; obj["action"] = "edit"; obj["type"] = "text"; obj["actionOwner"] = "Ringo"; obj["change"] = "default"; obj["resolved"] = "1"; obj["unresolved"] = "1"; obj["otherOpen"] = "3"; obj["otherOpen0"] = "John@apple1_records"; obj["otherAction0"] = "edit"; obj["otherChange0"] = "122"; obj["otherOpen1"] = "Paul@apple2_records"; obj["otherAction1"] = "edit"; obj["otherChange1"] = "default"; obj["otherOpen2"] = "George@apple3_records"; obj["otherAction2"] = "edit"; obj["otherChange2"] = "default"; obj["otherLock"] = "1"; obj["otherLock0"] = "Paul@apple2_records"; target.FromFstatCmdTaggedData(obj); Assert.AreEqual("c:\\source\\of\\the\\nile.loc", target.LocalPath.Path); Assert.AreEqual("//depot/of/the/nile.loc", target.DepotPath.Path); Assert.AreEqual("//depot/of/the/blue_nile.loc", target.MovedFile.Path); Assert.IsTrue(target.IsMapped); Assert.IsTrue(target.Shelved); Assert.AreEqual(12345, target.HeadChange); Assert.AreEqual(123, target.HeadRev); Assert.AreEqual(BaseFileType.Text, target.HeadType.BaseType); Assert.AreEqual(FormBase.ConvertUnixTime(1305157570), target.HeadTime); Assert.AreEqual(FormBase.ConvertUnixTime(1305049430), target.HeadModTime); Assert.AreEqual(122, target.HaveRev); Assert.AreEqual("The change of time", target.Desc); Assert.AreEqual("12:12:12:12:12",target.Digest); Assert.AreEqual(1234567,target.FileSize); Assert.AreEqual(FileAction.Edit, target.Action); Assert.AreEqual(BaseFileType.Text, target.Type.BaseType); Assert.AreEqual("Ringo",target.ActionOwner); Assert.AreEqual(0,target.Change); Assert.IsTrue(target.Resolved); Assert.IsTrue(target.Unresolved); Assert.AreEqual(3,target.OtherOpen); Assert.IsTrue(target.OtherUsers.ContainsKey("John@apple1_records")); Assert.AreEqual("John",target.OtherUsers["John@apple1_records"].UserName); Assert.AreEqual("apple1_records",target.OtherUsers["John@apple1_records"].ClientName); Assert.AreEqual(FileAction.Edit,target.OtherUsers["John@apple1_records"].Action); Assert.AreEqual(122,target.OtherUsers["John@apple1_records"].ChangelistId); Assert.IsTrue(target.OtherUsers.ContainsKey("Paul@apple2_records")); Assert.AreEqual("Paul",target.OtherUsers["Paul@apple2_records"].UserName); Assert.AreEqual("apple2_records",target.OtherUsers["Paul@apple2_records"].ClientName); Assert.AreEqual(FileAction.Edit,target.OtherUsers["Paul@apple2_records"].Action); Assert.AreEqual(0,target.OtherUsers["Paul@apple2_records"].ChangelistId); Assert.IsTrue(target.OtherUsers.ContainsKey("George@apple3_records")); Assert.AreEqual("George",target.OtherUsers["George@apple3_records"].UserName); Assert.AreEqual("apple3_records",target.OtherUsers["George@apple3_records"].ClientName); Assert.AreEqual(FileAction.Edit,target.OtherUsers["George@apple3_records"].Action); Assert.AreEqual(0,target.OtherUsers["George@apple3_records"].ChangelistId); Assert.IsTrue(target.OtherUsers["Paul@apple2_records"].hasLock); } } }