using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Xml;
namespace BruSoft.VS2P4.UnitTests
{
[TestClass]
public class P4OptionsDefaultTests
{
///
/// Test a single group with all settings specified.
///
[TestMethod]
public void SingleGroupAllSettings()
{
string xml = "" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"";
XmlReader xmlReader = XmlReader.Create(new StringReader(xml));
UserSettings.UserSettingsXML = xmlReader;
P4OptionsDefaultsProvider defaults = new P4OptionsDefaultsProvider(new List { "TestConfig" });
Assert.IsTrue(defaults.UseP4Config, "UseP4Config should be true.");
Assert.AreEqual(defaults.PerforceServer, "TestServer", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "TestUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "TestWorkspace", "Unexpected value for PerforceWorkspace");
Assert.AreEqual(defaults.WorkspacePath, "TestWorkspacePath", "Unexpected value for WorkspacePath");
}
///
/// Test two groups of settings, with each group providing only some of the values. Test the groups
/// in both possible orders to verify the priorities are correct.
///
[TestMethod]
public void TwoGroupsSomeSettings()
{
string xml = "" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"";
XmlReader xmlReader = XmlReader.Create(new StringReader(xml));
UserSettings.UserSettingsXML = xmlReader;
// Test using group 1 before group 2
P4OptionsDefaultsProvider defaults = new P4OptionsDefaultsProvider(new List { "TestGroup1", "TestGroup2" });
Assert.IsFalse(defaults.UseP4Config, "UseP4Config should be false");
Assert.AreEqual(defaults.PerforceServer, "TestServer1", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "MyUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "AWorkspace", "Unexpected value for PerforceWorkspace");
Assert.AreEqual(defaults.WorkspacePath, "TestWorkspacePath", "Unexpected value for WorkspacePath");
// Test using group 2 before group 1
defaults = new P4OptionsDefaultsProvider(new List { "TestGroup2", "TestGroup1" });
Assert.IsFalse(defaults.UseP4Config, "UseP4Config should be false");
Assert.AreEqual(defaults.PerforceServer, "AServer", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "MyUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "AWorkspace", "Unexpected value for PerforceWorkspace");
Assert.AreEqual(defaults.WorkspacePath, "TestWorkspacePath", "Unexpected value for WorkspacePath");
}
///
/// Test 3 groups in various combinations, where each group contains 2 settings each.
///
[TestMethod]
public void ThreeGroupsTwoEach()
{
string xml = "" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"";
XmlReader xmlReader = XmlReader.Create(new StringReader(xml));
UserSettings.UserSettingsXML = xmlReader;
// Test using group 1, 2, 3
P4OptionsDefaultsProvider defaults = new P4OptionsDefaultsProvider(new List { "TestGroup1", "TestGroup2", "TestGroup3" });
Assert.IsTrue(defaults.UseP4Config, "UseP4Config should be true");
Assert.AreEqual(defaults.PerforceServer, "TestServer1", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "MyUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "AWorkspace", "Unexpected value for PerforceWorkspace");
// Test using group 2, 3, 1
defaults = new P4OptionsDefaultsProvider(new List { "TestGroup2", "TestGroup3", "TestGroup1" });
Assert.IsTrue(defaults.UseP4Config, "UseP4Config should be true");
Assert.AreEqual(defaults.PerforceServer, "AServer", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "MyUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "AWorkspace", "Unexpected value for PerforceWorkspace");
// Test using group 3, 2, 1
defaults = new P4OptionsDefaultsProvider(new List { "TestGroup3", "TestGroup2", "TestGroup1" });
Assert.IsTrue(defaults.UseP4Config, "UseP4Config should be true");
Assert.AreEqual(defaults.PerforceServer, "AServer", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "SomeUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "AWorkspace", "Unexpected value for PerforceWorkspace");
// Test using group 2, 1
defaults = new P4OptionsDefaultsProvider(new List { "TestGroup2", "TestGroup1" });
Assert.IsTrue(defaults.UseP4Config, "UseP4Config should be true");
Assert.AreEqual(defaults.PerforceServer, "AServer", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "MyUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "AWorkspace", "Unexpected value for PerforceWorkspace");
// Test using group 1, 3
defaults = new P4OptionsDefaultsProvider(new List { "TestGroup1", "TestGroup3" });
Assert.IsTrue(defaults.UseP4Config, "UseP4Config should be true");
Assert.AreEqual(defaults.PerforceServer, "TestServer1", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "SomeUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "AWorkspace", "Unexpected value for PerforceWorkspace");
// Test using group 3, 2
defaults = new P4OptionsDefaultsProvider(new List { "TestGroup3", "TestGroup2" });
Assert.IsTrue(defaults.UseP4Config, "UseP4Config should be true");
Assert.AreEqual(defaults.PerforceServer, "AServer", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "SomeUser", "Unexpected value for PerforceUser");
Assert.IsNull(defaults.PerforceWorkspace, "Unexpected value for PerforceWorkspace");
}
///
/// Test 3 groups in various orders.
///
[TestMethod]
public void ThreeGroupsSomeSettings()
{
string xml = "" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"";
XmlReader xmlReader = XmlReader.Create(new StringReader(xml));
UserSettings.UserSettingsXML = xmlReader;
// Test using group 1, 2, 3
P4OptionsDefaultsProvider defaults = new P4OptionsDefaultsProvider(new List { "TestGroup1", "TestGroup2", "TestGroup3" });
Assert.IsFalse(defaults.UseP4Config, "UseP4Config should be false");
Assert.AreEqual(defaults.PerforceServer, "TestServer1", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "MyUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "AWorkspace", "Unexpected value for PerforceWorkspace");
Assert.AreEqual(defaults.WorkspacePath, "TestWorkspacePath", "Unexpected value for WorkspacePath");
// Test using group 2, 3, 1
defaults = new P4OptionsDefaultsProvider(new List { "TestGroup2", "TestGroup3", "TestGroup1" });
Assert.IsTrue(defaults.UseP4Config, "UseP4Config should be true");
Assert.AreEqual(defaults.PerforceServer, "AServer", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "MyUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "MyWorkspace", "Unexpected value for PerforceWorkspace");
Assert.AreEqual(defaults.WorkspacePath, "TestWorkspacePath", "Unexpected value for WorkspacePath");
// Test using group 3, 1
defaults = new P4OptionsDefaultsProvider(new List { "TestGroup3", "TestGroup1" });
Assert.IsTrue(defaults.UseP4Config, "UseP4Config should be true");
Assert.AreEqual(defaults.PerforceServer, "TestServer1", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "SomeUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "MyWorkspace", "Unexpected value for PerforceWorkspace");
Assert.AreEqual(defaults.WorkspacePath, "TestWorkspacePath", "Unexpected value for WorkspacePath");
// Test using group 2, 1
defaults = new P4OptionsDefaultsProvider(new List { "TestGroup2", "TestGroup1" });
Assert.IsFalse(defaults.UseP4Config, "UseP4Config should be false");
Assert.AreEqual(defaults.PerforceServer, "AServer", "Unexpected value for PerforceServer");
Assert.AreEqual(defaults.PerforceUser, "MyUser", "Unexpected value for PerforceUser");
Assert.AreEqual(defaults.PerforceWorkspace, "AWorkspace", "Unexpected value for PerforceWorkspace");
Assert.IsNull(defaults.WorkspacePath, "Unexpected value for WorkspacePath");
}
}
}