Exemplo n.º 1
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_should_work()
        {
            Dest dest = null;

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

            dest.Should().BeOfType <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.º 5
0
 public void PageModelActionTester_TestRedirectToAction_should_not_throw_exception_for_expected_action()
 {
     AssertExceptionNotThrown.WhenExecuting(() =>
     {
         RedirectToActionResult result =
             _pageTester.Action(x => x.RedirectToActionAction)
             .TestRedirectToAction("ActionName", "ControllerName");
         Assert.IsNotNull(result);
     });
 }
        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 VerifyOneCallTo_function_should_work()
        {
            _test.WithResponse(2);

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

            _test.WithResponse(2);

            AssertExceptionMessageContaining("once, but was 2 times", () => _mock.VerifyOneCallTo(_funcExpression));
        }
Exemplo n.º 8
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"));
        }
Exemplo n.º 9
0
        public void WithLogging_should_work_with_custom_logger()
        {
            var loggedMessages = new List <string>();

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   _mapTester.WithLogging(message => loggedMessages.Add(message))
                                                   .AssertMappedValues(_source, _dest));

            Assert.IsTrue(loggedMessages.Count > 0);
            Console.Write(string.Join('\n', loggedMessages));
        }
        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 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 VerifyAtMostOneSet_should_work()
        {
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyAtMostOneSet(_propSetExpression));

            SetProp();
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyAtMostOneSet(_propSetExpression));

            SetProp();
            AssertExceptionMessageContaining("at most once, but was 2 times",
                                             () => _mock.VerifyAtMostOneSet(_propSetExpression));
        }
        public void VerifyAtLeastOneSet_should_work()
        {
            AssertExceptionMessageContaining("at least once, but was never performed",
                                             () => _mock.VerifyAtLeastOneSet(_propSetExpression));

            SetProp();
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyAtLeastOneSet(_propSetExpression));

            SetProp();
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyAtLeastOneSet(_propSetExpression));
        }
        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));
        }
        public void VerifyNoCallsTo_action_should_work()
        {
            var exp = _mock.Expression(x => x.WithDateTime(Any.DateTime));

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

            _test.WithDateTime(DateTime.Now);

            AssertExceptionMessageContaining("should never have been performed, but was 1 times",
                                             () => _mock.VerifyNoCallsTo(exp));
        }
Exemplo n.º 16
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"));
        }
        public void VerifyAtLeastOneCallTo_function_should_work()
        {
            AssertExceptionMessageContaining("at least once, but was never performed",
                                             () => _mock.VerifyAtLeastOneCallTo(_funcExpression));

            _test.WithResponse(15);
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyAtLeastOneCallTo(_funcExpression));

            _test.WithResponse(20);
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyAtLeastOneCallTo(_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));
        }
Exemplo n.º 19
0
        public void AssertClientEndpointAddressesAreWellFormedUrls_should_not_throw_exeption_when_URLs_are_valid()
        {
            var tester = new XmlTester(FormattedXml(
                                           "<system.serviceModel><client>"
                                           + "<endpoint address=\"http://www.somewhere.com/something/service1.svc\" name=\"name1\" />"
                                           + "<endpoint address=\"http://www.somewhere.com/something/service2.svc\" name=\"name2\" />"
                                           + "<endpoint address=\"http://www.somewhere.com/something/service3.svc\" name=\"name3\" />"
                                           + "</client></system.serviceModel>"));

            AssertExceptionNotThrown.WhenExecuting(() => tester.AssertClientEndpointAddressesAreWellFormedUrls());
        }
Exemplo n.º 20
0
        public void AssertAppSettingsValues_should_not_throw_exception_when_values_match()
        {
            KeyValuePair <string, string>[] appSettings =
                Enumerable.Range(1, 5).Select(i => new KeyValuePair <string, string>($"key{i}", $"value{i}")).ToArray();

            string appSettingsXml = string.Join("\n", appSettings.Select(kv => FormattedAppSettingsElem(kv.Key, kv.Value)));

            var tester = new XmlTester(FormattedXml(FormattedAppSettingsSection(appSettingsXml)));

            AssertExceptionNotThrown.WhenExecuting(() => tester.AssertAppSettingsValues(appSettings));
        }
Exemplo n.º 21
0
        public void ValidationShouldReturn_RequiredErrorFor_should_use_Display_Names()
        {
            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   _validationForModel.When(x => x.StringProp3 = null).ShouldReturn.RequiredErrorFor(x => x.StringProp3));

            AssertExceptionThrown
            .OfType <ValidationTestException>()
            .WithMessage($"Expected \"The {nameof(StringProp3)} Display Name field is required.\". Member(s): \"{nameof(StringProp3)}\". Found:"
                         + "\n(no validation errors)\n")
            .WhenExecuting(() =>
                           _validationForModel.When(x => x.StringProp3 = "x").ShouldReturn.RequiredErrorFor(x => x.StringProp3));
        }
Exemplo n.º 22
0
        public void Where_extension_with_expression_should_work()
        {
            _test.WithInt(5);

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   _mock.Verify(x => x.WithInt(Any.Int.Where(i => i < 10)), Times.Once));

            AssertExceptionThrown
            .OfType <MockException>()
            .WithMessageContaining("once, but was 0 times")
            .WhenExecuting(() => _mock.Verify(x => x.WithInt(Any.Int.Where(i => i > 10)), Times.Once));
        }
        public void AssertAutoMappedRandomValues_with_IMapper_and_RandomValueProvider_should_work()
        {
            Dest dest = null;

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

            dest.Should().BeOfType <Dest>();
            dest.Id.Should().Be(_testInt);

            Console.WriteLine(JsonConvert.SerializeObject(dest));
        }
Exemplo n.º 24
0
        public void AssertNoDuplicateElements_should_not_throw_exception_when_there_are_no_duplicates()
        {
            var tester = new XmlTester(FormattedXml(FormattedAppSettingsSection(
                                                        FormattedAppSettingsElem("key1", "value1")
                                                        + FormattedAppSettingsElem("key2", "value2")
                                                        + FormattedAppSettingsElem("key3", "value3")
                                                        + FormattedAppSettingsElem("key4", "value4")
                                                        )));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   tester.AssertNoDuplicateElements(ConfigXPath.AppSettings, "key"));
        }
        public void VerifyCallCount_action_should_work()
        {
            var exp = _mock.Expression(m => m.WithNoParms());

            _test.WithNoParms();
            _test.WithNoParms();
            _test.WithNoParms();

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

            AssertExceptionMessageContaining("exactly 2 times, but was 3 times",
                                             () => _mock.VerifyCallCount(2, exp));
        }
        public void VerifyAtLeastOneCallTo_action_should_work()
        {
            var exp = _mock.Expression(x => x.WithString("test"));

            AssertExceptionMessageContaining("at least once, but was never performed",
                                             () => _mock.VerifyAtLeastOneCallTo(exp));

            _test.WithString("test");
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyAtLeastOneCallTo(exp));

            _test.WithString("test");
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyAtLeastOneCallTo(exp));
        }
        public void VerifyAtMostOneCallTo_action_should_work()
        {
            var exp = _mock.Expression(x => x.WithDouble(1.5));

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

            _test.WithDouble(1.5);
            AssertExceptionNotThrown.WhenExecuting(() => _mock.VerifyAtMostOneCallTo(exp));

            _test.WithDouble(1.5);
            AssertExceptionMessageContaining("at most once, but was 2 times",
                                             () => _mock.VerifyAtMostOneCallTo(exp));
        }
Exemplo n.º 28
0
 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));
     }));
 }
Exemplo n.º 29
0
        public void AssertNoDuplicateElements_should_ignore_specified_keys()
        {
            var tester = new XmlTester(FormattedXml(FormattedAppSettingsSection(
                                                        FormattedAppSettingsElem("TransformApplied", "transform1")
                                                        + FormattedAppSettingsElem("TransformApplied", "transform2")
                                                        + FormattedAppSettingsElem("key1", "value1")
                                                        + FormattedAppSettingsElem("key2", "value2")
                                                        + FormattedAppSettingsElem("key3", "value3")
                                                        + FormattedAppSettingsElem("key4", "value4")
                                                        )));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   tester.AssertNoDuplicateElements(ConfigXPath.AppSettings, "key", "TransformApplied"));
        }
Exemplo n.º 30
0
        public void AssertAttributeValues_should_not_throw_exception_when_values_match()
        {
            string appSettingsXml = FormattedAppSettingsSection(
                "<add key=\"testKey\" value=\"testValue\" value2=\"testValue2\" value3=\"testValue3\" />");

            var tester = new XmlTester(FormattedXml(appSettingsXml));

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   tester.AssertAttributeValues(
                                                       ConfigXPath.AppSettingForKey("testKey"),
                                                       new Dictionary <string, string>
            {
                { "value", "testValue" },
                { "value2", "testValue2" },
                { "value3", "testValue3" }
            }));
        }