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 CreateGroup
///
[TestMethod()]
public void CreateGroupTest()
{
bool unicode = false;
string uri = "localhost:6666";
string user = "admin";
string pass = string.Empty;
string ws_client = "admin_space";
string targetGroup = "thenewguys";
for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
{
Process p4d = Utilities.DeployP4TestServer(TestDir, 7, 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);
Group u = new Group();
u.Id = targetGroup;
u.UserNames = new List { "Alex" };
u.OwnerNames = new List { "Alex" };
u.MaxResults = 9999;
//GroupOptions uFlags = new GroupOptions(GroupFlags.Force);
Group newGuy = rep.CreateGroup(u, null);
Assert.IsNotNull(newGuy);
Assert.AreEqual(targetGroup, newGuy.Id);
}
}
finally
{
Utilities.RemoveTestServer(p4d, TestDir);
}
unicode = !unicode;
}
}
///
///A test for DeleteGroup
///
[TestMethod()]
public void DeleteGroupTest()
{
bool unicode = false;
string uri = "localhost:6666";
string user = "admin";
string pass = string.Empty;
string ws_client = "admin_space";
string targetGroup = "deleteme";
for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
{
Process p4d = Utilities.DeployP4TestServer(TestDir, 7, 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);
Group u = new Group();
u.Id = targetGroup;
u.UserNames = new List { "Alex" };
u.OwnerNames = new List { "Alex" };
u.MaxResults = 9999;
Group newGuy = rep.CreateGroup(u, null);
IList u2 = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));
Assert.IsNotNull(u2);
Assert.AreEqual(2, u2.Count);
rep.DeleteGroup(u, null);
u2 = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));
Assert.IsNotNull(u2);
Assert.AreEqual(1, u2.Count);
}
}
finally
{
Utilities.RemoveTestServer(p4d, TestDir);
}
unicode = !unicode;
}
}
///
///A test for GetGroup
///
[TestMethod()]
public void GetGroupTest()
{
bool unicode = false;
string uri = "localhost:6666";
string user = "admin";
string pass = string.Empty;
string ws_client = "admin_space";
string targetGroup = "everyone";
for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
{
Process p4d = Utilities.DeployP4TestServer(TestDir, 6, 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);
Group u = rep.GetGroup(targetGroup, null);
Assert.IsNotNull(u);
Assert.AreEqual(targetGroup, u.Id);
}
}
finally
{
Utilities.RemoveTestServer(p4d, TestDir);
}
unicode = !unicode;
}
}
///
///A test for GetGroups
///
[TestMethod()]
public void GetGroupsTest()
{
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, 6, 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 u = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));
Assert.IsNotNull(u);
Assert.AreEqual(1, u.Count);
}
}
finally
{
Utilities.RemoveTestServer(p4d, TestDir);
}
unicode = !unicode;
}
}
}
}