Using AngularJs, ASP.NET MVC, Web API and EntityFramework to build NLayered Single Page Web Applications

Building an NLayered, localized, well-structured Single-Page Web Application using AngularJs, ASP.NET MVC, Web API, EntityFramework and ASP.NET Boilerplate.

Read full article

Jay Ganesh

About these ads

All About C# Access Modifiers

Access modifiers (or access specifiers) are keywords in object-oriented languages that set the accessibility of classes, methods, and other members. Access modifiers are a specific part of programming language syntax used to facilitate the encapsulation of components.

Summary of the article:

1) The default access modifier is private for class members.
2) A class marked as internal can have its access limited to the current assembly only.
3) Namespaces as we see by default can have no accessibility specifiers at all. They are by default public and we cannot add any other access modifier including public again too.
4) A class can only be public or internal. It cannot be marked as protected or private. The default is internal for the class.
5) Members of a class can be marked with all the access modifiers, and the default access modifier is private.
6) Protected internal means that the derived class and the class within the same source code file can have access.
7) Between public and internal, public always allows greater access to its members.
8) Base class always allows more accessibility than the derived class.
9) The return values of a method must have greater accessibility than that of the method itself.
10) A class marked sealed can’t act as a base class to any other class.
11) Since we cannot derive from sealed classes, the code from the sealed classes cannot be overridden.
12) We need to initialize the const variable at the time we create it. We are not allowed to initialize it later in our code or program.
13) Like classes, const variables cannot be circular, i.e., they cannot depend on each other.
14) A const field of a reference type other than string can only be initialized with null.
15) One can only initialize a const variable to a compile time value, i.e., a value available to the compiler while it is executing.
16) A constant by default is static and we can’t use the instance reference, i.e., a name to reference a const. A const has to be static as no one will be allowed to make any changes to a const variable.
17) A const variable cannot be marked as static.
18) A variable in C# can never have an uninitialized value.
19) Static variables are always initialized when the class is loaded first. An int is given a default value of zero and a bool is given a default of False.
20) An instance variable is always initialized at the time of creation of its instance.
21) A static readonly field cannot be assigned to (except in a static constructor or a variable initializer).

Rad full article

Jay Ganesh

Get all the column names from Table

Recently, I was looking for all the column names from table and want to use them in select query. My table has total 70 column names so i thought why to type it. Why not query the syscolumns table and fetch those names.

Here is the script that will do the trick:


--Get column related information from table
SELECT * FROM Northwind.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'Customers'

--Get all the column names from Table
SELECT [name] AS [Column Name]
FROM syscolumns
WHERE id = (
		SELECT id
		FROM sysobjects
		WHERE type = 'U'
			AND [Name] = 'TableName'
		)

--Get all the columns from View
SELECT [name] AS [Column Name]
FROM syscolumns
WHERE id = (
		SELECT id
		FROM sysobjects
		WHERE type = 'V'
			AND [Name] = 'ViewName'
		)

--Get Comma separated column names from Table/View
DECLARE @ColumnList VARCHAR(max)

SELECT @ColumnList = COALESCE(@ColumnList + ', ', '') + CAST([name] AS VARCHAR(max))
FROM syscolumns
WHERE id = (
		SELECT id
		FROM sysobjects
		WHERE type = 'U'
			AND [Name] = 'TableName'
		)

SELECT @ColumnList

Hope this will help !!!

Jay Ganesh

CRUD Operations Using the Generic Repository Pattern and Unit of Work in MVC

This article introduces the Generic Repository pattern and Unit of Work in ASP.NET MVC applications. We are developing an application for a Book entity on which we can do Create, Read, Update and Delete operations. To keep the article simple and to make it easy to understand, the Generic Repository pattern and Unit of Work, we use a single book entity in the application.

Read Full Article Here.

Hope this will help !!!

Jay Ganesh

Open Source Code Coverage Tool for .NET

In computer science, code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite. A program with high code coverage has been more thoroughly tested and has a lower chance of containing software bugs than a program with low code coverage.

Read more – http://en.wikipedia.org/wiki/Code_coverage

OpenCover – an open source code coverage tool for .NET

An open source code coverage tool (branch and sequence point) for all .NET Frameworks 2 and above (including Silverlight). Also capable of handling 32 and 64 bit processes. Use ReportGenerator for best viewing results (also available via Nuget).

To install OpenCover – an open source code coverage tool for .NET, run the following command in the Package Manager Console

PM> Install-Package OpenCover

OpenCover does not directly execute your tests but instead needs to execute another application that executes your tests in this case we are using MSTest.

First lets create a batch file that we can execute our tests from the command line:

OpenCover.Console -register:Administrator -target:”C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTEST.exe” -targetdir:”D:\Source\Build\Test” -targetargs:”/testcontainer:MySoftware.Test.dll” -filter:”+[*]* -nodefaultfilters -mergebyhash -output:results.xml -target :< target application>

It can be a directory of executable file Nunit or MSTEST.

-targetdir:

It is the application directory whose code coverage needs to be executed. It should contain all referenced dlls along with PDB files (which is mandatory for code coverage).

-targetargs:

Parameters supported for the target application.

Ex:/testcontainer:testdll
-filter :< space separated filters>

A list of filters to apply to selectively include or exclude assemblies and classes from coverage results. Filters have their own format ± [module-filter]class-filter. If no filter(s) are supplied then a default includes all filter is applied +[*]*. As can be seen you can use an * as a wildcard. Also an exclusion filter (-) takes precedence over an inclusion filter (+).

-nodefaultfilters

A list of default exclusion filters are usually applied, this option can be used to turn them off. The default filters are:
-[mscorlib]*
-[mscorlib.*]*
-[System]*
-[System.*]*
-[Microsoft.VisualBasic]*
-mergebyhash

Under some scenarios e.g. using MSTest, an assembly may be loaded many times from different locations. This option is used to merge the coverage results for an assembly regardless of where it was loaded assuming the assembly has the same file-hash in each location.

-output :< results file name>

Coverage results will get stored in the above file and it resides in the opencover directory or the specified location in the parameter. When executed, OpenCover will produce an XML file (default results.xml) that contains all the data related to that test run.

ReportGenerator

ReportGenerator converts XML reports generated by PartCover, OpenCover or NCover into a readable report in various formats. The reports do not only show the coverage quota, but also include the source code and visualize which line has been covered.

ReportGenerator supports merging several reports into one. It is also possible to pass one XML file containing several reports to ReportGenerator (e.g. a build log file).

The following output formats are supported by ReportGenerator:

  • HTML, HTMLSummary
  • XML, XMLSummary
  • Latex, LatexSummary
  • TextSummary
  • Custom reports

D:\downloads\ReportGenerator_1.6.1.0\bin>ReportGenerator “D:\Source\Build\Test\results.xml” “D:\downloads\opencover.4.0.804\”

If we open the produced coverage output (coverage\index.htm) we can see the visualization of the coverage of our target code.

Reference Link:

Hope this will help !!!

Jay Ganesh