using Perforce.P4; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; namespace p4api.net.unit.test { /// ///This is a test class for BranchSpecTest and is intended ///to contain all BranchSpecTest Unit Tests /// [TestClass()] public class BranchSpecTest { private TestContext testContextInstance; static string id = "newBranch"; static string owner = "admin"; static DateTime updated = new DateTime(2011, 03, 21); static DateTime accessed = new DateTime(2011, 03, 21); static string description = "created by admin"; static bool locked = true; static ViewMap viewmap = new ViewMap() {"//depot/main/... //depot/rel1/...", "//depot/dev/... //depot/main/..."}; static FormSpec spec = null; static string options = "locked"; static BranchSpec target = null; static void setTarget() { target = new BranchSpec( id, owner, updated, accessed, description, locked, viewmap, spec, options); } /// ///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 Accessed /// [TestMethod()] public void AccessedTest() { DateTime expected = new DateTime(2011, 02, 17); setTarget(); Assert.AreEqual(target.Accessed, new DateTime(2011, 03, 21)); target.Accessed = expected; DateTime actual = target.Accessed; Assert.AreEqual(expected, actual); } /// ///A test for Description /// [TestMethod()] public void DescriptionTest() { string expected = "description"; setTarget(); Assert.AreEqual(target.Description, "created by admin"); target.Description = expected; string actual = target.Description; Assert.AreEqual(expected, actual); } /// ///A test for Id /// [TestMethod()] public void IdTest() { string expected = "branchname"; setTarget(); Assert.AreEqual(target.Id, "newBranch"); target.Id = expected; string actual = target.Id; Assert.AreEqual(expected, actual); } /// ///A test for Locked /// [TestMethod()] public void LockedTest() { bool expected = false; setTarget(); Assert.AreEqual(target.Locked, true); target.Locked = expected; bool actual = target.Locked; Assert.AreEqual(expected, actual); } /// ///A test for Options /// [TestMethod()] public void OptionsTest() { string expected = "unlocked"; setTarget(); Assert.AreEqual(target.Options, "locked"); target.Locked = true; bool actual = target.Locked; Assert.AreEqual(true, actual); } /// ///A test for Owner /// [TestMethod()] public void OwnerTest() { string expected = "perforce"; setTarget(); Assert.AreEqual(target.Owner, "admin"); target.Owner = expected; string actual = target.Owner; Assert.AreEqual(expected, actual); } /// ///A test for Updated /// [TestMethod()] public void UpdatedTest() { DateTime expected = new DateTime(2011, 02, 17); setTarget(); Assert.AreEqual(target.Updated, new DateTime(2011, 03, 21)); target.Updated = expected; DateTime actual = target.Updated; Assert.AreEqual(expected, actual); } /// ///A test for ViewMap /// [TestMethod()] public void ViewMapTest() { ViewMap expected = new ViewMap() { "//depot/... //build/..." }; setTarget(); Assert.AreEqual(target.ViewMap.Count, 2); target.ViewMap = expected; ViewMap actual = target.ViewMap; Assert.AreEqual(expected, actual); } /// ///A test for plus mappings /// [TestMethod()] public void PlusMapTest() { ViewMap expected = new ViewMap() { "+//depot/... //build/..." }; setTarget(); Assert.AreEqual(target.ViewMap.Count, 2); target.ViewMap = expected; ViewMap actual = target.ViewMap; Assert.AreEqual(expected, actual); } /// ///A test for minus mappings /// [TestMethod()] public void MinusMapTest() { ViewMap expected = new ViewMap() { "-//depot/... //build/..." }; setTarget(); Assert.AreEqual(target.ViewMap.Count, 2); target.ViewMap = expected; ViewMap actual = target.ViewMap; Assert.AreEqual(expected, actual); } /// ///A test for special characters in branchspec name /// [TestMethod()] public void SpecialCharsIdTest() { string expected = "#/@"; setTarget(); Assert.AreEqual(target.Id, "newBranch"); target.Id = expected; string actual = target.Id; Assert.AreEqual(expected, actual); } } }