Your SlideShare is downloading. ×
0
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
How totestinternalprotectmethodsinc#
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

How totestinternalprotectmethodsinc#

169

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
169
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. How to test internal / protected methods in c# Howard 2014/02/13
  • 2. Modifiers • internal • The internal keyword is an access modifier for types and type members. Internal types or members are accessible only within files in the same assembly • protected • The protected keyword is a member access modifier. A protected member is accessible within its class and by derived class instances.
  • 3. How?
  • 4. How to test internal methods?
  • 5. How to test internal methods? • InternalsVisibleToAttribute • • Specifies that types that are ordinarily visible only within the current assembly are visible to a specified assembly. Namespace: System.Runtime.CompilerServices
  • 6. How to test internal methods?
  • 7. How to test internal methods?
  • 8. How to test protected methods?
  • 9. How to test protected methods? • 繼承 TestClass 後 • 覆寫要測試的方法並將其 modifier 設為 public • 測試 public method
  • 10. How to test protected methods?
  • 11. new Modifier • When used as a declaration modifier, the new keyword explicitly hides a member that is inherited from a base class. • When you hide an inherited member, the derived version of the member replaces the base class version. • Although you can hide members without using the new modifier, you get a compiler warning. If you use new to explicitly hide a member, it suppresses this warning.
  • 12. How to test protected methods? – better solution! Set method modifier to protected internal, and use InternalsVisibleToAttribute • protected internal: Access is limited to the current assembly or types derived from the containing class.
  • 13. References • How to Test Private and Protected methods in .NET • http://www.codeproject.com/Articles/9715/How-to-Test-Private-and-Protected-methods-inNET • InternalsVisibleToAttribute Class • http://msdn.microsoft.com/enus/library/system.runtime.compilerservices.internalsvisibletoattribute(v=vs.110).aspx • Modifiers • http://msdn.microsoft.com/en-us/library/6tcf2h8w.aspx • http://msdn.microsoft.com/en-us/library/435f1dw2.aspx • new Modifier

×