public void Constructor_using_XDocument_should_work()
        {
            string xml       = FormattedXml();
            var    xDocument = XDocument.Parse(xml);

            AssertExceptionNotThrown.WhenExecuting(() => new XmlTester(xDocument));
        }
 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);
         }
     });
 }
Exemplo n.º 3
0
 public void ValidationShouldReturn_StringLengthErrorFor_should_not_throw_exception_when_error_is_found()
 {
     AssertExceptionNotThrown.WhenExecuting(() =>
                                            _validationForModel
                                            .When(x => x.StringProp4 = new string('x', 51))
                                            .ShouldReturn.StringLengthErrorFor(x => x.StringProp4));
 }
Exemplo n.º 4
0
        public void AssertAppSettingsValueMatch_should_not_throw_exception_when_value_matches()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "actualValue"));

            AssertExceptionNotThrown
            .WhenExecuting(() => tester.AssertAppSettingsValueMatch("testKey", ".*Value"));
        }
        public void AssertElementText_should_not_throw_exception_when_element_has_expected_text_and_attributes()
        {
            var tester = new XmlTester(FormattedXml("<textSection><textElem att1=\"value1\">test string</textElem></textSection>"));

            AssertExceptionNotThrown
            .WhenExecuting(() => tester.AssertElementText("configuration/textSection/textElem", "test string"));
        }
Exemplo n.º 6
0
        public void WithLogging_should_work_with_default_logger()
        {
            var loggedMessages = new List <string>();

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   _mapTester.WithLogging()
                                                   .AssertMappedValues(_source, _dest));
        }
        public void VerifyNoSets_should_work()
        {
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyNoSets(_propSetExpression));

            SetProp();
            AssertExceptionMessageContaining("should never have been performed, but was 1 times",
                                             () => _mock.VerifyNoSets(_propSetExpression));
        }
 public void ViewComponentInvocationTester_should_work_with_async_constructor()
 {
     AssertExceptionNotThrown.WhenExecuting(() =>
                                            _viewComponentTester
                                            .Invocation(x => x.InvokeAsync)
                                            .ExpectingViewName("Default")
                                            .TestView());
 }
Exemplo n.º 9
0
        public void RoutingAsserter_AssertMapTo_dynamic_object_should_not_throw_exception_when_values_match()
        {
            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   _routeTester.ForUrl("Home/INdex").AssertMapTo(new { controller = "Home", action = "Index" }));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   _routeTester.ForUrl("Order/Details/3").AssertMapTo(new { controller = "Order", action = "Details", id = 3 }));
        }
Exemplo n.º 10
0
        public void RoutingAsserter_AssertMapTo_expression_should_not_throw_exception_when_values_match()
        {
            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   _routeTester.ForUrl("Home/Index").AssertMapTo <HomeController>(x => x.Index));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   _routeTester.ForUrl("Order/Details/3").AssertMapTo <OrderController>(x => () => x.Details(3)));
        }
Exemplo n.º 11
0
        public void AssertAttributeValue_should_not_throw_when_value_matches()
        {
            var tester = new XmlTester(FormattedXmlWithAppSetting("testKey", "testValue"));

            AssertExceptionNotThrown
            .WhenExecuting(() =>
                           tester.AssertAttributeValue(ConfigXPath.AppSettingForKey("testKey"), "value", "testValue"));
        }
Exemplo n.º 12
0
        public void Any_Ref_should_work()
        {
            _mock.Setup(x => x.WithRef(Any.String, ref Any.Ref.Int));

            int refValue = 7;

            AssertExceptionNotThrown.WhenExecuting(() => _mock.Object.WithRef("yo", ref refValue));
        }
Exemplo n.º 13
0
 public void ControllerPageTester_TestRedirectToPage_should_not_throw_exception_for_expected_PageName()
 {
     AssertExceptionNotThrown.WhenExecuting(() =>
     {
         RedirectToPageResult result =
             _pageTester.Action(x => x.RedirectToPageAction).TestRedirectToPage("testPageName");
         Assert.IsNotNull(result);
     });
 }
Exemplo n.º 14
0
 public void PageModelActionTester_TestRedirectToRoute_should_not_throw_exception_for_expected_route()
 {
     AssertExceptionNotThrown.WhenExecuting(() =>
     {
         RedirectToRouteResult result =
             _pageTester.Action(x => x.RedirectToRouteAction).TestRedirectToRoute("Foo/Details/3");
         Assert.IsNotNull(result);
     });
 }
Exemplo n.º 15
0
 public void ControllerActionTester_TestRedirectToAction_should_not_throw_exception_for_expected_ActionName()
 {
     AssertExceptionNotThrown.WhenExecuting(() =>
     {
         RedirectToActionResult result =
             _controllerTester.Action(x => x.RedirectToActionAction).TestRedirectToAction("ActionName");
         Assert.IsNotNull(result);
     });
 }
Exemplo n.º 16
0
 public void ControllerPageTester_TestRedirect_should_not_throw_exception_for_expected_URL()
 {
     AssertExceptionNotThrown.WhenExecuting(() =>
     {
         RedirectResult result =
             _controllerTester.Action(x => x.RedirectAction).TestRedirect("testUrl");
         Assert.IsNotNull(result);
     });
 }
        public void VerifyOneSet_should_work()
        {
            AssertExceptionMessageContaining("once, but was 0 times",
                                             () => _mock.VerifyOneSet(_propSetExpression));

            SetProp();

            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyOneSet(_propSetExpression));
        }
        public void VerifyNoCallsTo_function_should_work()
        {
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyNoCallsTo(_funcExpression));

            _test.WithResponse(666);

            AssertExceptionMessageContaining("should never have been performed, but was 1 times",
                                             () => _mock.VerifyNoCallsTo(_funcExpression));
        }
Exemplo n.º 19
0
 public void ValidationResultTester_with_multiple_member_names_should_not_throw_exception_when_expected_error_is_found()
 {
     AssertExceptionNotThrown.WhenExecuting(() =>
                                            _validationForModel
                                            .When(x => x.StringProp2 = "wrong")
                                            .ShouldReturn
                                            .ErrorFor(x => x.StringProp2)
                                            .AndFor(x => x.StringProp3)
                                            .WithMessage("Invalid StringProp2/StringProp3 combination."));
 }
        public void Where_extension_should_work()
        {
            _test.WithInt(5);

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   _mock.VerifyOneCallTo(x => x.WithInt(Any.Int.Where(i => i < 10))));

            AssertExceptionMessageContaining("once, but was 0 times",
                                             () => _mock.VerifyOneCallTo(x => x.WithInt(Any.Int.Where(i => i > 10))));
        }
        public void AssertAutoMappedRandomValues_with_IMapper_should_work()
        {
            Dest dest = null;

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   dest = MapTester.ForMap <Source, Dest>().AssertAutoMappedRandomValues(_mapper));

            Assert.IsInstanceOfType(dest, typeof(Dest));
            Console.WriteLine(JsonConvert.SerializeObject(dest));
        }
        public void VerifySetCount_should_work()
        {
            AssertExceptionMessageContaining("exactly 2 times, but was 0 times",
                                             () => _mock.VerifySetCount(2, _propSetExpression));

            SetProp();
            SetProp();

            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifySetCount(2, _propSetExpression));
        }
Exemplo n.º 23
0
        public void AssertClientEndpointAddressIsWellFormedUrl_should_not_throw_exception_for_valid_URL()
        {
            var tester = new XmlTester(FormattedXml(
                                           "<system.serviceModel><client>"
                                           + "<endpoint address=\"http://www.somewhere.com/something/service.svc\" name=\"testName\" />"
                                           + "</client></system.serviceModel>"));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   tester.AssertClientEndpointAddressIsWellFormedUrl("testName"));
        }
        public void AssertAutoMappedRandomValues_should_work()
        {
            Dest dest = null;

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   dest = MapTester.ForMap <Source, Dest>().AssertAutoMappedRandomValues());

            dest.Should().BeOfType <Dest>();
            Console.WriteLine(JsonConvert.SerializeObject(dest));
        }
        public void VerifyOneCallTo_function_should_work()
        {
            _test.WithResponse(2);

            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyOneCallTo(_funcExpression));

            _test.WithResponse(2);

            AssertExceptionMessageContaining("once, but was 2 times", () => _mock.VerifyOneCallTo(_funcExpression));
        }
        public void AssertAutoMappedValues_with_IMapper_should_work()
        {
            Source source = GetRandom.InstanceOf <Source>();
            Dest   dest   = null;

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   dest = MapTester.ForMap <Source, Dest>().AssertAutoMappedValues(_mapper, source));

            dest.Should().BeOfType <Dest>();
            Console.WriteLine(JsonConvert.SerializeObject(dest));
        }
        public void VerifyCallCount_function_should_work()
        {
            _test.WithResponse(1);
            _test.WithResponse(2);
            _test.WithResponse(3);

            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyCallCount(3, _funcExpression));

            AssertExceptionMessageContaining("exactly 2 times, but was 3 times",
                                             () => _mock.VerifyCallCount(2, _funcExpression));
        }
        public void VerifyOneCallTo_action_should_work()
        {
            var exp = _mock.Expression(m => m.WithInt(2));

            _test.WithInt(2);

            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyOneCallTo(exp));

            _test.WithInt(2);
            AssertExceptionMessageContaining("once, but was 2 times", () => _mock.VerifyOneCallTo(exp));
        }
        public void AssertAutoMappedValues_should_work()
        {
            Source source = new RandomValuesHelper().CreateInstanceWithRandomValues <Source>();
            Dest   dest   = null;

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   dest = MapTester.ForMap <Source, Dest>().AssertAutoMappedValues(source));

            Assert.IsInstanceOfType(dest, typeof(Dest));
            Console.WriteLine(JsonConvert.SerializeObject(dest));
        }
Exemplo n.º 30
0
        public void AssertAttributeValueIsWellFormedUrl_should_not_throw_exeption_when_value_is_valid_URL()
        {
            var tester = new XmlTester(FormattedXml(
                                           "<system.serviceModel><client>"
                                           + "<endpoint address=\"http://www.somewhere.com/something/service.svc\" name=\"testName\" />"
                                           + "</client></system.serviceModel>"));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   tester.AssertAttributeValueIsWellFormedUrl(
                                                       ConfigXPath.ClientEndpointForName("testName"), "address"));
        }