2010: The year the Future arrived | Informatech CR Blog promised since the Space Age arrived Why Consider these two events that occured last year A computer virus Stuxnet was able to penetrate and deal as much damage to Iran s nuclear facilities as a full blown military strike Consider this not a life was lost not a bullet fired yet because of a piece of software that had to propagate through USB thumbdrives an entire country has been delayed years in a national endeavour Don t believe it Read Wikileaks I think that s all that needs to be said but more specifically how the entire diplomacy of the world s last superpower came to standstill because someone downloaded and posted it all online This is it this is the Future No longer are the virtual and real world separate they ve been meshing together and now finally the computer Internet revolutions changed all aspects of society world wide The challenges now are that as the Internet and computers have pushed into real word issues so have traditional real world issues pushed into the Internet In particular censorship like the traditional media has faced for ages from autocrats is now setting is sights on Web media Consider Venezuela s new Social Reponsibility in Media law 9 933333 84 083333 Share this Email Facebook Twitter Like this Like Loading Related January 5 2011 by pjpalm801 Categories News Tags 2010 censorship future stuxnet venezuela wikileaks Leave a comment Post navigation Ruby on Windows Now Easier How Google pulled off Instant Preview Leave a Reply Cancel reply Enter your comment here Please log in using one of these methods to post your comment Email required Address never made public Name required Website You are commenting using your WordPress com account Log Out Change You are commenting using your Twitter account Log Out

censorship | Informatech CR Blog two events that occured last year A computer virus Stuxnet was able to penetrate and deal as much damage to Iran s nuclear facilities as a full blown military strike Consider this not a life was lost not a bullet fired yet because of a piece of software that had to propagate through USB thumbdrives an entire country has been delayed years in a national endeavour Don t believe it Read Wikileaks I think that s all that needs to be said but more specifically how the entire diplomacy of the world s last superpower came to standstill because someone downloaded and posted it all online This is it this is the Future No longer are the virtual and real world separate they ve been meshing together and now finally the computer Internet revolutions changed all aspects of society world wide The challenges now are that as the Internet and computers have pushed into real word issues so have traditional real world issues pushed into the Internet In particular censorship like the traditional media has faced for ages from autocrats is now setting is sights on Web media Consider Venezuela s new Social Reponsibility in Media law 9 933333 84

future | Informatech CR Blog two events that occured last year A computer virus Stuxnet was able to penetrate and deal as much damage to Iran s nuclear facilities as a full blown military strike Consider this not a life was lost not a bullet fired yet because of a piece of software that had to propagate through USB thumbdrives an entire country has been delayed years in a national endeavour Don t believe it Read Wikileaks I think that s all that needs to be said but more specifically how the entire diplomacy of the world s last superpower came to standstill because someone downloaded and posted it all online This is it this is the Future No longer are the virtual and real world separate they ve been meshing together and now finally the computer Internet revolutions changed all aspects of society world wide The challenges now are that as the Internet and computers have pushed into real word issues so have traditional real world issues pushed into the Internet In particular censorship like the traditional media has faced for ages from autocrats is now setting is sights on Web media Consider Venezuela s new Social Reponsibility in Media law 9 933333 84

stuxnet | Informatech CR Blog two events that occured last year A computer virus Stuxnet was able to penetrate and deal as much damage to Iran s nuclear facilities as a full blown military strike Consider this not a life was lost not a bullet fired yet because of a piece of software that had to propagate through USB thumbdrives an entire country has been delayed years in a national endeavour Don t believe it Read Wikileaks I think that s all that needs to be said but more specifically how the entire diplomacy of the world s last superpower came to standstill because someone downloaded and posted it all online This is it this is the Future No longer are the virtual and real world separate they ve been meshing together and now finally the computer Internet revolutions changed all aspects of society world wide The challenges now are that as the Internet and computers have pushed into real word issues so have traditional real world issues pushed into the Internet In particular censorship like the traditional media has faced for ages from autocrats is now setting is sights on Web media Consider Venezuela s new Social Reponsibility in Media law 9 933333 84

venezuela | Informatech CR Blog occured last year A computer virus Stuxnet was able to penetrate and deal as much damage to Iran s nuclear facilities as a full blown military strike Consider this not a life was lost not a bullet fired yet because of a piece of software that had to propagate through USB thumbdrives an entire country has been delayed years in a national endeavour Don t believe it Read Wikileaks I think that s all that needs to be said but more specifically how the entire diplomacy of the world s last superpower came to standstill because someone downloaded and posted it all online This is it this is the Future No longer are the virtual and real world separate they ve been meshing together and now finally the computer Internet revolutions changed all aspects of society world wide The challenges now are that as the Internet and computers have pushed into real word issues so have traditional real world issues pushed into the Internet In particular censorship like the traditional media has faced for ages from autocrats is now setting is sights on Web media Consider Venezuela s new Social Reponsibility in Media law 9 933333 84 083333 Share this

wikileaks | Informatech CR Blog Consider these two events that occured last year A computer virus Stuxnet was able to penetrate and deal as much damage to Iran s nuclear facilities as a full blown military strike Consider this not a life was lost not a bullet fired yet because of a piece of software that had to propagate through USB thumbdrives an entire country has been delayed years in a national endeavour Don t believe it Read Wikileaks I think that s all that needs to be said but more specifically how the entire diplomacy of the world s last superpower came to standstill because someone downloaded and posted it all online This is it this is the Future No longer are the virtual and real world separate they ve been meshing together and now finally the computer Internet revolutions changed all aspects of society world wide The challenges now are that as the Internet and computers have pushed into real word issues so have traditional real world issues pushed into the Internet In particular censorship like the traditional media has faced for ages from autocrats is now setting is sights on Web media Consider Venezuela s new Social Reponsibility in Media law 9

.net | Informatech CR Blog as a solid data provider for your JavaScript application So stay tuned for more articles D Share this Email Facebook Twitter Like this Like Loading April 8 2014 by Luis Aguilar Categories NET JavaScript Programming Web Tags net c development java javascript programming 1 Comment UI Design Using Model View Presenter Part 3 In The Previous Episode In the previous part of the series we finally wrote some code and implemented the three main components of the Model View Presenter pattern We defined our Model class extreme makeover d our old Windows Form class to a slick View compliant class and then created a Presenter which will orchestrate all sorts of evil things so the Model and View play together nicely In case you missed any of our adrenaline filled previous posts now it is a good time to go back to Part 1 or Part 2 and drop a sweat boy Wiring Everything Up Now is time to wire up the Model View and Presenter classes so we have a running application which does the exact same thing as our old application but with a pretty sexy code base This wiring will take place at the Main method of the application which will instantiate the repository class the View and the Presenter initialize everything and then finally run the application So here is our new Program class doing what it does best namespace Codenough Demos WinFormsMVP public static class Program STAThread public static void Main Application EnableVisualStyles Application SetCompatibleTextRenderingDefault false var clientsForm new ClientsForm var clientsRepository new ClientRepository var clientsPresenter new ClientsPresenter clientsForm clientsRepository clientsForm Closed Application Exit Application Run clientsForm If you smash on that Run toolbar button at this point you will see a really nice window poppin up on screen with the clients list box populated just like the old application only that this time all data coming back and forth the View is going through the Presenter what a controlling psycho freak Most important of it all You can now look in the code examples how each part has a single purpose The Model stores data the View displays data and the Presenter controls data flow Now the only thing left to do and hopefully show the real benefit behind this pattern is to try again and implement our pre defined unit tests so we can verify our application meets all requirements Meeting Acceptance Criteria Our application code has never been so ready before for some unit testing We had some already defined which we could not implement at the time simply because the code was being a total jack But now using the MVP pattern on all its glory we are set up for it So for unit testing I am using NUnit and Moq Moq is a library that allows me to create mocks in this case the repository class and the View interface without having to write additional code we don t like to do that Before we proceed let s see what a mock is and what it can do for us A mock is a fake implementation of an interface or a class which members produce data we already know basically is like making a TV display a TiVO recording instead of an actual live show You know in this example we can know what the data coming from the repository class is just by looking at the code but in the real world we might not have that source code at hand Or even worst that data might come from a production dabatase we don t have access to With a mock we can fake a method to do or return anything we want Our first test is called ItShouldLoadAllClients Since our test naming skills are so incredibly sharp we can imply just by reading that title that a clients list has to be loaded during Presenter class initialization We first create a new method called SetUp that will run right before each time a test method runs to set everything up in this case it will initialize mock instances for the repository class and view interface We then proceed to create an instance of the Presenter class which is the test subject our lab rat yes and then we use the Verify method of the mock that will throw a nasty exception and make the unit test fail miserably if the specified View method LoadClients for this particular case was never called during Presenter initialization using Moq using NUnit Framework using System Collections Generic using System Linq namespace Codenough Demos WinFormsMVP TestFixture public class WhenClientsWindowLoads private Mock IClientsView clientsViewMock private Mock ClientRepository clientsRepositoryMock SetUp public void SetUp this clientsViewMock new Mock IClientsView this clientsRepositoryMock new Mock ClientRepository Test public void ItShouldLoadAllClients Act var clientsPresenter new ClientsPresenter clientsViewMock Object clientsRepositoryMock Object Assert clientsViewMock Verify view view LoadClients It IsAny IList ClientModel Expected clients to be loaded on initialization Of course this test passes A call to the LoadClients method is done at the Presenter constructor The following tests are a little more complicated since we will be setting up methods of the View and repository mocks to return what we need them to return method setup Our next test is ItShouldShowFirstClientOnListDetails which requires our presenter to load the first client on the list after initialization For this case we let the SetUp method do its thing and create the respective mocks and then at our test arrange phase we use the Setup method to make the repository mock return a sample list of clients when the FindAll method is called Finally we verify the LoadClient method of the view was called making this the assertion that makes the test case pass and make us happy or fail and quit our jobs Test public void ItShouldShowFirstClientOnListDetails Arrange var clients new List ClientModel new ClientModel Id 1 Name Matt Dylan Age 28 Gender Male Email mattd none com new ClientModel Id 2 Name Anna Stone Age 22 Gender Female Email ann none com clientsRepositoryMock Setup repository repository FindAll Returns clients Act var clientsPresenter new ClientsPresenter clientsViewMock Object clientsRepositoryMock Object Assert clientsViewMock Verify view view LoadClient clients First Expected first client to be loaded on initialization The last test is ItShouldShowClientDetailsOnListItemSelected and finding out the way it works will be your homework dear reader This is the most complicated of them all since now we use Moq to fire view events and wake up the Presenter which should be listening to them Test public void ItShouldShowClientDetailsOnListItemSelected Arrange var clients new List ClientModel new ClientModel Id 1 Name Matt Dylan Age 28 Gender Male Email mattd none com new ClientModel Id 2 Name Anna Stone Age 22 Gender Female Email ann none com clientsRepositoryMock Setup repository repository FindAll Returns clients clientsRepositoryMock Setup repository repository GetById 1 Returns clients First clientsViewMock SetupGet view view SelectedClient Returns clients First var clientsPresenter new ClientsPresenter clientsViewMock Object clientsRepositoryMock Object Act clientsViewMock Raise view view ClientSelected null Assert clientsViewMock Verify view view LoadClient clients First Expected first client to be loaded on initialization Conclusion Making code testable is not easy at all No really AT ALL At least not at first since you have to think on all the possible test scenarios your code could go through But in the long term this is what makes testable code more robust and clean than regular hastily thrown together code Okay this makes it up for it Hope you enjoyed it and learned a couple things Stay tuned for more talk on patterns and good practices and maybe really off topic things Oh Don t forget to check out the code examples including an exciting port on Java Code Examples WinformsMVP C SwingMVP Java Share this Email Facebook Twitter Like this Like Loading March 21 2013 by Luis Aguilar Categories NET Programming Tags net c development model view presenter mvp user interface design 1 Comment UI Design Using Model View Presenter Part 2 What Just Happened In the previous part we demonstrated the traditional way of doing things when it comes to UI design We also reviewed some key concepts like Code Coverage and Separation Of Concerns Lastly we reviewed some concepts behind the Model View Presenter pattern Yeap that was a lot of stuff So if you haven t read it yet be a good boy and go read it now Everything has been really theoric up until now which is boring to depressing levels But don t worry I ll make it up for you on this part We are now going to look at how each piece of the pattern is implemented Alright let s move on then but have in mind this diagram at all times UI Design Redemption Ok time to make things right First thing to do to sort this mess up dear reader is to create the Model The Model is a domain object fancy name for a class full of properties only which contains the information the View is gonna show In this case our View will contain a list of clients so the Model is actually the Client class renamed to obey naming conventions as ClientModel C mon lots of people including seven devs two architects and a baby goat were required to figure out that name refactor namespace Codenough Demos WinFormsMVP public class ClientModel public int Id get set public string Name get set public int Age get set public string Gender get set public string Email get set As mentioned before I tend to repeat myself bear with me here the Model is a really simple class composed only of properties better known as plain old C object or POCO for the friends Wait poco actually means not much in Spanish so it does not much Wow cool right Okay here is a list of things the Model should NOT do Do any data validation Refresh save or update its data on the database Throw exceptions like it was something actually funny Be aware of any other class outside the domain model Provide a solution to world hunger actually that would be pretty impressive but DON T Next step is to create an interface that will serve as a contract of whatever the View is capable to do so the Presenter is aware of it Remember it will be communicating with it to serve view data and receive input so the guy needs to know what is in the view regardless of implementation using System using System Collections Generic namespace Codenough Demos WinFormsMVP public interface IClientsView event Action ClientSelected event Action Closed IList ClientModel Clients get ClientModel SelectedClient get void LoadClients IList ClientModel clients void LoadClient ClientModel client The interface only defines the methods needed by the Presenter so it can puppet it as needed in order to get its data and validate anything before it gets back into the database or any other event triggered by the user Also see those fancy events on the view interface Dude I didn t even knew interfaces could have events on it LOL just kidding Actually they are there so the Presenter subscribe to them and then the View can fire them to notify of data changes Is a two way communication Okay now to complete the View portion we need to create the concrete implementation of the view interface In this case is our old Windows Forms class which has gone under a strict diet low on carbs to reduce its functionality to the minimum using System using System Collections Generic using System Windows Forms namespace Codenough Demos WinFormsMVP public partial class ClientsForm Form IClientsView public event Action ClientSelected public event Action Closed public ClientsForm this InitializeComponent this BindComponent public IList ClientModel Clients get return this clientsListBox DataSource as IList ClientModel public ClientModel SelectedClient get return this clientsListBox SelectedItem as ClientModel public void LoadClients IList ClientModel clients this clientsListBox DataSource clients public void LoadClient ClientModel client this clientNameTextBox Text client Name this clientEmailTextBox Text client Email this clientGenderTextBox Text client Gender this clientAgeTextBox Text client Age ToString private void BindComponent this closeButton Click OnCloseButtonClick this clientsListBox DisplayMember Name this clientsListBox SelectedIndexChanged OnClientsListBoxSelectedIndexChanged private void OnClientsListBoxSelectedIndexChanged object sender EventArgs e if this ClientSelected null this ClientSelected private void OnCloseButtonClick object sender EventArgs e if this Closed null this Closed Now the View implementation only loads data from someone else and fires events as the loaded data changes so anyone out there in space listening to it be aware of the changes and will take appropriate action OK that sounded like a line from a Law Order episode As you might have already guessed the only component aware of the View events would be the Presenter So the next step is to implement the infamous Presenter class The Presenter is a component that is aware of what is happening in the View through its events See what I said about repeating myself But hopefully that will help get things carved out in your head bud As we mentioned before the Presenter talks to the View by using its interface instead of the concrete implementation the ClientsForm class that is this for the sake of code testability Later on we are going to provide the Presenter with a mock instead of the actual View implementation We are going to learn what a mock is later no need to hurry using System Linq namespace Codenough Demos WinFormsMVP public class ClientsPresenter private readonly IClientsView view private readonly ClientRepository clientsRepository public ClientsPresenter IClientsView view ClientRepository clientsRepository this view view this clientsRepository clientsRepository var clients clientsRepository FindAll this view ClientSelected OnClientSelected this view LoadClients clients if clients null this view LoadClient clients First public void OnClientSelected if this view SelectedClient null var id this view SelectedClient Id var client this clientsRepository GetById id this view LoadClient client This time around the one handling data access through the repository class is the Presenter The View is no longer aware of where its data is coming from that s a good thing Also we can notice how the Presenter reacts each time a client is selected on the list box since it has subscribed to the View s ClientSelected event Fancy right Now the only thing left to do is to wire up everything so we can run this incredibly clever application which will save many companies from bankruptcy from now on to the future Of course that is for the next part in our series Gotcha huh Coming Up In our next part we will wire up all this mess so we have a nice and working application We will also implement all unit tests we defined in the first part Is going to be lots of fun I promise Go read Part 3 Share this Email Facebook Twitter Like this Like Loading March 20 2013 by Luis Aguilar Categories NET Programming Tags net c development model view presenter mvp user interface design 4 Comments UI Design Using Model View Presenter Part 1 Introduction Current tendencies and best practices in software development lead to the common pattern that a software system has to be solid scalable and reliable In order to comply with those three requirements two aspects have to be considered during design phase Code coverage and separation of concerns What Ok so code coverage is a metric that indicates how much of the code is being covered by unit tests or in other words English plz how testable is the source code we have written during those lovely 18 hour shifts Yes unit testing is SO important it has its own goddamn metric Then we have separation of concerns which plays close with code coverage since in order to have handsome unit tests we need to give each component of the system a single concern to deal with In software design the milk man cannot deliver newspapers around the neighborhood Each component has a specific well defined responsibility and it has to stick to that scope But what does all of this has to do with user interface design Well user interface code is the number one culprit of most software design flaws since it often lead developers into breaking these two design aspects specifically Is a common well known scenario where a class that represents a window to be rendered on screen also performs business logic validations and queries the database directly This not only screws up the whole idea of separation of concerns but also makes unit testing of that particular class almost impossible punching code coverage right in the face That s right Developers are well known for not being too skilled at designing pretty GUIs However when they nail it they screw infrastructure up Go figure Anyways this three part series of articles intend to demonstrate clear examples of both the traditional way and the awesome way don t mind quotes at all using the Model View Presenter pattern in order to improve overall infrastructure design of the application user interface Examples will be provided in C using Windows Forms The example application is Mono compliant so it can be compiled to run in several platforms using the Mono Framework An additional version for Java using Swing will be provided at the last article of the series The Scenario For our practical example we are going to build a small application that displays a list of clients available in a data source to the user on screen The user will then be able to select clients from the list and view additional details like age gender and e mail address You get the idea The clients will be queried from a repository which for matters of simplicity I m just THAT lazy will return data from a pre defined generic list For a start here is the repo source code using System Collections Generic namespace Codenough Demos WinFormsMVP public class ClientRepository private IList Client clients new List Client new Client Id 1 Name Matt Dylan Age 28 Gender Male Email mattd none

c# | Informatech CR Blog sexy code base This wiring will take place at the Main method of the application which will instantiate the repository class the View and the Presenter initialize everything and then finally run the application So here is our new Program class doing what it does best namespace Codenough Demos WinFormsMVP public static class Program STAThread public static void Main Application EnableVisualStyles Application SetCompatibleTextRenderingDefault false var clientsForm new ClientsForm var clientsRepository new ClientRepository var clientsPresenter new ClientsPresenter clientsForm clientsRepository clientsForm Closed Application Exit Application Run clientsForm If you smash on that Run toolbar button at this point you will see a really nice window poppin up on screen with the clients list box populated just like the old application only that this time all data coming back and forth the View is going through the Presenter what a controlling psycho freak Most important of it all You can now look in the code examples how each part has a single purpose The Model stores data the View displays data and the Presenter controls data flow Now the only thing left to do and hopefully show the real benefit behind this pattern is to try again and implement our pre defined unit tests so we can verify our application meets all requirements Meeting Acceptance Criteria Our application code has never been so ready before for some unit testing We had some already defined which we could not implement at the time simply because the code was being a total jack But now using the MVP pattern on all its glory we are set up for it So for unit testing I am using NUnit and Moq Moq is a library that allows me to create mocks in this case the repository class and the View interface without having to write additional code we don t like to do that Before we proceed let s see what a mock is and what it can do for us A mock is a fake implementation of an interface or a class which members produce data we already know basically is like making a TV display a TiVO recording instead of an actual live show You know in this example we can know what the data coming from the repository class is just by looking at the code but in the real world we might not have that source code at hand Or even worst that data might come from a production dabatase we don t have access to With a mock we can fake a method to do or return anything we want Our first test is called ItShouldLoadAllClients Since our test naming skills are so incredibly sharp we can imply just by reading that title that a clients list has to be loaded during Presenter class initialization We first create a new method called SetUp that will run right before each time a test method runs to set everything up in this case it will initialize mock instances for the repository class and view interface We then proceed to create an instance of the Presenter class which is the test subject our lab rat yes and then we use the Verify method of the mock that will throw a nasty exception and make the unit test fail miserably if the specified View method LoadClients for this particular case was never called during Presenter initialization using Moq using NUnit Framework using System Collections Generic using System Linq namespace Codenough Demos WinFormsMVP TestFixture public class WhenClientsWindowLoads private Mock IClientsView clientsViewMock private Mock ClientRepository clientsRepositoryMock SetUp public void SetUp this clientsViewMock new Mock IClientsView this clientsRepositoryMock new Mock ClientRepository Test public void ItShouldLoadAllClients Act var clientsPresenter new ClientsPresenter clientsViewMock Object clientsRepositoryMock Object Assert clientsViewMock Verify view view LoadClients It IsAny IList ClientModel Expected clients to be loaded on initialization Of course this test passes A call to the LoadClients method is done at the Presenter constructor The following tests are a little more complicated since we will be setting up methods of the View and repository mocks to return what we need them to return method setup Our next test is ItShouldShowFirstClientOnListDetails which requires our presenter to load the first client on the list after initialization For this case we let the SetUp method do its thing and create the respective mocks and then at our test arrange phase we use the Setup method to make the repository mock return a sample list of clients when the FindAll method is called Finally we verify the LoadClient method of the view was called making this the assertion that makes the test case pass and make us happy or fail and quit our jobs Test public void ItShouldShowFirstClientOnListDetails Arrange var clients new List ClientModel new ClientModel Id 1 Name Matt Dylan Age 28 Gender Male Email mattd none com new ClientModel Id 2 Name Anna Stone Age 22 Gender Female Email ann none com clientsRepositoryMock Setup repository repository FindAll Returns clients Act var clientsPresenter new ClientsPresenter clientsViewMock Object clientsRepositoryMock Object Assert clientsViewMock Verify view view LoadClient clients First Expected first client to be loaded on initialization The last test is ItShouldShowClientDetailsOnListItemSelected and finding out the way it works will be your homework dear reader This is the most complicated of them all since now we use Moq to fire view events and wake up the Presenter which should be listening to them Test public void ItShouldShowClientDetailsOnListItemSelected Arrange var clients new List ClientModel new ClientModel Id 1 Name Matt Dylan Age 28 Gender Male Email mattd none com new ClientModel Id 2 Name Anna Stone Age 22 Gender Female Email ann none com clientsRepositoryMock Setup repository repository FindAll Returns clients clientsRepositoryMock Setup repository repository GetById 1 Returns clients First clientsViewMock SetupGet view view SelectedClient Returns clients First var clientsPresenter new ClientsPresenter clientsViewMock Object clientsRepositoryMock Object Act clientsViewMock Raise view view ClientSelected null Assert clientsViewMock Verify view view LoadClient clients First Expected first client to be loaded on initialization Conclusion Making code testable is not easy at all No really AT