2010-07-13 18 views
8

İç içe geçmiş koleksiyonlarla çalışan CollectionAssert.AreEquivalent() öğesine benzer bir şey var mı? NUnit İç İçe Toplama Karşılaştırması

CollectionAssert.AreEquivalent ( 
    new Dictionary<int, Dictionary<int, string>> 
    { 
     { 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } }, 
     { 2, new Dictionary < int, string > { { 20, "eggs" }, { 21, "eels" } } }, 
     { 3, new Dictionary < int, string > { { 30, "hovercraft" } } } 
    }, 
    new Dictionary<int, Dictionary<int, string>> 
    { 
     { 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } }, 
     { 2, new Dictionary < int, string > { { 20, "eggs" }, { 21, "eels" } } }, 
     { 3, new Dictionary < int, string > { { 30, "hovercraft" } } } 
    }); 

bu istisna atar

Aşağıdaki kodu ... ...

Expected: equivalent to 
    < [1, System.Collections.Generic.Dictionary`2[System.Int32,System.String]], 
    [2, System.Collections.Generic.Dictionary`2[System.Int32,System.String]], 
    [3, System.Collections.Generic.Dictionary`2[System.Int32,System.String]] > 
But was: 
    < [1, System.Collections.Generic.Dictionary`2[System.Int32,System.String]], 
    [2, System.Collections.Generic.Dictionary`2[System.Int32,System.String]], 
    [3, System.Collections.Generic.Dictionary`2[System.Int32,System.String]] > 

şu assert geçirir:

CollectionAssert.AreEquivalent (
    new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } }, 
    new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } }); 

beklediğim koleksiyona değişiklik yaparsanız , assert iletide her iki koleksiyonun tüm içeriğiyle bir istisna atar:

Expected: equivalent to < [10, foo], [11, bar], [12, spam] > 
But was: < [10, foo], [11, bar], [12, eggs] > 

NUnit 2.4.7.0 kullanıyorum.

+0

benzer soru: http://stackoverflow.com/questions/4185164/recursive-assert-on-collection –

cevap

0

Kendi yazmanız gerekir. Ancak, eğer ben olsaydım, eğer benim önerimi farklı bir şekilde yazmayı denerdim ki, eğer iki listede bir fark varsa, neyin yanlış olduğunu daha açık bir şekilde görebilseydim.

+0

mevcut yöntem beklenen ve fiili sonuçları ve nerede sorundur hakkında oldukça açıktır. Sorumu çıktı olarak görmek istediklerimle güncelleyeceğim. – MikeWyatt

0

Eski bir soru, ama biri sadece ... nunit-tartışmak üzerinde bunun bir bağlantısını yayınlanmıştır

NUnit sürüm iki sözlükleri arasında eşitlik karşılaştırmalar destek vermedi kullanılan ve nesne karşılaştırma geri düştü çünkü başarısızlık . Son sürümlerde bu sorun olmayacak.