Mercurial > pub > bltoolkit
diff UnitTests/CS/Mapping/BltMapTests.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UnitTests/CS/Mapping/BltMapTests.cs Thu Mar 27 21:46:09 2014 +0400 @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; + +using BLToolkit.Mapping; +using BLToolkit.Reflection; + +using NUnit.Framework; + +namespace Mapping +{ + [TestFixture] + public class BltMapTests + { + #region Types + + public class TestStep + { + public string Step { get; set; } + } + + internal class Test_Int + { + private BindingList<TestStep> _steps; + + public Test_Int() + { + InitializeStepsList(); + } + + public bool NotNullSetterCalled = false; + + private void InitializeStepsList(IList<TestStep> init = null) + { + _steps = new BindingList<TestStep>(init ?? new List<TestStep>()); + if (init != null) NotNullSetterCalled = true; + } + + [MapField(Storage = "Steps")] + public IList<TestStep> Steps + { + get { return _steps; } + private set { InitializeStepsList(value); } + } + } + + public class Test_Pub + { + private BindingList<TestStep> _steps; + + public Test_Pub() + { + InitializeStepsList(); + } + + public bool NotNullSetterCalled = false; + + private void InitializeStepsList(IList<TestStep> init = null) + { + _steps = new BindingList<TestStep>(init ?? new List<TestStep>()); + if (init != null) NotNullSetterCalled = true; + } + + [MapField(Storage = "Steps")] + public IList<TestStep> Steps + { + get { return _steps; } + private set { InitializeStepsList(value); } + } + } + + public class TestStepRecord + { + public string Step { get; set; } + } + + public class TestRecord + { + //[MapField] + public List<TestStepRecord> Steps; + } + + #endregion + + [Test] + public void TestExpressionMapper_Int() + { + //Arrange + var em = new ExpressionMapper<TestRecord, Test_Int>(); + var tr = new TestRecord { Steps = new List<TestStepRecord> { new TestStepRecord {Step = "Test" } } }; + + //Act + var t = em.GetMapper()(tr); + + //Assert + Assert.IsTrue(t.Steps.Count == 1); + Assert.IsTrue(t.NotNullSetterCalled); + } + + [Test] + public void TestExpressionMapper_Pub() + { + //Arrange + var em = new ExpressionMapper<TestRecord, Test_Pub>(); + var tr = new TestRecord { Steps = new List<TestStepRecord> { new TestStepRecord { Step = "Test" } } }; + + //Act + var t = em.GetMapper()(tr); + + //Assert + Assert.IsTrue(t.Steps.Count == 1); + Assert.IsTrue(t.NotNullSetterCalled); + } + } +}