Monday, June 30, 2014

Web Test Automation Sample with powershell

Selenium -Web browser Automation

Reference :

Purpose- Automation UI Test -Useful for regression test and unit test.
Download Selenium Webdriver c#

  1. Open Powershell- Run ISE as Administration
  2. Add below code and f5.
  3. Source Code- * Give path of the WebDriver.dll


Thursday, June 26, 2014

Foreign Key Constraint vs Nhibernate

If you have worked extensively on nhibernate then you will understand the caveat it carries at time of implementation. One of the case is with foreign key constraint for one to many relationship in which it fails to insert rows for child as it always sends foreign key column value zero and when it tries to apply this it into constraint-data integrity conflicts.

Most of the solution suggests:-
1. Apply Inverse =true
2. Apply Cascade all

So on..

But all this solution doesn't work.

When one remove foreign key constraint it works absolutely fine. What it does under the hood?

1. It first insert the parent table enteries.
2. It then insert the child table enteries but keep the foreign key column value as zero
it tries to apply select scope_identity but it return null.
3. Then there are two update on parent and child table where it just update foreign key column with actual values.

The above step is tricky to understand but can be evident in sql profiler log.

Workaround- You can keep the foreign key but can disabled constraint( Disabled Constraint does not mean removing constraint) It still satisfy DDL best practice.


Wednesday, June 25, 2014

Part 3 Http Unrevealed- Connections

Parallel Connection-

Initially it is like one user agent-web browser can establish two connection with host webserver. Just imagine we have two files that needs to be requested therefore browser makes two requests and establish two connection to download the files.

IE6 used to have this 2 connection setup.

* Approach 1:
We keep files in different server in that case user agent can opens parallel connections to host server. In that sense, we states two connections is directly proportional to host and not IP addresses of the host. So we conclude two connection is dependent on host but independent of IP address.

* Approach 2:
With case of IE8 where it applies heuristics logics and it establish 6 concurrent connections w.r.t host.
Persistent Connections:-
 Connection: keep-alive
This is a state where we keep the socket opened or maintain persistent connection even it server one request response transaction for given user agent. It persist the connection between user agent and host and consume same socket opened for communication. With this there is no overhead on memory consumption, cpu utilization, less network congestion, less latency, more throughput and improves response time of given request.

The only demerits about this type of connection is falling prey of security vulnerability. Longer period of open connections can pose threat to security compromise. Some webserver close connections when idle even we can configure
user agent or webserver to close connection when idle for certain threshold limit.

HTTP/1.1 200 OK
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Connection: close

This close header indicates that connection will be closed as soon request is served with response and hence no subsequent request on same socket is available.

Pipelined Connections-

It opens up multiple connections and queue the requests into efficient packets. But this is not widely used.

Part 4: Http Unrevealed - Outside of Http

Outside of Http:
Proxy Server-
Is very much visible to end users. It takes users http request and take response back from server to the user.
Benefits of Proxy Server-1. In order to prevent users accessing restricted sites we can use proxy server to capture all http traffic at proxy server and thus setup strategy that will not send these requests to destination server. In this way we can ensure no one use the sites that is restricted.

2.Proxy server in fact can be used to inspect /probe the confidential message flow from system to server. In a way we can remove referrer headers that referenced organization resources such as images, files etc.

3. Proxy server can acts as access control to create http log that act as audit trail for http request that is send.
Type of Proxy
Forward Proxy Server-
This server sits close to client. This proxy help secure confidential information and can help filter traffic send from the client to destinations server.
Reverse Proxy-
is a proxy server that sits close to the server.This server can take off the load from destination webserver or any server for that matter. Take a case of compression of file or data using gzip which can delegated to this proxy server making destination server concentrate on processing of data or request.
Load Balanaced Proxy server-
All http request reaches this load balanced proxy server which will send requests to given server based on load as per round robin manner.

SSL Acceleration server-
This server will encrypt and decrypt http messages. This provides very secured level of isolation and can act as a centralized source to provide insulation to attack such as cross site scripting (XSS) or sql
injection for that reason.
Caching proxies-
Can act as centralized repository of cached data in distributed environment.

Caching -
HTTP response can have a value for Cache-Control of public, private, or no-cache
There is also a no-store value, meaning the message might contain sensitive information and should not be persisted, but should be removed from memory as soon as possible.
Public Cache- This is cache is applicable to whole system and is available for all users. Say for e.g we have logo, header and footer which will be consistent for all users.
Private Cache- This cache is specific to users , we can use Response.Cache for this kind of caching.
EtagThere are other ways to even identify given resource has been changed from last cache value is Etag. Etag is hashed values. Every time resource value or resources data changes it generated new hash value. Using this identifier we can even check the cache nature of the data.
HTTP/1.1 200 OK
Server: Apache
Last-Modified: Fri, 06 Jan 2012 18:08:20 GMT
ETag: "8e5bcd-59f-4b5dfef104d00"
Content-Type: text/xml

Tuesday, June 24, 2014

Part 2 : Http Unrevealed

In part 1 , I almost listed most of the intrinsic feature of Http. In part 2, the focus is more on how http interact with other layer protocol and ensure connectivity and communication.

Courtesy Succinctly Http: By Scott Allen

1. Http :it allows two Web Browser and Web Server( IIS or Apache) to communicate over a network.
2.TCP- Transmission Control Protocol

Browser extract host name and port . Opens TCP socket. Once ports is data is written into the socket.
TCP ensures data is transmitted to server and notify error if any. TCP also controls the flow of data, it has mechanism where it controls the rate at which that data being transfered thus ensuring enough time for receiver to process the data. Flow control is two way handshaking that TCP very well follows. Hence TCP is reliable protocol with flow control and error detection

3.IP: Internet protocol:-
IP ensures data moves across switches, routes, gateways , repeaters and other devices that help flow of data. IP even breaks down the larger piece of information into packets-fragment called data datagrams. This is indeed optimizes performance over network segment.

4. Data Link Layer- Ethernet .Eventually this IP datagram travels through  a optic fiber cable, wifi n/w or a satellite link.


 Wireshark is network analyzer for IP and TCP- network traffic.

Monday, June 23, 2014

Part 1 Http Unrevealed

Part 1 Hypertext Transfer Protocol
Whatever we see in www is possible through http protocol.

Few know-how to be familiar with HTTP.

Resource Locators: URL Uniform Resource locator.

URL path
://:/?# - host name

URL with keyword such as author is help rank your website for given search keywords in URL.It improves your Search Engine Optimization.

By default URL with out port points to port 80. Other than port 80, one needs to mention or host url with port number.

#sign represents fragment. The fragment locate a specific HTML element in a html page by control ids. For example bookmark in given page.

URL EncodingUnsafe characters such space and ^ carat are replaced with %
%20 is the encoding for a space character ( 20 is hexadecimal value = US-ASCII space character).
%5 represents ^

Resources and Media

Web page can request different resource format for display for end users they can be executable applications ,mages, XML , Json,video,HTML audio etc.
When a host server responds to an HTTP request, it returns a resource and also specifies the content type. This content type is called Media type. Media type is represented by Multipurpose Internet Mail Extensions (MIME) standards.
Client request content type html then it will send text/html

File Extension in URL

File extensions not always output requested file extension as given example
How it works:-
1. Client first look at response header content type tag send by host server.
2. If content type not available it will parse first 200 bytes of response to identify content type.
3. If client fails to identify content type and first 200 bytes of response then it look into URL file extension to guess content type.

Content Type Negotiation

Client can tell host server what content type it want at time of response. For example some resource of book url may suggest the client may display book content in some specific language and can be downloaded in specific format.In such scenarioncontent type negotiation plays a essential role.
Accept keyword in Response header suggests this.

Accept-Language: fr-FR

Http Request Method
Method Description
GET Safe Method:Retrieve a resource
PUT Store a resource
DELETE Remove a resource
POST Update a resource
HEAD Retrieve the headers for a resource

HTTP Response Request

A full HTTP request might look like the following.
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) Chrome/16.0.912.75 Safari/535.7
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3


HTTP/1.1 200 OK

Cache-Control: private

Content-Type: text/html; charset=utf-8

Server: Microsoft-IIS/7.0

X-AspNet-Version: 2.0.50727

X-Powered-By: ASP.NET

Date: Sat, 14 Jan 2012 04:00:08 GMT

Connection: close

Content-Length: 17151

Http Status Code Classification
Range Category
100–199 Informational
200–299 Successful
300–399 Redirection
400–499 Client Error
500–599 Server Error

With the help of  Fiddler Tool we can read and analyze the http response and request.

Tuesday, June 17, 2014

Iterator Enumerator with Yield Return.

public System.Collections.IEnumerable SampleIterator(int start, int end)
    for (int i = start; i <= end; i++)
        yield return i;
We can fetch the results from SampleIterator:-
ListClass test = new ListClass();

foreach (int n in test.SampleIterator(1, 10))
    System.Console.Write(n + " ");
// Output: 1 2 3 4 5 6 7 8 9 10

IEnumerable and IEnumerator

 class Test : IEnumerable, IEnumerator
        IEnumerator IEnumerable.GetEnumerator()
            throw new NotImplementedException();

        public object Current
            get { throw new NotImplementedException(); }

        public bool MoveNext()
            throw new NotImplementedException();
        public void Reset()
            throw new NotImplementedException();

IEnumerable has GetEnumerator() Method with IEnumerator return type. Whereas IEnumerator has one property Current (position) and two method MoveNext() and Reset().

Important Facts:- When you write a foreach loop in C#, the compiler generates code that uses an Enumerator.

foreach (small x in Big)
it's functionally equivalent to writing:
IEnumerator x= Big.GetEnumerator();
while (x.MoveNext())
   y= (Big)x.Current

Thursday, June 12, 2014

Code Analysis :Avoid Calling Virtual Method in Constructor.

The above code is referenced from Bill Wagner post. The intent is the base constructor get called first and which indeed called Vfunc of derived class as in runtime the derived class had to be initialized.

Wednesday, June 11, 2014

AggregateException in Unit testing Task Parallel Library Asyc Call

Some Background Exception Handling (Task Parallel Library)

If a task is the parent of attached child tasks, or if you are waiting on multiple tasks, then multiple exceptions could be thrown. To propagate all the exceptions back to the calling thread, the Task infrastructure wraps them in an AggregateException instance

Problem Statement:

Most of the time when we create a unit testing on Async Method- TPL it executes the unit test completely but ends up throwing AggregateException. This is due to the fact that it completes the one set of flow completely within a thread and comes out without executing all thread in parallel. If you see there is no UI and hence while testing the TPL must understand that unit testing is just to check the conditions of expected output with actual given a input as required whereas TPL works in different context. So ideally we must create test on non TPL methods in such case create separate methods to test on.

•An asynchronous method call will either produce a result immediately if one is available and continue execution in the current method or it will produce a result at a later time and immediately return control to the caller of the current method.
•The code that comes after an awaited method – the continuation – is what will be executed when the awaited method returns with a result.


Brute force method not recommended but can be used if just unit test case conditions with failed and pass data.
public class TestAsyncClassTest {
    public void SomeAsyncTest() {

Sunday, June 8, 2014

Data Driven Excel data source Unit Testing Using VS 2013


Introduction:- We're using excel as data source for data driven unit testing.

Test Data:

Trobleshooting Issues:
Probable Error: "Excel microsoft.ace.oledb.12.0 provider is not registered"
Download and install
2007 Office System Driver: Data Connectivity Components


Monday, June 2, 2014

Column Store Index in Sql Server 2012

The data in dataware house keep growing day by day , data  processing in data mart sometimes becomes unmanageable. The larger point is performance and to keep things at its bench mark we need proactive setup therefore Column Store Index is one of the important facility we can use in table to speed of query performance.

Courtesy above blog post


Limitations of SQL Server ColumnStore Indexes

There are several limitations of using SQL Server ColumnStore indexes over Row Store indexes including:
  • A table with a ColumnStore Index cannot be updated
  • ColumnStore index creation takes more time (1.5 times almost) than creating a B-tree index (on same set of columns) because the data is compressed
  • A table can have only one ColumnStore Index and hence you should consider including all columns or at least all those frequently used columns of the table in the index
  • A ColumnStore Index can only be non cluster and non unique index; you cannot specify ASC/DESC or INCLUDE clauses
  • Not all data types (binary, varbinary, image, text, ntext, varchar(max), nvarchar(max), etc.) are supported
  • The definition of a ColumnStore Index cannot be changed with the ALTER INDEX command, you need to drop and create the index or disable it then rebuild it
  • You can create a ColumnStore index on a table which has compression enabled, but you cannot specify the compression setting for the column store index
  • A ColumnStore Index cannot be created on view
  • A ColumnStore Index cannot be created on table which uses features like Replication, Change Tracking, Change Data Capture and Filestream