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 StreamTest and is intended
///to contain all StreamTest Unit Tests
///
[TestClass()]
public class StreamTest
{
private TestContext testContextInstance;
static string id = "//projectX/dev";
static DateTime updated = new DateTime(2011, 04, 10);
static DateTime accessed = new DateTime(2011, 04, 10);
static string ownername = "John Smith";
static string name = "ProjectX development";
static PathSpec parent = new DepotPath("//projectX/main");
static PathSpec baseparent = null;
static StreamType type = StreamType.Development;
static string description = "development stream for experimental work on projectX";
static string firmerthanparent = "n/a";
static string changeflowstoparent = "false";
static string changeflowsfromparent = "false";
static StreamOption options = new StreamOptionEnum(StreamOption.OwnerSubmit | StreamOption.Locked | StreamOption.NoToParent | StreamOption.NoFromParent);
static ViewMap paths = null;
static MapEntry path = new MapEntry(MapType.Share, new DepotPath("//projectX/main"), null);
static ViewMap remapped = null;
static MapEntry remap = new MapEntry(MapType.Include, new DepotPath("//projectX/main"), null);
static ViewMap ignored = null;
static ViewMap view = null;
static MapEntry ig = new MapEntry(MapType.Include, new DepotPath("//projectX/extra"), null);
static FormSpec spec = new FormSpec(new List(), new Dictionary(), new List(), new List(), new Dictionary(),
new Dictionary(), "here are the comments");
static Stream target = null;
static void setTarget()
{
paths = new ViewMap();
paths.Add(path);
remapped = new ViewMap();
remapped.Add(remap);
ignored = new ViewMap();
ignored.Add(ig);
target = new Stream(id, updated, accessed,
ownername, name, parent, baseparent, type, description,
options, firmerthanparent, changeflowstoparent,
changeflowsfromparent,paths, remapped, ignored, view, spec);
}
///
///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,03,01);
setTarget();
Assert.AreEqual(target.Accessed, new DateTime(2011, 04, 10));
target.Accessed = expected;
DateTime actual;
actual = target.Accessed;
Assert.AreEqual(expected, actual);
}
///
///A test for Parse
///
[TestMethod()]
public void ParseTest()
{
string streamForm = "Stream:\t{0}\r\n" +
"\r\n" +
"Update:\t{1}\r\n" +
"\r\n" +
"Access:\t{2}\r\n" +
"\r\n" +
"Owner:\t{3}\r\n" +
"\r\n" +
"Name:\t{4}\r\n" +
"\r\n" +
"Parent:\t{5}\r\n" +
"\r\n" +
"Type:\t{6}\r\n" +
"\r\n" +
"Description:\r\n\t{7}\r\n" +
"\r\n" +
"Options:\t{8}\r\n" +
"\r\n" +
"Paths:\r\n\t{9}\r\n" +
"\r\n" +
"Remapped:\r\n\t{10}\r\n" +
"\r\n" +
"Ignored:\r\n\t{11}\r\n";
String streamData = String.Format(streamForm, "//User/test",
"", "", "user1", "test", "//User/user1_stream", "development",
"created by user1.", "allsubmit unlocked toparent fromparent",
"share ...", "", "");
Stream stream = new Stream();
stream.Parse(streamData);
Assert.AreEqual(stream.OwnerName, "user1");
Assert.AreEqual(stream.Id, "//User/test");
Assert.AreEqual(stream.Name, "test");
}
///
///A test for Description
///
[TestMethod()]
public void DescriptionTest()
{
string expected = "wrong string";
setTarget();
Assert.AreEqual(target.Description, "development stream for experimental work on projectX");
target.Description = expected;
string actual;
actual = target.Description;
Assert.AreEqual(expected, actual);
}
///
///A test for Ignored
///
[TestMethod()]
public void IgnoredTest()
{
MapEntry fs = new MapEntry(MapType.Include, new DepotPath("//projectX/extra"), null);
setTarget();
ViewMap actual;
actual = target.Ignored;
Assert.IsTrue(actual.Contains(fs));
}
///
///A test for Name
///
[TestMethod()]
public void NameTest()
{
string expected = "wrong string";
setTarget();
Assert.AreEqual(target.Name, "ProjectX development");
target.Name = expected;
string actual;
actual = target.Name;
Assert.AreEqual(expected, actual);
}
///
///A test for Options
///
[TestMethod()]
public void OptionsTest()
{
setTarget();
StreamOption actual;
actual = target.Options;
Assert.IsTrue((actual & StreamOption.OwnerSubmit) == StreamOption.OwnerSubmit);
Assert.IsTrue((actual & StreamOption.Locked) == StreamOption.Locked);
Assert.IsTrue((actual & StreamOption.NoToParent) == StreamOption.NoToParent);
Assert.IsTrue((actual & StreamOption.NoFromParent) == StreamOption.NoFromParent);
}
///
///A test for OwnerName
///
[TestMethod()]
public void OwnerNameTest()
{
string expected = "wrong string";
setTarget();
Assert.AreEqual(target.OwnerName, "John Smith");
target.OwnerName = expected;
string actual;
actual = target.OwnerName;
Assert.AreEqual(expected, actual);
}
///
///A test for Parent
///
[TestMethod()]
public void ParentTest()
{
PathSpec expected = new DepotPath("//Wrong/main");
setTarget();
Assert.AreEqual(target.Parent, new DepotPath("//projectX/main"));
target.Parent = expected;
PathSpec actual;
actual = target.Parent;
Assert.AreEqual(expected, actual);
}
///
///A test for Paths
///
[TestMethod()]
public void PathsTest()
{
MapEntry sp = new MapEntry(MapType.Share, new DepotPath("//projectX/main"), null);
setTarget();
ViewMap actual;
actual = target.Paths;
Assert.IsTrue(actual.Contains(sp));
}
///
///A test for Remapped
///
[TestMethod()]
public void RemappedTest()
{
MapEntry re = new MapEntry(MapType.Include, new DepotPath("//projectX/main"), null);
setTarget();
ViewMap actual;
actual = target.Remapped;
Assert.IsTrue(actual.Contains(re));
}
///
///A test for Spec
///
[TestMethod()]
public void SpecTest()
{
setTarget();
string actual = target.Spec.Comments;
string expected = "here are the comments";
Assert.AreEqual(expected, actual);
}
///
///A test for StreamId
///
[TestMethod()]
public void StreamIdTest()
{
string expected = "//projectX/dev";
string actual;
setTarget();
actual = target.Id;
Assert.AreEqual(expected, actual);
}
///
///A test for Type
///
[TestMethod()]
public void TypeTest()
{
StreamType expected = StreamType.Development;
StreamType actual;
setTarget();
actual = target.Type;
Assert.AreEqual(expected, actual);
}
///
///A test for Updated
///
[TestMethod()]
public void UpdatedTest()
{
DateTime expected = new DateTime(2011, 03, 01);
setTarget();
Assert.AreEqual(target.Updated, new DateTime(2011, 04, 10));
target.Updated = expected;
DateTime actual;
actual = target.Updated;
Assert.AreEqual(expected, actual);
}
}
}