Code Leader Using People, Tools, and Processes to Build Successful Software phần 9

Phần còn lại của View vẫn giữ nguyên. Xem đáp ứng với các sự kiện của người sử dụng và populates điều khiển của nó trong cùng một cách như trước, tất cả đã thay đổi là tương tác của nó với Trình. Trong cả hai trường hợp, thuyết trình insolated từ các chi tiết của View, làm cho các thuyết trình dễ dàng để kiểm tra. | Part III Code Construction The rest of the View remains the same. The View responds to user events and populates its controls in the same way as before all that has changed is its interaction with the Presenter. In either case the Presenter remains insolated from the details of the View which makes the Presenter easy to test. The code remaining in the View itself is concerned only with populating controls and firing events and it is thus very easy to validate using human testers. Testing MVP Applications The main advantage to following the MVP pattern is that it makes your application easy to test. To test an MVP application you create a simulated or test version of your View interface. The Presenter then interacts with the simulated View rather than the actual View implementation. You can add additional infrastructure code to the simulated View that allows you to simulate user interactions from your test code. To test the sample application you would write a simulated View such as the following. Note that this is the first example View that calls the Presenter directly. class TestSurveyView ISurveyView List string users bool question1 string question2 get the back reference to the presenter to events can be reported public TestSurveyView presenter this the presenter reference SurveyPresenter presenter to be called by test code public void DoOnLoad to be called by test code public void ChangeSelection int selectedIndex selectedIndex region ISurveyView Members public List string Users get 184 Chapter 10 The Model-View-Presenter MVP Model return users set users value public bool Questionl get return questionl set questionl value public string Question2 get return question2 set question2 value endregion The extra methods DoOnLoad and ChangeSelection allow the test code to fire events that simulate user interaction. No user interface is required and all of the functionality of the Presenter and .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.