public void WithMessageMatching_should_handle_unmatched_message() { ForTest.Scenarios ( new { Message = "Something bad happened. ", Pattern = @"^Something bad happened\.$" }, new { Message = "Error 45.", Pattern = @"Error 4\d{2}" }, new { Message = "Invalid operation. SAD!", Pattern = @".*BAD\!" } ) .TestEach(scenario => { try { AssertExceptionThrown .OfType <InvalidOperationException>() .WithMessageMatching(scenario.Pattern) .WhenExecuting(() => throw new InvalidOperationException(scenario.Message)); } catch (ExpectedExceptionNotThrownException ex) { string expected = $"Expected message matching \"{scenario.Pattern}\". Actual: \"{scenario.Message}\"." + "\n(message from System.InvalidOperationException.)"; Assert.AreEqual(expected, ex.Message); } }); }
public void Scenario_Arrange_Assert_should_work_as_expected() { bool arrange1Called = false; bool arrange2Called = false; bool assert1Called = false; bool assert2Called = false; ForTest.Scenarios <TestClass1, TestClass2>() .Arrange(t1 => arrange1Called = true).Assert(t2 => assert1Called = true) .Arrange(t1 => arrange2Called = true).Assert(t2 => assert2Called = true) .TestEach(scenario => { var test1 = new TestClass1(); scenario.Arrange(test1); var test2 = new TestClass2(); scenario.Assert(test2); }); using (new AssertionScope()) { arrange1Called.Should().BeTrue(); assert1Called.Should().BeTrue(); arrange2Called.Should().BeTrue(); assert2Called.Should().BeTrue(); } }
public void ViewComponentTester_constructor_should_check_for_valid_ViewComponent_class() { ForTest.Scenarios ( new ConstructorScenario(true, () => new ViewComponentTester <ViewComponentInvocationTesterTests>(this)), new ConstructorScenario(true, () => new ViewComponentTester <ClassWithViewComponentAttribute>(new ClassWithViewComponentAttribute())), new ConstructorScenario(true, () => new ViewComponentTester <ClassWithNameEndingWithViewComponent>(new ClassWithNameEndingWithViewComponent())), new ConstructorScenario(false, () => new ViewComponentTester <InvalidViewComponentClass>(new InvalidViewComponentClass())) ) .TestEach(scenario => { if (scenario.IsValidViewComponent) { AssertExceptionNotThrown.WhenExecuting(scenario.ConstructorCall); } else { AssertExceptionThrown .OfType <ActionTestException>() .WithMessageStartingWith("A ViewComponent must inherit from ViewComponent, have a name ending with") .WhenExecuting(scenario.ConstructorCall); } }); }
public void ResolveRelativePath_should_return_expected_values() { ForTest.Scenarios ( new { Base = @"C:\SourceCode\sparky-test-helpers\.vs\SparkyTestHelpers\lut\0\t\SparkyTestHelpers.Xml.UnitTests\bin\Debug", Relative = "../../../../../../../../app.transform1.config", Expected = @"C:\SourceCode\sparky-test-helpers\app.transform1.config" }, new { Base = @"c:\folder\subfolder", Relative = @"something\web.config", Expected = @"c:\folder\subfolder\something\web.config" }, new { Base = @"c:\folder\subfolder", Relative = @"/something/web.config", Expected = @"c:\something\web.config" }, // Can use either forward or backward slashes: new { Base = @"c:\folder\subfolder", Relative = @"../../something/web.config", Expected = @"c:\something\web.config" }, new { Base = @"c:\folder\subfolder", Relative = @"..\..\something\web.config", Expected = @"c:\something\web.config" }, new { Base = @"c:\folder\subfolder", Relative = @"../something\web.config", Expected = @"c:\folder\something\web.config" }, new { Base = @"c:\folder\subfolder", Relative = @"..\something\web.config", Expected = @"c:\folder\something\web.config" }, // Full path ignores base: new { Base = @"c:\folder\subfolder", Relative = @"c:\different\subDifferent\web.config", Expected = @"c:\different\subDifferent\web.config" } ) .TestEach(scenario => Assert.AreEqual( scenario.Expected.ToLowerInvariant(), XmlTransformer.ResolveRelativePath(scenario.Base, scenario.Relative).ToLowerInvariant())); }
public void ViewComponentInvocationTester_Test_methods_should_throw_exception_when_result_is_not_expected_IViewComponentResult_type() { ForTest.Scenarios ( new InvocationScenario( () => _viewComponentTester.Invocation(x => x.Invoke).TestResult <ContentViewComponentResult>(), typeof(ContentViewComponentResult), typeof(ViewViewComponentResult)), new InvocationScenario( () => _viewComponentTester.Invocation(x => x.Invoke).TestContent(), typeof(ContentViewComponentResult), typeof(ViewViewComponentResult)), new InvocationScenario( () => _viewComponentTester.Invocation(x => x.Invoke).TestHtmlContent(), typeof(HtmlContentViewComponentResult), typeof(ViewViewComponentResult)), new InvocationScenario( () => _viewComponentTester.Invocation(x => x.InvokeContent).TestView(), typeof(ViewViewComponentResult), typeof(ContentViewComponentResult)) ) .TestEach(scenario => { AssertExceptionThrown .OfType <ActionTestException>() .WithMessage($"Expected IViewComponentResult type {scenario.ExpectedTypeName}. Actual: {scenario.ActualTypeName}.") .WhenExecuting(() => scenario.TestAction()); }); }
public void Any_Double_should_work() { ForTest.Scenarios(1.0d, 2.0d) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithDouble(scenario); _mock.Verify(x => x.WithDouble(Any.Double), Times.Once); }); }
public void Any_Boolean_should_work() { ForTest.Scenarios(true, false) .TestEach(scenario => { _mock.ResetCalls(); _test.WithBoolean(scenario); _mock.VerifyOneCallTo(x => x.WithBoolean(Any.Boolean)); }); }
public void Any_Decimal_should_work() { ForTest.Scenarios(1.0m, 2.0m) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithDecimal(scenario); _mock.Verify(x => x.WithDecimal(Any.Decimal), Times.Once); }); }
public void Any_DateTime_should_work() { ForTest.Scenarios(DateTime.Now, DateTime.Now.AddMonths(1)) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithDateTime(scenario); _mock.Verify(x => x.WithDateTime(Any.DateTime), Times.Once); }); }
public void Any_Boolean_should_work() { ForTest.Scenarios(true, false) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithBoolean(scenario); _mock.Verify(x => x.WithBoolean(Any.Boolean), Times.Once); }); }
public void Any_String_should_work() { ForTest.Scenarios("string1", "string2") .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithString(scenario); _mock.Verify(x => x.WithString(Any.String), Times.Once); }); }
public void Any_Object_should_work() { ForTest.Scenarios(new { A = 1 }, new { A = 2 }) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithObject(scenario); _mock.Verify(x => x.WithObject(Any.Object), Times.Once); }); }
public void Any_Int_should_work() { ForTest.Scenarios(1, 2) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithInt(scenario); _mock.Verify(x => x.WithInt(Any.Int), Times.Once); }); }
public void Any_DateTime_should_work() { ForTest.Scenarios(DateTime.Now, DateTime.Now.AddMonths(1)) .TestEach(scenario => { _mock.ResetCalls(); _test.WithDateTime(scenario); _mock.VerifyOneCallTo(x => x.WithDateTime(Any.DateTime)); }); }
public void Any_Int_should_work() { ForTest.Scenarios(1, 2) .TestEach(scenario => { _mock.ResetCalls(); _test.WithInt(scenario); _mock.VerifyOneCallTo(x => x.WithInt(Any.Int)); }); }
public void Any_Decimal_should_work() { ForTest.Scenarios(1.0m, 2.0m) .TestEach(scenario => { _mock.ResetCalls(); _test.WithDecimal(scenario); _mock.VerifyOneCallTo(x => x.WithDecimal(Any.Decimal)); }); }
public void Any_Double_should_work() { ForTest.Scenarios(1.0d, 2.0d) .TestEach(scenario => { _mock.ResetCalls(); _test.WithDouble(scenario); _mock.VerifyOneCallTo(x => x.WithDouble(Any.Double)); }); }
public void Any_String_should_work() { ForTest.Scenarios("string1", "string2") .TestEach(scenario => { _mock.ResetCalls(); _test.WithString(scenario); _mock.VerifyOneCallTo(x => x.WithString(Any.String)); }); }
public void Any_Object_should_work() { ForTest.Scenarios(new { A = 1 }, new { A = 2 }) .TestEach(scenario => { _mock.ResetCalls(); _test.WithObject(scenario); _mock.VerifyOneCallTo(x => x.WithObject(Any.Object)); }); }
public void WhenModelStateIsValidEquals_method_should_work_as_expected() { ForTest.Scenarios(true, false) .TestEach(isValid => { bool result = _controllerTester.Action <bool>(x => x.BoolResultActionThatChecksModelState) .WhenModelStateIsValidEquals(isValid) .Test(response => response.Should().Be(isValid)); result.Should().Be(isValid); }); }
public void Any_Dictionary_should_work() { ForTest.Scenarios ( new Dictionary <string, string>() ) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithDictionary(scenario); _mock.Verify(x => x.WithDictionary(Any.Dictionary <string, string>()), Times.Once); }); }
public void Any_KeyValuePair_should_work() { ForTest.Scenarios ( new KeyValuePair <string, string>("key", "value") ) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithKeyValuePair(scenario); _mock.Verify(x => x.WithKeyValuePair(Any.KeyValuePair <string, string>()), Times.Once); }); }
public void Any_KeyValuePair_should_work() { ForTest.Scenarios ( new KeyValuePair <string, string>("key", "value") ) .TestEach(scenario => { _mock.ResetCalls(); _test.WithKeyValuePair(scenario); _mock.VerifyOneCallTo(x => x.WithKeyValuePair(Any.KeyValuePair <string, string>())); }); }
public void Any_Dictionary_should_work() { ForTest.Scenarios ( new Dictionary <string, string>() ) .TestEach(scenario => { _mock.ResetCalls(); _test.WithDictionary(scenario); _mock.VerifyOneCallTo(x => x.WithDictionary(Any.Dictionary <string, string>())); }); }
public void TransformedByFile_should_return_XmlTransformer_when_one_or_more_paths_specified() { ForTest.Scenarios ( new[] { "path1" }, new[] { "path1", "path2" } ) .TestEach(scenario => AssertExceptionNotThrown.WhenExecuting(() => { var transformer = XmlTransformer.ForXmlFile(scenario); Assert.AreSame(transformer, transformer.TransformedByFile(scenario)); })); }
public void MsTest_ForTest_Scenarios_TestEach_extension_method_should_call_test_callback_action_for_each_scenario() { int callbackCount = 0; var scenarios = new[] { "a", "b", "c" }; ForTest.Scenarios(scenarios).TestEach(scenario => { Assert.AreEqual(scenarios[callbackCount], scenario); callbackCount++; }); Assert.AreEqual(scenarios.Length, callbackCount); }
public void Any_IEnumerable_should_work() { ForTest.Scenarios ( new[] { "a", "b" }, new[] { "c", "d" } ) .TestEach(scenario => { _mock.ResetCalls(); _test.WithIEnumerable(scenario); _mock.VerifyOneCallTo(x => x.WithIEnumerable(Any.IEnumerable <string>())); }); }
public void Any_Tuple_should_work() { ForTest.Scenarios ( Tuple.Create("A", 1), Tuple.Create("B", 2) ) .TestEach(scenario => { _mock.ResetCalls(); _test.WithTuple(scenario); _mock.VerifyOneCallTo(x => x.WithTuple(Any.Tuple <string, int>())); }); }
public void Any_InstanceOf_should_work() { ForTest.Scenarios ( new ScenarioTester <string>(new[] { "a", "b" }), new ScenarioTester <string>(new[] { "c", "d" }) ) .TestEach(scenario => { _mock.ResetCalls(); _test.WithScenarioTester(scenario); _mock.VerifyOneCallTo(x => x.WithScenarioTester(Any.InstanceOf <ScenarioTester <string> >())); }); }
public void Any_Array_should_work() { ForTest.Scenarios ( new[] { "a", "b" }, new[] { "c", "d" } ) .TestEach(scenario => { _mock.ResetCalls(); _test.WithArray(scenario); _mock.VerifyOneCallTo(x => x.WithArray(Any.Array <string>())); }); }