public void MapTest()
        {
            var          a        = new TestClassA();
            var          c        = new TestClassC();
            PropertyInfo fromProp = typeof(TestClassA).GetProperty("Name");
            PropertyInfo toProp   = typeof(TestClassA).GetProperty("Name");
            var          mock     = new ConverterMock();
            bool         executed = false;

            mock.ConvertAction = (f, fp, t, tp, s) =>
            {
                Assert.AreEqual(c, f);
                Assert.AreEqual(fromProp, fp);
                Assert.AreEqual(a, t);
                Assert.AreEqual(toProp, tp);
                Assert.IsTrue(s);
                executed = true;
            };
            var target = new ReflectionPropertyMappingInfo <TestClassC, TestClassA>(
                fromProp, toProp, true, mock);

            target.Map(c, a);

            Assert.IsTrue(executed);
        }
        public void Should_throw_if_converter_throws()
        {
            ConverterMock.Setup(c => c.Convert <string>(It.IsAny <JToken[]>())).Throws <InvalidCastException>();

            CreateProvider(new {})
            .Invoking(p => p.GetConfiguration <string>())
            .ShouldThrow <InvalidCastException>();
        }
        public void Should_delegate_conversion_to_converter()
        {
            ConverterMock.Setup(c => c.Convert <string>(It.IsAny <JToken[]>())).Returns <JToken[]>(tokens => String.Join(String.Empty, tokens.Select(s => s.Value <string>())));

            CreateProvider("con", "tent")
            .GetConfiguration <string>()
            .Should().Be("content");

            ConverterMock.Verify(c => c.Convert <string>(It.IsAny <JToken[]>()), Times.Once);
        }
        public void Should_select_sub_property_for_deserialization()
        {
            var selectorMock = new Mock <IConfigurationSelector <JToken, JToken> >(MockBehavior.Strict);

            selectorMock.Setup(s => s.Select(It.IsAny <JToken>())).Returns <JToken>(token => token["Parent"]["Child"]);
            ConverterMock.Setup(c => c.Convert <string>(It.IsAny <JToken[]>())).Returns <JToken[]>(tokens => tokens.First().Value <string>());

            CreateProvider(new { Parent = new { Child = "content" } })
            .GetConfiguration <string>(selectorMock.Object)
            .Should().Be("content");
        }
        public void MapTest()
        {
            var a = new TestClassA();
            var c = new TestClassC();
            PropertyInfo fromProp = typeof (TestClassA).GetProperty("Name");
            PropertyInfo toProp = typeof (TestClassA).GetProperty("Name");
            var mock = new ConverterMock();
            bool executed = false;

            mock.ConvertAction = (f, fp, t, tp, s) =>
            {
                Assert.AreEqual(c, f);
                Assert.AreEqual(fromProp, fp);
                Assert.AreEqual(a, t);
                Assert.AreEqual(toProp, tp);
                Assert.IsTrue(s);
                executed = true;
            };
            var target = new ReflectionPropertyMappingInfo<TestClassC, TestClassA>(
                fromProp, toProp, true, mock);
            target.Map(c, a);

            Assert.IsTrue(executed);
        }
 protected void VerifyMocks()
 {
     ConverterMock.Verify(m => m.Convert(It.IsAny <string>()), Times.Once);
     MapperMock.Verify(m => m.MapValue(It.IsAny <object>(), It.IsAny <TValue>()), Times.Once);
     ValidatorMock.Verify(m => m.Validate(It.IsAny <TValue>()), Times.Once);
 }
 protected ParserTestsBase()
 {
     ConverterMock.Setup(m => m.Convert(It.IsAny <string>())).Verifiable();
     MapperMock.Setup(m => m.MapValue(It.IsAny <object>(), It.IsAny <TValue>())).Verifiable();
     ValidatorMock.Setup(m => m.Validate(It.IsAny <TValue>())).Returns(true).Verifiable();
 }
 public void ConverterSinks()
 {
     ConverterMock.Verify(m => m.Convert(It.IsAny <string>()), Times.Once);
 }