public void TestParams_Partial(int i, Expected expected) { if(_reversableTrue) Assert.True(i > 3, String.Format("expected {0} to be greater than 3", i)); else Assert.True(i <= 3, String.Format("expected {0} to be less than 3", i)); }
private static string Differences(Parse theActual, Parse theExpected) { if (theActual == null) { return (theExpected != null ? FormatNodeDifference(theActual, theExpected) : string.Empty); } if (theExpected == null) { return FormatNodeDifference(theActual, theExpected); } var actualString = theActual.ToString().Replace("\n", string.Empty).Replace("\r", string.Empty); var expectedString = theExpected.ToString().Replace("\n", string.Empty).Replace("\r", string.Empty); if (actualString == expectedString) return string.Empty; var expected = new Expected(theExpected); if (theActual.Tag != expected.Node.Tag) { return FormatNodeDifference(theActual, expected.Node); } string result = BodyDifferences(theActual.Body, expected.Node.Body); if (result.Length > 0) { return string.Format("in {0} body, {1}", theActual.Tag, result); } result = Differences(theActual.Parts, theExpected.Parts); if (result.Length > 0) { return string.Format("in {0}, {1}", theActual.Tag, result); } return Differences(theActual.More, theExpected.More); }
public void SetUp() { formatter = Smart.CreateDefaultSmartFormat(); formatter.ErrorAction = ErrorAction.ThrowError; formatter.FormatterExtensions.Insert(0, ExpectedFormatter.Instance); expected = Substitute.For<Expected>(); expected.Value.Returns("value"); }
public void Dispose() { Expected?.Dispose(); Subject?.Dispose(); }
public void TestParams_Partial(int i, Expected expected) { Assert.True(i > 3, String.Format("expected {0} to be greater than 3", i)); }
public void Range(int i, Expected result) { Assert.That(i,Is.InRange(1,4)); }
private void DoCheckActualError(XmlNode error, List<Expected> unexpectedErrors) { string checkID = "", fullName = "", typeName = ""; foreach (XmlNode child in error.ChildNodes) { if (child.Name == "Location") { fullName = child.Attributes["name"].Value; int i = fullName.IndexOf(' '); if (i >= 0) fullName = fullName.Substring(i + 1); } else if (child.Name == "Violation") { checkID = child.Attributes["checkID"].Value; typeName = child.Attributes["typeName"].Value; } } // Console.WriteLine("actual {0} {1}", checkID, fullName); Expected err = new Expected(checkID, fullName, typeName); m_actual.Add(err); }
public override void WriteRollback(DdlRules rules, TextWriter writer) { if (Actual == null) { Expected.WriteDropStatement(rules, writer); return; } foreach (var foreignKey in ForeignKeys.Missing) { foreignKey.WriteDropStatement(Expected, writer); } foreach (var change in ForeignKeys.Different) { change.Expected.WriteDropStatement(Expected, writer); } // Extra columns foreach (var column in Columns.Extras) { writer.WriteLine(column.AddColumnSql(Expected)); } // Different columns foreach (var change1 in Columns.Different) { writer.WriteLine(change1.Actual.AlterColumnTypeSql(Actual, change1.Expected)); } foreach (var change in ForeignKeys.Different) { change.Actual.WriteAddStatement(Expected, writer); } rollbackIndexes(writer); // Missing columns foreach (var column in Columns.Missing) { writer.WriteLine(column.DropColumnSql(Expected)); } foreach (var foreignKey in ForeignKeys.Extras) { foreignKey.WriteAddStatement(Expected, writer); } switch (PrimaryKeyDifference) { case SchemaPatchDifference.Invalid: case SchemaPatchDifference.Update: writer.WriteLine($"alter table {Expected.Identifier} drop constraint if exists {Expected.PrimaryKeyName};"); writer.WriteLine($"alter table {Expected.Identifier} add {Actual.PrimaryKeyDeclaration()};"); break; case SchemaPatchDifference.Create: writer.WriteLine($"alter table {Expected.Identifier} drop constraint if exists {Expected.PrimaryKeyName};"); break; } }
private static void OutputExpectedExpression(Expected expected, IOutput output, FormatDetails formatDetails) { output.Write(expected.Expression + Environment.NewLine + NewLineIndent(output), formatDetails); }
public string GetSolution() { return(Expected.ToString()); }
public override bool Validate() { return((Expected == null) ? string.IsNullOrEmpty(Actual) : Expected.Contains(Actual ?? string.Empty)); }
public async Task CsrfValidateAntiForgeryTokenIgnoreOnBaseClass() { var cSharpTest = $@" using {Namespace}; namespace VulnerableApp {{ [IgnoreAntiforgeryTokenAttribute] public class BaseController : Controller {{ [HttpPost] public virtual void ControllerMethod(string input) {{ }} }} public class TestController : BaseController {{ [HttpPost] public override void ControllerMethod(string input) {{ }} }} }} "; var visualBasicTest = $@" Imports {Namespace} Namespace VulnerableApp <IgnoreAntiforgeryTokenAttribute> _ Public Class BaseController Inherits Controller <HttpPost> _ Public Overridable Sub ControllerMethod(input As String) End Sub End Class Public Class TestController Inherits BaseController <HttpPost> _ Public Overrides Sub ControllerMethod(input As String) End Sub End Class End Namespace "; await VerifyCSharpDiagnostic(cSharpTest, new[] { Expected.WithLocation(10, 29).WithMessage(AuditMessage), Expected.WithLocation(17, 30).WithMessage(AuditMessage) }, Options).ConfigureAwait(false); await VerifyVisualBasicDiagnostic(visualBasicTest, new[] { Expected.WithLocation(10, 32).WithMessage(AuditMessage), Expected.WithLocation(18, 30).WithMessage(AuditMessage) }, Options).ConfigureAwait(false); }
public override void When() { Expected = DateTime.Today; Actual = TypeParser.Parse <DateTime?>(Expected.ToString()); }
public DateTime?GetNextRunDate(ScheduleInfo scheduleInfo, Schedule schedule, DateTime?lastFromDate) { var curDate = scheduleInfo.ScheduleFromDate.Value; if (lastFromDate.HasValue) { curDate = lastFromDate.Value; } var curTime = DateTime.Parse(Time); var curDateTime = new DateTime(curDate.Year, curDate.Month, curDate.Day, curTime.Hour, curTime.Minute, curTime.Second); var nextDateTime = curDateTime; switch (Expected.ToLowerInvariant()) { case "daily": if (lastFromDate.HasValue && lastFromDate.Value == curDateTime) { try { return(nextDateTime.AddDays(1)); } catch { return(null); } } if (IsGoodTimeForToday(nextDateTime)) { return(nextDateTime); } try { return(nextDateTime.AddDays(1)); } catch { return(null); } case "weekly": if (lastFromDate.HasValue && lastFromDate.Value == curDateTime) { try { nextDateTime = nextDateTime.AddDays(1); } catch { return(null); } } if (IsGoodDayOfWeek(nextDateTime) && IsGoodTimeForToday(nextDateTime)) { return(nextDateTime); } while (!IsGoodDayOfWeek(nextDateTime)) { try { nextDateTime = nextDateTime.AddDays(1); } catch { return(null); } } return(nextDateTime); case "monthly": if (lastFromDate.HasValue && lastFromDate.Value == curDateTime) { try { nextDateTime = nextDateTime.AddDays(1); } catch { return(null); } } if (IsGoodMonthOfYear(nextDateTime) && IsGoodDayOfMonth(nextDateTime) && IsGoodTimeForToday(nextDateTime)) { return(nextDateTime); } while (!(IsGoodMonthOfYear(nextDateTime) && IsGoodDayOfMonth(nextDateTime))) { try { nextDateTime = nextDateTime.AddDays(1); } catch { return(null); } } return(nextDateTime); } return(null); }
public void TestMethod2() { Input.AppendLine("12"); Expected.AppendLine("unlucky"); Test(); }
private static void OutputExpectedValue(Expected expected, IOutput output, FormatDetails formatDetails) { output.Write(string.Empty + expected.Value, formatDetails); }
public void Setup() { Expected = CreateExpected(); Actual = Expected.Clone(new Uri("http://overridden")).Result; }
private static void OutputFormattedExpected(object current, Format format, IOutput output, FormatDetails formatDetails, Expected expected) { formatDetails.Formatter.Format(output, format, current, formatDetails); }
public bool Equals(Expected rhs) { return this == rhs; }
private bool ParseInternal(StringBuilder actualUrl, ref int index, ref int lastDelimiter, ref Expected expectedToken) { char currentChar = actualUrl[index]; switch (currentChar) { default: if (currentChar != SegmentSeparator) { ProcessNonPathChar(actualUrl, index, expectedToken); return false; } if (Scheme.Length > 0) { FinalizeHostOrPort(actualUrl, index, lastDelimiter, ref expectedToken); } ParsePath(actualUrl, index); index = actualUrl.Length; return true; case '%': index = DecodeEscape(actualUrl, index); return false; case ':': lastDelimiter = FinalizeUserNameOrHost(actualUrl, index, lastDelimiter, ref expectedToken); return false; case '@': lastDelimiter = FinalizeUserNameOrPassword(actualUrl, index, lastDelimiter, ref expectedToken); return false; } }
public void TestMethod3() { Input.AppendLine("2 4"); Expected.AppendLine("0"); Test(); }
private void ProcessNonPathChar(StringBuilder actualUrl, int index, Expected expectedToken) { char currentChar = actualUrl[index]; if ((((expectedToken & Expected.Host) == Expected.Host) && (!HostAllowed.Contains(currentChar))) || (((expectedToken & (Expected.UserName | Expected.Password)) != Expected.Nothing) && (!LoginAllowed.Contains(currentChar))) || (((expectedToken & Expected.Port) == Expected.Port) && (!Char.IsDigit(currentChar)))) { throw new ArgumentOutOfRangeException("url", "Passed url is malformed."); } }
public Case( string path, Expected expected ) { this.fetchUri = GetUrl(path); this.expected = expected; }
private int FinalizeUserNameOrPassword(StringBuilder actualUrl, int index, int lastDelimiter, ref Expected expectedToken) { if (!SupportsLogin) { throw new ArgumentOutOfRangeException("url", "Passed url is malformed."); } if ((expectedToken & Expected.Password) == Expected.Password) { Password = actualUrl.ToString(lastDelimiter, index - lastDelimiter); expectedToken = Expected.Host; return index + 1; } if ((expectedToken & Expected.UserName) == Expected.UserName) { UserName = actualUrl.ToString(lastDelimiter, index - lastDelimiter); expectedToken = Expected.Host; return index + 1; } throw new ArgumentOutOfRangeException("url", "Passed url is malformed."); }
public void TestMethod(Expected e) { }
private int FinalizeUserNameOrHost(StringBuilder actualUrl, int index, int lastDelimiter, ref Expected expectedToken) { if (((expectedToken & Expected.UserName) == Expected.UserName) && (SupportsLogin)) { UserName = actualUrl.ToString(lastDelimiter, index - lastDelimiter); expectedToken = Expected.Password; return index + 1; } if ((expectedToken & Expected.Host) == Expected.Host) { Host = actualUrl.ToString(lastDelimiter, index - lastDelimiter).ToLowerInvariant(); expectedToken = Expected.Port; return index + 1; } throw new ArgumentOutOfRangeException("url", "Passed url is malfored."); }
public ExpectedResponse(Expected <Response> onTag, Option <Unit> onError, Option <M> onResult) { OnTag = onTag; OnError = onError; OnResult = onResult; }
private void FinalizeHostOrPort(StringBuilder actualUrl, int index, int lastDelimiter, ref Expected expectedToken) { if ((expectedToken & Expected.Host) == Expected.Host) { if ((Host = actualUrl.ToString(lastDelimiter, index - lastDelimiter).ToLowerInvariant()).Length == 0) { throw new ArgumentOutOfRangeException("url", "Passed url is malformed."); } } else if ((expectedToken & Expected.Port) == Expected.Port) { string port = actualUrl.ToString(lastDelimiter, index - lastDelimiter); if (port.Length == 0) { throw new ArgumentOutOfRangeException("url", "Passed url is malfored."); } Port = UInt16.Parse(port); } else { throw new ArgumentOutOfRangeException("url", "Passed url is malformed."); } expectedToken = Expected.Path; }
public bool IsEquivalent(IRecurrenceProvider compareProvider) { RecurringProvider compareRP = compareProvider as RecurringProvider; if (compareRP == null) { return(false); } var thisTime = string.IsNullOrWhiteSpace(Time) ? "" : Time.Trim().ToLowerInvariant(); var compareTime = string.IsNullOrWhiteSpace(compareRP.Time) ? "" : compareRP.Time.Trim().ToLowerInvariant(); var thisExpected = string.IsNullOrWhiteSpace(Expected) ? "" : Expected.Trim().ToLowerInvariant(); var compareExpected = string.IsNullOrWhiteSpace(compareRP.Expected) ? "" : compareRP.Expected.Trim().ToLowerInvariant(); var thisExpectedWhen = string.IsNullOrWhiteSpace(ExpectedWhen) ? "" : ExpectedWhen.Trim().ToLowerInvariant(); var compareExpectedWhen = string.IsNullOrWhiteSpace(compareRP.ExpectedWhen) ? "" : compareRP.ExpectedWhen.Trim().ToLowerInvariant(); var thisExpectedEveryDays = ExpectedEveryDays == null ? new List <int>() : ExpectedEveryDays; var compareExpectedEveryDays = compareRP.ExpectedEveryDays == null ? new List <int>() : compareRP.ExpectedEveryDays; var thisExpectedEveryMonths = ExpectedEveryMonths == null ? new List <int>() : ExpectedEveryMonths; var compareExpectedEveryMonths = compareRP.ExpectedEveryMonths == null ? new List <int>() : compareRP.ExpectedEveryMonths; var thisExpectedEveryMonthsOnDays = ExpectedEveryMonthsOnDays == null ? new List <int>() : ExpectedEveryMonthsOnDays; var compareExpectedEveryMonthsOnDays = compareRP.ExpectedEveryMonthsOnDays == null ? new List <int>() : compareRP.ExpectedEveryMonthsOnDays; return(thisTime == compareTime && thisExpected == compareExpected && thisExpectedWhen == compareExpectedWhen && thisExpectedEveryDays.HasSameContent(compareExpectedEveryDays) && thisExpectedEveryMonths.HasSameContent(compareExpectedEveryMonths) && thisExpectedEveryMonthsOnDays.HasSameContent(compareExpectedEveryMonthsOnDays)); }
public void TestMethod2() { Input.AppendLine("3 4"); Expected.AppendLine("NG"); Test(); }
public void TestMethod2() { Input.AppendLine("2 7"); Expected.AppendLine("ng"); Test(); }
public override string ToString() { return($"Input: [{InputData.EnumerableToString()}], Expected: [{Expected.EnumerableToString()}], Label: {Label}"); }
public void TestMethod1() { Input.AppendLine("7"); Expected.AppendLine("lucky"); Test(); }
public void Range(int i, Expected result) { Assert.That(i, Is.InRange(1, 4)); }
public override void WriteUpdate(DdlRules rules, TextWriter writer) { if (Difference == SchemaPatchDifference.Invalid) { throw new InvalidOperationException($"TableDelta for {Expected.Identifier} is invalid"); } if (Difference == SchemaPatchDifference.Create) { SchemaObject.WriteCreateStatement(rules, writer); return; } // Extra indexes foreach (var extra in Indexes.Extras) { writer.WriteDropIndex(Expected, extra); } // Different indexes foreach (var change in Indexes.Different) { writer.WriteDropIndex(Expected, change.Actual); } // Missing columns foreach (var column in Columns.Missing) { writer.WriteLine(column.AddColumnSql(Expected)); } // Different columns foreach (var change1 in Columns.Different) { writer.WriteLine(change1.Expected.AlterColumnTypeSql(Expected, change1.Actual)); } writeForeignKeyUpdates(writer); // Missing indexes foreach (var indexDefinition in Indexes.Missing) { writer.WriteLine(indexDefinition.ToDDL(Expected)); } // Different indexes foreach (var change in Indexes.Different) { writer.WriteLine(change.Expected.ToDDL(Expected)); } // Extra columns foreach (var column in Columns.Extras) { writer.WriteLine(column.DropColumnSql(Expected)); } switch (PrimaryKeyDifference) { case SchemaPatchDifference.Invalid: case SchemaPatchDifference.Update: writer.WriteLine($"alter table {Expected.Identifier} drop constraint {Actual.PrimaryKeyName};"); writer.WriteLine($"alter table {Expected.Identifier} add {Expected.PrimaryKeyDeclaration()};"); break; case SchemaPatchDifference.Create: writer.WriteLine($"alter table {Expected.Identifier} add {Expected.PrimaryKeyDeclaration()};"); break; } }
public void InlineInRange(int i, Expected result) { Assert.InRange(i, 0, 2); }
public string GetSolution() { return(Expected == null?string.Empty: Expected.ToString()); }
public void PropertyInRange(int i, Expected result) { Assert.InRange(i, 0, 2); }
private void DoGetExpected(XmlDocument xml) { foreach (XmlNode child in xml.ChildNodes) // need this retarded loop because m_settings.IgnoreComments doesn't appear to do anything { if (child.Name == "Expectations") { foreach (XmlNode grandchild in child.ChildNodes) { if (grandchild.Name == "Expected") { string checkID = grandchild.Attributes["checkID"].Value; string fullName = grandchild.Attributes["fullName"].Value; string typeName = grandchild.Attributes["typeName"].Value; bool shouldPass = false, shouldFail = false; Expected e = new Expected(checkID, fullName, typeName); if (grandchild.Attributes["shouldPass"] != null) { string value = grandchild.Attributes["shouldPass"].Value; shouldPass = value == "true" || value == "1"; } if (grandchild.Attributes["shouldFail"] != null) { string value = grandchild.Attributes["shouldFail"].Value; shouldFail = value == "true" || value == "1"; } if (shouldPass) m_shouldPass.Add(e); else if (shouldFail) m_shouldFail.Add(e); else m_expected.Add(e); } } } } }
public void ClassLessInRange(int i, Expected result) { Assert.InRange(i, 0, 2); }
public virtual void WriteRollback(DdlRules rules, TextWriter writer) { Expected.WriteDropStatement(rules, writer); Actual.WriteCreateStatement(rules, writer); }
public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue(nameof(Expected), Expected.ToArray()); info.AddValue(nameof(Actual), Actual.ToArray()); }
public void TestMethod2() { Input.AppendLine("10 10"); Expected.AppendLine("0"); Test(); }
/// <summary> /// Indicates if a given argument can be converted. /// </summary> /// <param name="argument">The value to convert.</param> /// <returns>A boolean if this is possible.</returns> public bool CanConvertFrom(Value argument) { return(Expected.IsInstanceOfType(argument)); }
public void TestMethod1() { Input.AppendLine("5 2"); Expected.AppendLine("3"); Test(); }
public void each_string_is_escaped() { Expected.ShouldEqual(Actual); }