Posts

Showing posts from February, 2014

Enum Support in MVC 5.1

Image
  Enum support for MVC views is a new feature introduced in Asp.net MVC 5.1. If you have Enum in your model view will create a dropdown list or radio button list in the view for you. See the example below. Model public class MyData      {          public int Id { get ; set ; }            public MyEnum Enum1 { get ; set ; }            public MyEnum ? Enum2 { get ; set ; }            public FlagsEnum FlagsEnum { get ; set ; }      }   Enum as Dropdown List   < div class ="form-group">           @Html.LabelFor(model => model.Enum1, new { @class = "control-label col-md-2" })           < div class ="col-md-10">               @Html.EditorFor(model => model.Enum1)               @Html.ValidationMessageFor(model => model.Enum1)           </ div >       </ div >         < div class ="form-group">           @Html.LabelFor(model =>...

TestCase Attribute (NUnit 2.5)

Image
Have you ever thought how easy would it be if we could pass parameters and expected result to a Unit Test method we have rather writing multiple test methods. It is possible now with NUnit 2.5 “ TestCase ” Attribute. Suppose you have a method to test whether a year is a leap year or not which you want to test by passing different values here is the solution. [TestCase(2000, Result = true)] [TestCase(1996, Result = true)] [TestCase(2013, Result = false)] public bool IsLeapYearTest(int year) { return DateTime.IsLeapYear(year); } and if you want to pass multiple parameters just add them comma seperated as below example. [TestCase(12, 3, Result = 4)] [TestCase(12, 2, Result = 6)] [TestCase(12, 4, Result = 3)] public int DivideTest(int n, int d) { return (n / d); } This helps us to provide test methods with parameters as well as providing inline date to be ...

February 2014

  Please find the presentation & the sample code for February Sri Lanka .net Forum meet up which I did on c# interfaces here. https://skydrive.live.com/redir?resid=80EDE0125C9CA03A!109&authkey=!AJKHEV7BrDCEP1c&ithint=file%2c.zip

SOLID Design Principles

Image
  SOLID design principles are some set of best practices for object oriented programming. SOLID stands for S ingle responsibility principle (SRP) O pen-Closed principle (OCP) L iskov substitution principle (LSP) I nterface segregation principle (ISP) D ependency inversion principle (DIP)   S ingle responsibility principle “There should never be more than one reason for a class to change”. This means every object should have single focus of responsibility. This can be applied in different levels. A method should carry out one thing only A domain object should only represent one isolated object within business domain Presentation layer should be only responsible for presenting data Purpose of implementing this principle is to get High Cohesive & Low Couples code which is easily testable and maintainable. Cohesion : how strongly related and focused the various responsibilities of a module are Coupling : the degree to which each program module relies on ...