2011-11-11 63 views
0

據筆者在版本2.0Automapper嵌套子容器

http://lostechies.com/jimmybogard/2011/09/29/automapper-2-0-nestedchild-containers/

但這個測試不工作後,能有人指出,什麼是錯在這裏嗎?

用於測試通過,automapper必須撥打ConstructServicesUsing通過的代碼,這是不

public class Source 
    { 
     public int SomeValue { get; set; } 
    } 

    public class Destination 
    { 
     public Destination() { } 

     public Destination(bool value) 
     { 
      this.WasCustom = true; 
     } 
     public bool WasCustom { get; private set; } 
     public int SomeValue { get; set; } 
    } 


    [TestMethod] 
    public void can_make_servicelocator_work() 
    { 
     Mapper.CreateMap<Source, Destination>(); 
     var source = new Source { SomeValue = 100 }; 
     var dest = Mapper.Map<Source, Destination>(source, 
      (option) => option.ConstructServicesUsing((t) => new Destination(true))); 
     Assert.IsTrue(dest.WasCustom); 
    } 
+1

你期待什麼發生?你似乎很困惑。你的代碼沒有意義。 – CrazyDart

+0

我以爲你會閱讀代碼,無論如何,我想測試通過,現在它的失敗,它傳遞,具有布爾參數的構造函數將不得不被調用,這是沒有被調用,調用它的方式是使用在map調用期間傳遞的構造函數func(而不是在初始化配置期間) –

回答

1

我問上automapper論壇同樣的問題,並根據筆者,這將是可用2.1

here是鏈接

+0

我在2.2.1中試過了,它從上面的測試仍然失敗? –