How easy to reduce efforts in retesting a asp.net web application?

 

Most of the time when you write code for a web application you need to test it again and again. You have to run a whole flow of positive or negative test cases to check whether your application is working or not.

Now suppose your application have 20 pages and you need to traverse each individual page and may be perform some operation and on each change of your development you need to perform same thing.

sometimes, this thing will irritate you and you will skip testing which may be harmful because most of the time it happens when you skipped something Smile you took a deep breath  and at that moment your application crashed Sad smile.

So , as a responsible developer we do not have to skip any test scenario but next question is how to reduce this effort which you feel boring sometime.

I can say we can reduce this effort by a installing a simple  Firefox add-in which is absolutely free. The add in “Selenium add in”

you can download it from https://addons.mozilla.org/en-US/firefox/addon/selenium-expert-selenium-ide/

once you have installed this you will find the selenium icon near by search bar as shown below

selenium_icon

when you click this icon you will get a selenium interface as shown below

selenium_interface

The basic concept of this tool is what ever you will run in browser it has capability of recording those steps so it is just play button and pause button game, no rocket science. You can easily run and use this.

I am sure it will reduce your testing effort and when when selenium ide will play your test cases you can take a deep breath and enjoy your coffee and snacks.

I hope this tip may be helpful to you somewhere.

Happy Holidays.

Regards,

RJ

Advertisements

How to split entity classes in a separate project from Entity Framework in easy step

Dear All,

Below are easy step to split the entity classes in a separate project. I have created a MVC sample project in below example. Now follow below steps

Step 1:- Add  a Ado.NET Entity Data Model  as shown below. I am using SQL Server “Friends” Database in this example.defaultedm 

Step 2:-

Once EDMX is added I got below structure as shown in below figure. Entities for each table object of Friends Database shown in below fig

defaultedmx

Step 3:- Now as our goal to separate this entity class  I added a new class project as shown in below figure

pocoentities

Step 4:-

Now in this class project add  EF 5.x Db Context Generator  as shown in below figure

newEFDbContextGenerator

Step 5:-

Now  click on Model.tt file in your new class project. Just edit  the Input file  as I edited in below fix you need to give your EDMX Path. 

Like I did “ using string inputFile = @”..\youredmxprojectname\youredmxname.edmx”

changethePathofEdmx

Step 6:-   Once this code is changed delete the all the  entities files from EDMX and rebuild  the project

Step 7:-  Once the file is generated you are good to go  just see as I got the files  in separate class project.

 

generatedEntities

I hope you will achieve the same with above steps.

So enjoy learning Smile

Your Host,

Rajat Jaiswal

How to create Web API ?

Dear Friends,

In Last article https://indiandotnet.wordpress.com/2014/02/23/what-is-web-api/ 

We have discussed what is Web API. Now in this article we will see how to create web API. So with out wasting much time lets start visual studio (In my case I am running VS 2013 web express).

So in my example I am creating a web API project for Friends. this API should return either all the friends or specific friend according to Id so lets start.

Step 1: Create a  new web project when you click on web project you will get following option. Select Web API option as shown in below screen shot.

project-WebAPi

You will get default project as below with defined folder structure

defaultProject

The main point here is to remember Model class should come in model folder & Controller class should come in controller folder

Step 2:- Once you click on Web API option project will open. Now Create a model (a simple class) with name Friend. this model class have basic friend’s property like his firstName, LastName,Id etc. as shown in below fig

FriendModelClass

Step 3:- Now create  a Friend controller so for this just add new item which is controller as shown in below fig

AddWebAPIController

In the above option I have selected Web API 2 controller Empty template

things to remember here the name of controller class will be use later on in your API URL so select the name properly and the controller class name should followed by controller.

In my case I have created controller with following name =”FriendController.cs”. So now your project structure is as shown below

CurrentProject_Structure

Step 4:- Now remember all the coding part need to be done here . I am creating two method here one method with name “GetAllFriends” and “GetFriendById”.

So as name suggest one will return list of all friends and one will return particular friend for a given id. If you see below instead of fetching data from database I have created a array of friends as shown.

ControllerDefinition

Now in above fig you saw two method with different return type. Now concentrate on GetFriendByID It’s return type is HttpActionResult. so if you see below in that particular method the return type is OK which means status code 200. It means http response will be return in this method.

Now another interesting part is you can add different attribute with method like HTTPGET, HTTPPOST,HTTPDELETE etc Just see in below screen shot as shown below.

HttpGetOrOtherAttributes

Now another interesting point is what if you want two attribute on same method then you can use below option which shown “AcceptVerbs”

AcceptVerbs

Step 5:- Now our most part is done now you need to access web API but before accessing web API you need to check route and if something is missing their then you need to modify WebAPI config  which you will get in App_Start function. In my case I have added API/{controller}/{action}/{id} which was not exist earlier. as shown in below fig

WebAPIConfigSettings

Step 6:- Now we are good to go now just run the application and type in url http://localhost:yourport/API/Friend you will get list of all the friends as shown below

FindListOfAllFriends

Now if you want to get specific friend with particular id then you have to write url like http://localhost:youport/API/Friend/1

You will get particular friend with that id as shown below

FindingSpecificFriendByID

 

Isn’t it simple ?

I hope you understand how easy to create Web API. Now in next step we will learn how to consume the Web API.

Mean while you can create different web api.

So enjoy till than

Your host,

Rajat

Why and Why not Asp.net 3.5 MVC Projects ? Asp.net 3.5 MVC Project series – IInd

Hello Friends,

Today we just try to make a sample project so I am taking here task to make a simple friend List in that list we can add friends and view friends.

So just follow the step as I mention below and we together make it easy

Step 1:- Add A project for Asp.net MVC as shown in below fig.

mvc1

Step 2:- once you done with this you will find default folders of Views, Model and controller.

The point to remember here is all the presentation layer comes in views folder and if there is sub folder in views so there must be a controller with that particular name.

As you see there is home folder in Views so in controller folder there must be Home controller exists.

The view name or we can say our page name will be the function or procedure in controller.

Suppose there is page in views –> Product –> ProductList.aspx

So in our project there must be a product controller and in that controller there must be a sub routine for product List.

There is also a shared folder in our application which is mainly used to keep shared views like Master Page & other custom controls. 

mvc2

Step 3:- Define views in home folder

1) Index.aspx :- it will be our default page. This page having default text and pictures of you

mvc3

2) AddFriend.aspx :- It is used to add friends in our database.

mvc4

3)ViewFriends.aspx:- it is used to search friend by location.

mvc5

3)SearchFriendsByArea.aspx:- it is used to find location of friend on Google map.

mvc6

 Step 4:- Now we create a database for it. In our database there is single table which is “TblFriends” with field lngId, strFirstName, strLastName, strEmailAddress, strAddress, strCity, strCountry, strphone,strBrief intro.

 Step 5:-Now and LINQ to SQL class which is  “FriendsDb.dbml”  in Model. This is use to intract with Database.

 Step 6:- We have Home Controller now we have to add different method in according to our View, Like Index, AddFriend, viewFriends, SearchFriendByArea

Once you done with this. Now we think about how the data will save from add friend.aspx. For this we just mention another function in home Controller which is Save Friend.

Save Method have all the parameter which is on the form like, strFirstName , strLastName etc.

Once you got all the require parameter we just going for add as shown below.

 Function SaveFriend(ByVal FirstName As String, ByVal LastName As String, ByVal Mobile As String, ByVal Email As String, ByVal Address As String, ByVal city As String, ByVal country As String, ByVal BriefIntro As String) As ActionResult

        ‘Require validation…

        ‘ Basic parameter validation

        Dim blnValidate As Boolean = True

        Dim errors As New List(Of String)

        If FirstName.Trim = String.Empty Then

            errors.Add(“Your first name is required!”)

            blnValidate = False

        End If

        If LastName.Trim = String.Empty Then

            errors.Add(“Your Last  name is required!”)

        End If

        If city.Trim = String.Empty Then

            errors.Add(“your city is required!”)

        End If

        If country.Trim = String.Empty Then

            errors.Add(“Country is required!”)

        End If

        If Address.Trim = String.Empty Then

            errors.Add(“Address is required!”)

        End If

        ‘Save Data i

        If blnValidate = True Then

            Dim clsFriend As New MyFriend

            clsFriend.strFirstName = FirstName

            clsFriend.strLastName = LastName

            If Mobile.Trim <> String.Empty Then

                clsFriend.strMobile = Mobile

            Else

                clsFriend.strMobile = Nothing

            End If

            If Email.Trim <> String.Empty Then

                clsFriend.strEmail = Email

            Else

                clsFriend.strEmail = Nothing

            End If

            If country.Trim <> String.Empty Then

                clsFriend.strCountry = country

            Else

                clsFriend.strCountry = Nothing

            End If

            If city.Trim <> String.Empty Then

                clsFriend.strCity = city

            Else

                clsFriend.strCity = Nothing

            End If

            If BriefIntro.Trim <> String.Empty Then

                clsFriend.strBriefIntro = BriefIntro

            Else

                clsFriend.strBriefIntro = Nothing

            End If

            If Address.Trim <> String.Empty Then

                clsFriend.strAddress = Address

            Else

                clsFriend.strAddress = Nothing

            End If

             db.MyFriends.InsertOnSubmit(clsFriend)

            db.SubmitChanges()

             ViewData(“Title”) = “Record is Saved”

            Return RedirectToAction(“ViewFriends”)

        Else

            ViewData(“Errors”) = errors

            Return View(“AddFriend”)

        End If

     End Function ‘SaveFriend

Step 7:- for searching we will do following thing

 Function SearchFriendsByArea(ByVal Area As String, ByVal city As String, ByVal country As String)

        ‘Search Friends And return

        Dim mylist = From f In db.MyFriends Where f.strAddress Like Area Or f.strCity Like city Or f.strCountry Like country Select f Order By f.strFirstName, f.strLastName

        Return View(mylist.ToList)

    End Function ‘SearchFriendsByArea

Here the things to understand the Return view Parameter. The Return view parameter is again a data collection which we will provide to search Friend’s View.

On this page we have to consider only one thing which is as follows

Inherits System.Web.Mvc.ViewPage(Of List(Of MyFriend))

 Means we provide View Data a data list of Linq Class which is MyFriends.

Now we can use it in aspx page.

<%  For Each mfriend As MyAddressBook.MyFriend In ViewData.Model%>

            <tr>

                <td>

                    <% =mfriend.strFirstName%>

                </td>

                <td>

                    <% If mfriend.strLastName Is Nothing = False AndAlso mfriend.strLastName.Trim <> String.Empty Then%>

                    <%=mfriend.strLastName%>

                    <%Else%>

                    &nbsp;

                    <% End If%>

                </td>

                <td>

                    <% If mfriend.strAddress Is Nothing = False AndAlso mfriend.strAddress.Trim <> String.Empty Then%>

                    <%=mfriend.strAddress%>

                    <% Else%>

                    &nbsp;

                    <% End If%>

                </td>

                <td>

                    <%=mfriend.strCity%>

                </td>

                <td>

                    <%=mfriend.strCountry%>

                </td>

                <td>

                    <% If mfriend.strEmail Is Nothing = False AndAlso mfriend.strEmail.Trim <> String.Empty Then%>

                    <%=mfriend.strEmail%>

                    <%Else%>

                    &nbsp;

                    <% End If%>

                </td>

            </tr>

            <% Next%>

 So in this way we just add records and view data.

You can download source Code from http://indiandotnet.tk

Thanks

Enjoy programming 🙂

Keep doing great Job 🙂

Why and Why not Asp.net 3.5 MVC? Asp.net 3.5 MVC Project series – Ist

1. What is MVC?
Answer: On of the most popular framework or we can say pattern is Model View Controller. It’s just like three tire architecture. This bifurcate our application in three different part or we can say layer which is presentation layer, business Layer and Data Access Layer.
Here we understand theree combination Model, View, Controller One by one.
As I mentiion above its three tier architecture design so here I explain why its three tire architecture.

1) View: – View is our presentation layer. Means what ever end user see or interact with our application is just View. In simple manner we can say it’s our forms either web or windows. If we taking about asp.net application or we application views are just our html Pages which we created normally. It’s not dependent on application Logic
2) Controller: – Controller is the part which decides which view should be render when user asks for some request. Or we can say it handle end user interaction.
Suppose I have requested “home.aspx” then its goes to controller and controller will decide which view he has to show to us. It’s our middle layer which we can business logic Layer.
3) Model: – Model is combination of our Database Layer + Business layer. It’s interacted with database like save, update, delete etc and also perform business logic.

So above are simple definitions for model view controller.
Now see below fig

mvc

In The figure you find three different entities. But there are some how dependent with each other
I will explain with the example let supposes a user request for customer data form.
Then the request first goes to controller and now controller is responsible to show a view
Suppose the view name is customerView.aspx then this view will be shown to the end user. Now what is the role of model here so model will provide data to view.

mvc1

Question: – why we use this?
Re use of code this first and most important advantage of MVC architecture. It’s single for web and windows we have to just change the views.

Suppose a company wants software of inventory on both windows and web then you don’t need to write whole code 2 times instead of this you have to write 2 views while model and controller will same for both. This is first and most important benefit.

multiplatformsupportmvc
Secondly Its give proper separation between presentation layer, Business layer and Data Layer.

As This blog is mainly for Asp.net and Sql Server so I will tell you for MVC dot net provide a new project template in Asp.net 3.5 which is Asp.net MVC project.
Now you thinking what earlier for previous version so here I will tell in earlier version dot net 1.1 Microsoft provide MUIAB (Microsoft User Inter Application Block) I will provide information an example for this in my next post.

Microsoft Asp.net 3.5 MVC project Support TDD (Test Driven Development) this is another most useful feature.

MVC use core html control which we used in asp classic (3.0) like Input, button so it is much faster then our web form application.

Microsoft Asp.net 3.5 project use URL is such a way which helpful in SEO (Search Engine Optimization).

Question: – why we don’t use it?
Again it’s depend on person to person according to there requirements or there preference that whether he want to use this pattern or not. According to me (as my experience and read from other articles) there is few disadvantage of using it.
The first and most important disadvantage which I feel is limitation in controls in direct use. There are many server controls link data Grid, List control which we used in web form project can not use directly in MVC project.
Lot of work in pure HTML which is some time irritating for the programmer who earlier works on asp. Net’s web form application with server controls.

In Next article we read basic of MVC (Model View Controller). Advantage & Disadvantage. In Next Session. I come with the example how we create a simple MVC project with asp.net 3.5
Till than friends do take care your self
Enjoy dot net
Enjoy MVC

Thanks & Esteemed Regards
From one and only one your Host 🙂
Rajat Jaiswal