Created
September 9, 2012 12:24
-
-
Save davybrion/3684070 to your computer and use it in GitHub Desktop.
code snippets for "How To Write Testable ASP.NET UserControls", part II
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 DummyViewPartController : PartController<IDummyViewPart>, IDummyViewPartController | |
| { | |
| public DummyViewPartController(IDummyViewPart viewPart) : base(viewPart) {} | |
| public override void AddInitialRequests() | |
| { | |
| // add some initial requests to the IDispatcher | |
| } | |
| public override void GetInitialResponses() | |
| { | |
| // retrieve the responses for the initial requests from the IDispatcher | |
| } | |
| public void SomeSpecificOperationForTheDummyViewPart() | |
| { | |
| // do something specific to the 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 IDummyView : IView | |
| { | |
| IDummyViewPart DummyPart { 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 partial class DummyPage : Page<DummyController>, IDummyView | |
| { | |
| protected void Page_Load(object sender, EventArgs e) | |
| { | |
| Controller.Load(); | |
| } | |
| public IDummyViewPart DummyPart | |
| { | |
| get { return dummyPart; } | |
| } | |
| } |
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 DummyController : Controller<IDummyView> | |
| { | |
| private IDummyViewPartController partController; | |
| public DummyController(IDummyView view) : base(view) | |
| { | |
| } | |
| public void Load() | |
| { | |
| partController = View.DummyPart.GetPartController(Dispatcher); | |
| if (!View.IsPostBack) | |
| { | |
| partController.AddInitialRequests(); | |
| SendOurOwnRequestsAndGetTheResponses(); | |
| partController.GetInitialResponses(); | |
| } | |
| } | |
| private void SendOurOwnRequestsAndGetTheResponses() | |
| { | |
| // this method would send some requests through the IDispatcher and | |
| // retrieve the responses | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment