Created
September 9, 2012 12:21
-
-
Save davybrion/3684062 to your computer and use it in GitHub Desktop.
code snippets for "How To Write Testable ASP.NET UserControls", part I
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IViewPart | |
| { | |
| bool IsPostBack { get; } | |
| IDictionary State { get; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IPartController | |
| { | |
| IDispatcher Dispatcher { get; set; } | |
| void AddInitialRequests(); | |
| void GetInitialResponses(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IViewPart<TPartController> : IViewPart | |
| where TPartController : IPartController | |
| { | |
| TPartController GetPartController(IDispatcher dispatcher); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IPartController<TViewPart> : IPartController | |
| where TViewPart : IViewPart | |
| { | |
| TViewPart ViewPart { get; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class PartController<TViewPart> : IPartController<TViewPart> where TViewPart : IViewPart | |
| { | |
| protected PartController(TViewPart viewPart) | |
| { | |
| ViewPart = viewPart; | |
| } | |
| public TViewPart ViewPart { get; private set; } | |
| public IDispatcher Dispatcher { get; set; } | |
| public virtual void AddInitialRequests() {} | |
| public virtual void GetInitialResponses() {} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class UserControl<TPartController> : System.Web.UI.UserControl, IViewPart<TPartController> | |
| where TPartController : IPartController | |
| { | |
| protected TPartController Controller { get; private set; } | |
| protected UserControl() | |
| { | |
| Controller = IoC.Container.Resolve<TPartController>(new { ViewPart = this }); | |
| } | |
| public TPartController GetPartController(IDispatcher dispatcher) | |
| { | |
| Controller.Dispatcher = dispatcher; | |
| return Controller; | |
| } | |
| public IDictionary State | |
| { | |
| get { return ViewState; } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public partial class DummyPart : UserControl<IDummyViewPartController>, IDummyViewPart | |
| { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IDummyViewPart : IViewPart<IDummyViewPartController> | |
| { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IDummyViewPartController : IPartController<IDummyViewPart> | |
| { | |
| void SomeSpecificOperationForTheDummyViewPart(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment