2010-04-17 18 views
72

मैं वर्तमान में पुस्तक Professional Enterprise .NET पढ़ रहा हूँ और मैं उदाहरण के कार्यक्रमों में से कुछ में इस चेतावनी को ध्यान दिया है:NUnit.Framework.Assert.IsInstanceOfType() अप्रचलित है

'NUnit.Framework.Assert.IsInstanceOfType(System.Type, object)' is obsolete 

अब मैं पहले से ही हो सकता है जवाब मेरी खुद का सवाल है, लेकिन इस चेतावनी को ठीक करने के लिए यह केवल Assert.IsInstanceOf() के साथ Assert.IsInstanceOfType() को बदलने का मामला है? उदाहरण के लिए इस के लिए:

Assert.IsInstanceOfType(typeof(ClassName), variableName); 

बन जाएगा:

Assert.IsInstanceOf(typeof(ClassName), variableName); 

उत्तर

116

the NUnit documentation से IsInstanceOf विधि एक सामान्य तरीका है, ताकि आप इस का प्रयोग करेंगे: पूर्णता के लिए

Assert.IsInstanceOf<ClassName>(variableName); 
+2

है यही कारण है कि यहां तक ​​कि क्लीनर वाक्य रचना, धन्यवाद मार्क! – Malice

18

: यदि आप the constraint model का उपयोग :

Assert.That(variableName, Is.InstanceOf<ClassName>()); 

या अपने परीक्षण वर्ग AssertionHelper विरासत:

Expect(variableName, InstanceOf<ClassName>()); 
संबंधित मुद्दे