- Sources.zip
- GeneratedCrawler.Sample
- GeneratedCrawler.Sample.sln
- GeneratedCrawler.Sample.suo
- GeneratedCrawler.Sample.vsmdi
- GeneratedCrawler.Sample
- GeneratedCrawler.Tests
- LightWebTestFramework
- bin
- Debug
- Release
- LightWebTestFramework.csproj
- Microsoft.VisualStudio.QualityTools.WebTestFramework
- Microsoft.VisualStudio.TestTools.WebTesting.Rules
- Microsoft.VisualStudio.TestTools.WebTesting
- obj
- Debug
- Properties
- WebTesting.Properties.Resources.resources
- Local.testsettings
- TraceAndTestImpact.testsettings
|
using System;
using System.Globalization;
namespace LightWebTestFramework.Rules
{
[LocalizableDescription("ConditionalRuleDescriptionProbabilityRule"), LocalizableDisplayName("ConditionalRuleNameProbabilityRule")]
public class ProbabilityRule : ConditionalRule
{
private string m_contextParameterName;
private double m_percentage;
private static Random s_random = new Random();
[LocalizableDescription("PropertyDescriptionProbabilityContextParameterName"), LocalizableDisplayName("PropertyNameContextParameterName"), IsContextParameterName(true)]
public string ContextParameterName
{
get
{
return this.m_contextParameterName;
}
set
{
this.m_contextParameterName = value;
}
}
[LocalizableDescription("PropertyDescriptionPercentage"), LocalizableDisplayName("PropertyNamePercentage")]
public double Percentage
{
get
{
return this.m_percentage;
}
set
{
this.m_percentage = value;
}
}
public override void CheckCondition(object sender, ConditionalEventArgs e)
{
if (this.m_percentage < 0.0 || this.m_percentage > 100.0)
{
e.IsMet = false;
string message = string.Format(CultureInfo.CurrentCulture, Resources.ErrorInvalidPercentageValues, new object[]
{
this.m_contextParameterName
});
throw new ConditionalRuleException(message);
}
double num = ProbabilityRule.s_random.NextDouble() * 100.0;
if (e.WebTest.Context.ContainsKey(this.m_contextParameterName))
{
e.WebTest.Context[this.m_contextParameterName] = num;
}
else
{
e.WebTest.Context.Add(this.m_contextParameterName, num);
}
if (num < this.m_percentage)
{
e.IsMet = true;
return;
}
e.IsMet = false;
}
public override string StringRepresentation()
{
return string.Format(CultureInfo.CurrentCulture, Resources.StringRepresentationProbabilityRule, new object[]
{
this.m_percentage
});
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am currently the CTO of
Metaco, we are leveraging the Bitcoin Blockchain for delivering financial services.
I also developed a tool to make IaaS on Azure more easy to use
IaaS Management Studio.
If you want to contact me, go
this way