先建立一个需要测试的项目
安装nunit
通过nuget安装Install-Package Nunit
类前加[TestFixture]
要测试的方法前加[Test]
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AutoMapper; using NUnit.Framework; namespace autompr { [TestFixture] class Su { [Test] public void Example() { var customer = new Customer { Name = "George Costanza" }; var order = new Order { Customer = customer }; var bosco = new Product { Name = "Bosco", Price = 4.99m }; order.AddOrderLineItem(bosco, 15); // 配置 AutoMapper Mapper.CreateMap<Order, OrderDto>(); // 执行 mapping OrderDto dto = Mapper.Map<Order, OrderDto>(order); Console.WriteLine("CustomerName:" + dto.CustomerName); Console.WriteLine("Total:" + dto.Total); } } }
通过下图的两种办法可以进行测试
参考资料:
http://www.cnblogs.com/xishuai/p/3728576.html
原文:http://www.cnblogs.com/tengguang/p/4541034.html