using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using YLErp.DBModels; using KellermanSoftware.CompareNetObjects; namespace YLErp.ExternalLibTests { [TestClass] public class AutoMapperTest : UnitTestBase { class MapA { public int? id { get; set; } } class MapB { public int id { get; set; } } [TestMethod] public void TestBasic() { var config = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap(); }); var mapper = config.CreateMapper(); var mapA = new MapA(); var mapB = mapper.Map(mapA); Assert.AreEqual(mapB.id, 0); } [TestMethod] public void TestVolatilityMap() { var volSrc = new volatility { id = 10, Ask_Deviation = 10, Bid_Deviation = 20, ContractCode = "RB2010", Data = ReadResourceFile("volatility.json"), InterpolationMethod = "testt", OptDate = new DateTime(2020, 02, 02), OptId = 10, OptName = "测试", QuotationDate = new DateTime(2020, 02, 08), ReviewDownLimit = 5.55, ReviewUpLimit = 8.88, UnderlyingId = 10009, UserGroup = "UserGroup", VolSurfaceMode = "VolSurfaceMode123", VolType = "VolType677" }; var volDest = YLAutoMapper.Map(volSrc); Assert.AreEqual(volDest.id, 0); var config = new ComparisonConfig { MembersToIgnore = new List() { nameof(volatility.id), nameof(volatility.EncryptId) } }; var compareLogic = new CompareLogic(config); ComparisonResult result = compareLogic.Compare(volSrc, volDest); Assert.IsTrue(result.AreEqual); } } }