本文整理汇总了C#中System.Collections.Dictionary.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.GetValue方法的具体用法?C# Dictionary.GetValue怎么用?C# Dictionary.GetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.GetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplaceTokens
private string ReplaceTokens(Dictionary<string, string> testFields, string url, string tabId)
{
var defaultAlias = testFields.GetValue("DefaultAlias", String.Empty);
var httpAlias = testFields.GetValue("Alias", String.Empty);
var tabName = testFields["Page Name"];
var vanityUrl = testFields.GetValue("VanityUrl", String.Empty);
var homeTabId = testFields.GetValue("HomeTabId", String.Empty);
var userName = testFields.GetValue("UserName", String.Empty);
string userId = String.Empty;
if (!String.IsNullOrEmpty(userName))
{
var user = UserController.GetUserByName(PortalId, userName);
if (user != null)
{
userId = user.UserID.ToString();
}
}
return url.Replace("{alias}", httpAlias)
.Replace("{usealias}", defaultAlias)
.Replace("{tabName}", tabName)
.Replace("{tabId}", tabId)
.Replace("{portalId}", PortalId.ToString())
.Replace("{vanityUrl}", vanityUrl)
.Replace("{userId}", userId)
.Replace("{defaultPage}", _defaultPage);
}
示例2: GetValue_WhenIWantToRetrieveTheValueOfAKeyInADictionary_ReturnValue
public void GetValue_WhenIWantToRetrieveTheValueOfAKeyInADictionary_ReturnValue()
{
//Arrange
Dictionary<string, string> dictionary = new Dictionary<string, string>()
{
{ "Value1", "Result1"},
{ "Value2", "Result2"}
};
var stringValueExpected = "Result1";
var stringKey = "Value1";
//Act
var value = dictionary.GetValue<string, string>(stringKey);
//Assert
Assert.AreEqual(stringValueExpected, value, "Dictionary value test passed");
}
示例3: AdvancedUrlRewriter_JiraTests
public void AdvancedUrlRewriter_JiraTests(Dictionary<string, string> testFields)
{
var testName = testFields.GetValue("Test", String.Empty);
var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", "Jira_Tests", testName + ".csv");
var dictionary = UrlTestFactoryClass.GetDictionary("UrlRewrite", "Jira_Tests", testName + "_dic.csv");
int homeTabId = -1;
foreach (var keyValuePair in dictionary)
{
switch (keyValuePair.Key)
{
case "HomeTabId":
homeTabId = UpdateHomeTab(Int32.Parse(keyValuePair.Value));
break;
default:
break;
}
}
ExecuteTest(settings, testFields, true);
if (homeTabId != -1)
{
UpdateHomeTab(homeTabId);
}
}
示例4: AdvancedUrlRewriter_VanityUrl
public void AdvancedUrlRewriter_VanityUrl(Dictionary<string, string> testFields)
{
var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", testFields["TestName"]);
settings.DeletedTabHandlingType = DeletedTabHandlingType.Do301RedirectToPortalHome;
var vanityUrl = testFields.GetValue("VanityUrl", String.Empty);
var userName = testFields.GetValue("UserName", String.Empty);
var redirectOld = testFields.GetValue("RedirectOldProfileUrl", String.Empty);
if (!String.IsNullOrEmpty(userName))
{
var user = UserController.GetUserByName(PortalId, userName);
if (user != null)
{
user.VanityUrl = vanityUrl;
UserController.UpdateUser(PortalId, user);
}
}
if (!String.IsNullOrEmpty(redirectOld))
{
settings.RedirectOldProfileUrl = Convert.ToBoolean(redirectOld);
}
ExecuteTest(settings, testFields, true);
}
示例5: AdvancedUrlRewriter_ReplaceSpace
public void AdvancedUrlRewriter_ReplaceSpace(Dictionary<string, string> testFields)
{
var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", testFields["TestName"]);
string replaceSpaceWith = testFields.GetValue("ReplaceSpaceWith");
if (!String.IsNullOrEmpty(replaceSpaceWith))
{
settings.ReplaceSpaceWith = replaceSpaceWith;
}
ExecuteTest(settings, testFields, true);
}
示例6: AdvancedUrlRewriter_ReplaceChars
public void AdvancedUrlRewriter_ReplaceChars(Dictionary<string, string> testFields)
{
var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", testFields["TestName"]);
string testPageName = testFields.GetValue("TestPageName");
TabInfo tab = null;
if (!String.IsNullOrEmpty(testPageName))
{
var tabName = testFields["Page Name"];
var tc = new TabController();
tab = tc.GetTabByName(tabName, PortalId);
tab.TabName = testPageName;
tc.UpdateTab(tab);
//Refetch tab from DB
tab = tc.GetTab(tab.TabID, tab.PortalID, false);
}
settings.PortalId = PortalId;
string autoAscii = testFields.GetValue("AutoAscii");
if (!String.IsNullOrEmpty(autoAscii))
{
settings.AutoAsciiConvert = Convert.ToBoolean(autoAscii);
}
TestUtil.GetReplaceCharDictionary(testFields, settings.ReplaceCharacterDictionary);
SetDefaultAlias(testFields);
ExecuteTestForTab(tab, settings, testFields);
}
示例7: AdvancedUrlRewriter_ForceLowerCase
public void AdvancedUrlRewriter_ForceLowerCase(Dictionary<string, string> testFields)
{
var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", testFields["TestName"]);
string forceLowerCaseRegex = testFields.GetValue("ForceLowerCaseRegex");
if (!String.IsNullOrEmpty(forceLowerCaseRegex))
{
settings.ForceLowerCaseRegex = forceLowerCaseRegex;
}
settings.PortalId = PortalId;
ExecuteTest(settings, testFields, true);
}
示例8: AdvancedUrlRewriter_DeletedTabHandling
public void AdvancedUrlRewriter_DeletedTabHandling(Dictionary<string, string> testFields)
{
var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", testFields["TestName"]);
settings.PortalId = PortalId;
var tc = new TabController();
var tab = tc.GetTabByName(_testPage, PortalId);
if (Convert.ToBoolean(testFields["HardDeleted"]))
{
DeleteTab(_testPage);
CacheController.FlushPageIndexFromCache();
}
else
{
tab.IsDeleted = Convert.ToBoolean(testFields["SoftDeleted"]);
tab.DisableLink = Convert.ToBoolean(testFields["Disabled"]);
if (Convert.ToBoolean(testFields["Expired"]))
{
tab.EndDate = DateTime.Now - TimeSpan.FromDays(1);
}
UpdateTab(tab);
}
string deletedTabHandling = testFields.GetValue("DeletedTabHandling");
if (!String.IsNullOrEmpty(deletedTabHandling))
{
switch (deletedTabHandling)
{
case "Do404Error":
settings.DeletedTabHandlingType = DeletedTabHandlingType.Do404Error;
break;
default:
settings.DeletedTabHandlingType = DeletedTabHandlingType.Do301RedirectToPortalHome;
break;
}
}
SetDefaultAlias(testFields);
ExecuteTest(settings, testFields, true);
}
示例9: ExecuteTestForTab
private void ExecuteTestForTab(TabInfo tab, FriendlyUrlSettings settings, Dictionary<string, string> testFields)
{
var httpAlias = testFields.GetValue("Alias", String.Empty);
var scheme = testFields["Scheme"];
var url = testFields["Test Url"];
var result = testFields["Expected Url"];
var expectedStatus = Int32.Parse(testFields["Status"]);
var redirectUrl = testFields.GetValue("Final Url");
var redirectReason = testFields.GetValue("RedirectReason");
var tabID = (tab == null) ? "-1" : tab.TabID.ToString();
var expectedResult = ReplaceTokens(testFields, result, tabID);
var testurl = ReplaceTokens(testFields, url, tabID);
var expectedRedirectUrl = ReplaceTokens(testFields, redirectUrl, tabID);
CreateSimulatedRequest(new Uri(testurl));
var request = HttpContext.Current.Request;
var testHelper = new UrlTestHelper
{
HttpAliasFull = scheme + httpAlias + "/",
Result = new UrlAction(request)
{
IsSecureConnection = request.IsSecureConnection,
RawUrl = request.RawUrl
},
RequestUri = new Uri(testurl),
QueryStringCol = new NameValueCollection()
};
ProcessRequest(settings, testHelper);
//Test expected response status
Assert.AreEqual(expectedStatus, testHelper.Response.StatusCode);
switch (expectedStatus)
{
case 200:
//Test expected rewrite path
if (!String.IsNullOrEmpty(expectedResult))
{
Assert.AreEqual(expectedResult, testHelper.Result.RewritePath.TrimStart('/'));
}
break;
case 301:
case 302:
//Test for final Url if redirected
Assert.AreEqual(expectedRedirectUrl, testHelper.Result.FinalUrl.TrimStart('/'));
Assert.AreEqual(redirectReason, testHelper.Result.Reason.ToString(), "Redirect reason incorrect");
break;
}
}
示例10: AddPersonFilmIndexes
public static void AddPersonFilmIndexes(this List<Person> peopleFilmIndexesToAdd, int filmID, Dictionary<string, string> castCharacters, int roleID )
{
foreach (Person person in peopleFilmIndexesToAdd)
{
Context.AddToPersonFilmIndexes(
new PersonFilmIndex
{
FilmID = filmID,
PersonID = person.PersonID,
Character = castCharacters.GetValue(string.Format("{0} {1}", person.FirstName, person.LastName)),
RoleID = roleID
}
);
}
}
示例11: get_nullable_datetime
public void get_nullable_datetime()
{
var collection = new Dictionary<string, DateTime?> { { "startDate", null } };
var value = collection.GetValue<DateTime?>("startDate");
Expect(value, Is.Null);
}
示例12: get_null_string_without_default
public void get_null_string_without_default()
{
var collection = new Dictionary<string, string> { { "app id", null } };
var value = collection.GetValue<string>("app id");
Expect(value, Is.Null);
}
示例13: GetValue_DictionaryContainsKey_ReturnsExistingValue
public void GetValue_DictionaryContainsKey_ReturnsExistingValue()
{
var key = new object();
var value = new object();
var dictionary = new Dictionary<object, object> { {key, value} };
var result = dictionary.GetValue(key, () => null);
Assert.That(result, Is.SameAs(value));
}
示例14: GetValue_DictionaryContainsKey_GetValueToAddIsNotCalled
public void GetValue_DictionaryContainsKey_GetValueToAddIsNotCalled()
{
int counter = 0;
var key = new object();
var dictionary = new Dictionary<object, object> { { key, null } };
dictionary.GetValue(key, () =>
{
counter++;
return null;
});
Assert.That(counter, Is.EqualTo(0));
}
示例15: ExecuteTestForTab
private void ExecuteTestForTab(TabInfo tab, FriendlyUrlSettings settings, Dictionary<string, string> testFields)
{
var defaultAlias = testFields.GetValue("DefaultAlias", String.Empty);
var httpAlias = testFields.GetValue("Alias", String.Empty);
var tabName = testFields["Page Name"];
var scheme = testFields["Scheme"];
var url = testFields["Test Url"];
var result = testFields["Expected Url"];
var expectedStatus = Int32.Parse(testFields["Status"]);
var redirectUrl = testFields.GetValue("Final Url");
var redirectReason = testFields.GetValue("RedirectReason");
var vanityUrl = testFields.GetValue("VanityUrl", String.Empty);
var tabID = (tab == null) ? "-1" : tab.TabID.ToString();
var userName = testFields.GetValue("UserName", String.Empty);
string userId = String.Empty;
if (!String.IsNullOrEmpty(userName))
{
var user = UserController.GetUserByName(PortalId, userName);
if (user != null)
{
userId = user.UserID.ToString();
}
}
var expectedResult = ReplaceTokens(result, httpAlias, defaultAlias, tabName, tabID, PortalId.ToString(), vanityUrl, userId);
var testurl = ReplaceTokens(url, httpAlias, defaultAlias, tabName, tabID, PortalId.ToString(), vanityUrl, userId);
var expectedRedirectUrl = ReplaceTokens(redirectUrl, httpAlias, defaultAlias, tabName, tabID, PortalId.ToString(), vanityUrl, userId);
CreateSimulatedRequest(new Uri(testurl));
var testHelper = new UrlTestHelper
{
HttpAliasFull = scheme + httpAlias + "/",
Result = new UrlAction(scheme, scheme + httpAlias, Globals.ApplicationMapPath)
{
IsSecureConnection = HttpContext.Current.Request.IsSecureConnection,
RawUrl = HttpContext.Current.Request.RawUrl
},
RequestUri = new Uri(testurl),
QueryStringCol = new NameValueCollection()
};
ProcessRequest(settings, testHelper);
//Test expected response status
Assert.AreEqual(expectedStatus, testHelper.Response.StatusCode);
switch (expectedStatus)
{
case 200:
//Test expected rewrite path
if (!String.IsNullOrEmpty(expectedResult))
{
Assert.AreEqual(expectedResult, testHelper.Result.RewritePath);
}
break;
case 301:
case 302:
//Test for final Url if redirected
Assert.AreEqual(expectedRedirectUrl, testHelper.Result.FinalUrl);
Assert.AreEqual(redirectReason, testHelper.Result.Reason.ToString(), "Redirect reason incorrect");
break;
}
}