public SatisfyAnyMatcher(params ITestMatcher <T>[] matchers) { _matchers = Array.ConvertAll( matchers ?? Array.Empty <ITestMatcher <T> >(), m => (ITestMatcher <T>)TestMatcher.AllowingNullActualValue(m) ); }
public void For_unwinds_support_test_matcher() { var wrapped = TestMatcher.UnitWrapper(new ThrowsMatcher()); Assert.Equal( "spec.throws", TestMatcherName.For(wrapped).Name ); }
public void Matches_returns_false() { var matcher = new TestMatcher(""); var matches = matcher.Matches(""); Assert.False(matches); }
public void Describe_to() { var matcher = new TestMatcher(""); var description = new StringDescription(); matcher.DescribeTo(description); Assert.Equal("", description.ToString()); }
public void To_string() { const string text = "text"; var matcher = new TestMatcher(text); var toString = matcher.ToString(); Assert.Equal(text, toString); }
public void ValidateParseError() { string path = "agent.product.(1)name[3]\"Safari\""; var matcher = new TestMatcher(new Dictionary <string, IDictionary <string, string> >(), new Dictionary <string, ISet <string> >()); MatcherExtractAction action = new MatcherExtractAction("Dummy", 42, path, matcher); Action a = new Action(() => action.Initialize()); a.Should().Throw <InvalidParserConfigurationException>(); }
public void ValidateParseErrorUselessFixedString() { string path = "\"Safari\""; TestMatcher matcher = new TestMatcher(new Dictionary <string, IDictionary <string, string> >(), new Dictionary <string, ISet <string> >()); MatcherRequireAction action = new MatcherRequireAction(path, matcher); Action a = new Action(() => action.Initialize()); a.Should().Throw <InvalidParserConfigurationException>(); }
public void DescribeMismatch_appends_item() { var matcher = new TestMatcher(); var descriptionMock = new Mock <IDescription>(); descriptionMock.Setup(d => d.AppendText(It.IsAny <string>())).Returns(descriptionMock.Object); const string item = "item"; matcher.DescribeMismatch(item, descriptionMock.Object); descriptionMock.Verify(d => d.AppendText("was "), Times.Once); descriptionMock.Verify(d => d.AppendValue(item), Times.Once); }
public void DescribeMismatch_appends_item() { var matcher = new TestMatcher(); var description = MockRepository.GenerateStub <IDescription>(); description.Stub(d => d.AppendText(Arg <string> .Is.Anything)).Return(description); const string item = "item"; matcher.DescribeMismatch(item, description); description.AssertWasCalled(d => d.AppendText("was ")); description.AssertWasCalled(d => d.AppendValue(item)); }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="expectedHashEntries"></param> /// <param name="expectedWalkList"></param> private void CheckPath(string path, string[] expectedHashEntries, string[] expectedWalkList) { var lookups = new Dictionary <string, IDictionary <string, string> > { ["TridentVersions"] = new Dictionary <string, string>() }; var matcher = new TestMatcher(lookups, new Dictionary <string, ISet <string> >()); var action = new MatcherExtractAction("Dummy", 42, path, matcher); action.Initialize(); var sb = new StringBuilder("\n---------------------------\nActual list (") .Append(matcher.receivedValues.Count) .Append(" entries):\n"); foreach (var actual in matcher.receivedValues) { sb.Append(actual).Append('\n'); } sb.Append("---------------------------\n"); // Validate the expected hash entries (i.e. the first part of the path) foreach (var expect in expectedHashEntries) { matcher.receivedValues.Contains(expect).Should().BeTrue("\nExpected:\n" + expect + sb.ToString()); } expectedHashEntries.Length.Should().Be(matcher.receivedValues.Count, "Found that number of entries"); // Validate the expected walk list entries (i.e. the dynamic part of the path) var evaluator = action.EvaluatorForUnitTesting; var walkList = evaluator.WalkListForUnitTesting; var step = walkList.FirstStep; foreach (var walkStep in expectedWalkList) { step.Should().NotBeNull("Step: " + walkStep); walkStep.Should().Be(step.ToString(), "step(" + step.ToString() + " should be " + walkStep + ")"); step = step.NextStep; } step.Should().BeNull(); }
private static ITestMatcher <object> Matcher(object specified) { if (specified is null) { return(Matchers.BeNull()); } if (specified is ITestMatcher <object> tm) { return(tm); } var iface = specified.GetType().GetInterface(typeof(ITestMatcher <>).FullName); if (iface == null) { return(Matchers.Equal(specified)); } return((ITestMatcher <object>)TestMatcher.Adapter( iface.GetGenericArguments()[0], typeof(object), specified )); }