Pages

Search This Blog

Thursday, February 12, 2015

Visual Studio Tips and Tricks

Visual Studio Tips and Tricks

Selecting an updating code vertically

Hold down SHIFT + ALT while you’re selecting a code snippet. Now if you move the arrow keys , you can select vertically
Now you can update the code simultaneously too , if you type all vertically selected code line will be updated.

 

Navigating between open files

Press CTRL + TAB or CTRL + SHIFT + TAB to open this overview window. You can then move around using the TAB key or the arrows.

Cut the whole line

If you mark a text and press CTRL + X that text will be cut. But if you don’t mark any text and press the same CTRL + X the whole line (including carriage return) will be cut. You can also press CTRL + L to cut the whole line without the carriage return.

Select active document in Solution explorer

If you are having a lot of files and folders in your project you may face problem to get the active document. Here’s the solution:
Press the Left Right arrow button in solution explorer to navigate to current document.


Inserting snippet (way of saving a lot typing)

Using snippets you can save a lot for your typing.
To insert snippet navigate to where you want to add and press Ctrl + K and Ctrl + X to open snippet windows (Or right click and choose insert snippet) . Use up down navigation keys to move through list or press any character to navigate to particular item.
Press enter to insert snippet. Use the tab key to move between fields in the code.



 

Wrapping a code block inside other predefined code blocks

Just select the code block which you want to wrap inside other code blocks and Press Ctrl + K and Ctrl + S to open code blocks list (or right click and select Surround with).
Select from the list in which code block you want to wrap your existing code and press Enter.

Implementing interface

Put the cursor to the interface which you want to implement and press Ctrl +. (Period) and select implement interface from list (or right click and select implement interface from menu) , all the functions of that interface that needs to be implemented will be populated automatically.


Wednesday, February 11, 2015

Plan and Manage Testing Projects Effectively


Project planning is one of the pivotal elements in the project management process.

Test planning process

    Here below, is a walk-through of the various stages in the test planning process, discussed concisely.
Stage #1: Review and analyze the requirements 

This is the first step for any project and plays a very important role in any testing project. While trying to analyze the requirements, the test team has to identify and hence determine what items have to be tested. These items are heavily based on how the end user will consume the system and hence has to be measurable, detailed and meaningful.
The items or features that are identified generally describe what the particular software or product intends to do; characterized as functional requirements. There can also be some non-functional requirements identified such as performance or end to end software components’ interaction.
The people who’re aware of the business goal and can suitably define the requirements needed are generally part of this activity. The requirements are then documented and circulated for reviews. All the review comments and feedback must be incorporated to drive the document to the final sign-off.
Stage #2: Scope of testing

The scope of testing is generally an extension of the requirement analysis phase and mostly considered as a single activity, since they go hand in hand. Once the requirements are out, the test team determines what items are to be tested and what not.
For example: one team is dedicated for FVT (Function Verification Test) and SVT (System Verification Test) will have a completely different scope for testing, and globalization may or may not be performed by FVT and so on.
Also if the test project requires automation, the feasibility of that is also evaluated here. Having a clear scope defined, will prove invaluable to the management to clearly figure what has been tested and which team has covered the testing effort. 



Stage #3: Design the test strategy according to the scope 

The test team after gathering the requirements and identifying the scope of testing, will then put out a high level document called the test strategy document, defining the testing approach to achieve the test objectives.
A test strategy document is not meant to be updated too often.
On a high level, the content of the test strategy document will have the scope and objective of the testing, the approach, roles and responsibilities of individual test teams, tools identified for testing, the metrics identified, risks and mitigation plans, reporting and tracking mechanisms, etc.
Stage #4: Identify the required tools needed for testing and management 

Based on whether automation is possible and whether CLI (Command Line Interface) or GUI automation is targeted, the corresponding tools need to be identified. 
There also have to be tools identified for test management which will help in creating and assigning tasks, tracking the test progress, identifying roadblocks and generating reports indicating progress. We will discuss this more in detail in the second part of the tutorial. 

Stage #5: Estimate the test effort and team 

Correct effort estimation can prevent any time delays and dynamically enable the re-balancing of resources as required.
The primary factors that would influence this activity are: the size of the team, the skills within the team, the attitude of the team and the schedule.
It is mandatory to have the effort estimations reviewed by the team to keep in line with these factors which is directly proportional to their interest levels. 

Stage #6: Define test schedule 

Once you have the testable items that have been broken down into logical line items, the sizing estimate complete for the specified piece of work, a measurable test schedule has to be defined based on all these and the assigned testers.
Stage #7: Enablement plan

Whether it’s a new project that has to be tested or an enhancement of a previously existing system, the test team must be trained not only technically but also with respect to the overall test process being followed.
Stage #8: Determine and procure the test environment

Identify the needed infrastructure required for testing the system and initiate all the requests to acquire the needed hardware, software and networking pieces to support the testing.
This is a crucial element in the planning phase as this will govern the stability of the test environment, which will have a direct impact on the defects produced.
Stage #9: Identify test metrics 


Test metrics are generally the quantified method to derive the quality of the product or system.
At the beginning of any project these measurable units need to be level-set which aid in determining whether there are any opportunities for improvement. Generally for quality audit purposes, the metrics are direct indicators of the product and process quality.

Stage #10: Create the softwaretest plan, reviews and approved 

A test plan document is more test centric and explains “what to test”, “when to test”, “how to test” and “who will test” which is determined from technical documentation such as use case documents, High-level designs, etc.
Till now, we discussed about the different stages in Project planning.
While each stage can be a tutorial in itself, this portion of the article aims to bring out the less commonly talked about planning tasks. These tasks if not given suitable fore-thought, will have an adverse effect on the test team and hence the product.
Let’s take a look at these tasks, their importance and tips to constantly keep improvising them in order to manage the QA project effectively.

Effective management of a Test project 

When effective planning techniques are applied, any risks or errors can be easily identified even before testing actually commences. Although each of the tasks below are interrelated with each other, but it was worth giving them a separate mention.

Allocation and distribution of tasks 

This stems from the Effort Estimation and sizing in the planning stage. Keeping in mind skills, attitude, schedule and size of the team, here are some pointers for allocation of tasks:
#1) It’s a very good practice to sit the team down and communicate the objective and rationale behind the specified task very clearly. Knowing how a particular piece of work fits in the overall scheme of things, will help people derive a meaningful method of accomplishing them and will enable them to put their best foot forward.

#2) Prepare a skill chart of all the team members and accordingly assign the tasks. Also keep in mind that a fair chance must be given to even junior members.

For example: If a task is large, it can be split within a senior and junior member. Doing this will enable leadership qualities in the senior member and will also build on the junior member’s knowledge. If a task is complex, have 2 or more senior members contribute to it.

#3) Once an initial skeleton of the task assignment with the schedule is decided, float it around within the team and have them review it. Also explain the motive and logic behind the assignment.
Before finalizing the assignment, a good idea would be to check with the individual if they agree with it or they have any other suggestions. If there are no objections, discuss the schedule and the kind of status reporting required from their end.
A feedback can also mean the individual does not agree with the allocation. Discuss with individuals on why they disagree with it and respect their opinion. If the concerns expressed are valid, look out for options to re-balance the assignment, such that there is no risk to the task being completed on schedule.
#4) Agree on the mode of reporting that is expected. Allow the individuals to decide, if they want to give an email update or using any other informal modes. Be approachable and instill the feeling that they can approach you anytime they feel they are getting stuck or if there is anything preventing them from achieving the goal.
#5) Identification of the required tools to track the required tasks is essential. This will help timely review of the tasks that are still not yet worked upon, the ones in progress and the ones that are completed.

Resource management tips


 #1) More often than not, testers are always under high pressure due to stringent project deadlines, being short staffed or excessive content suddenly being added with no change in project schedules.
In such cases if you foresee that the timelines may get hampered, discuss with the management and have the scope accordingly modified.
#2) It’s very important to keep the communication lines always open more with the testers in such cases. Discuss with the testers the current situation and indicate how these changes happen and get translated top-down.

#3) There will always be defects, technical issues, queries that would need to be resolved that would have a direct impact on the project status. Always try to diminish the gap between the development and test teams so that issues related to defects or other technical queries are sorted quickly.
Instill within each tester a sense of ownership, such that they are in a confident position to drive and lead discussions to resolve technical queries or issues with the management or developers at any given point.
#4) Schedules always have a good chance of going haywire, so don’t set expectations to the management from the test team of always being able to stretch themselves.

Test tracking / tools usage for reporting 

Management often reacts with raised eyebrows when the actual status is communicated to them. Here are some tips on how to get those eyebrows down to a reasonable degree.
#1) Testers deal with a lot of instability while testing and many times it so happens that multiple people ask them for progress as different levels. They find it exhaustive and an overhead to perform these administrative tasks.

#2) Have regular checkpoint/ scrum meetings with the test team and analyze if things are going smoothly. Interlock with them to see how far they have come, what is in progress, what is needed to be done and what is holding them back. In case someone is feeling overburdened, take action to do some re-balancing in order for smooth execution.

#3) Have regular meetings with the management and make them realize that the lead is the point of contact for any questions related to the status and individual testers can be asked to pitch in only when required.
Try and showcase the test team as much as possible, apart from communicating status. If a tester has filed an important defect, showcase and appreciate it in a larger audience. This will motivate everyone to raise their bar.
#4) Needless to even mention that the most accurate and transparent manner of reporting status is to have tools identified for test management / reporting.



This tool helps in defining a project in phases, gist of tasks required with a breakdown of the major and minor tasks allocated to each of those phases, effort estimations, identification of dependencies between tasks and assignment of resources. In this way this helps with efficient tracking and management of a project.




Configuring Permissions on Database Objects

Configuring Permissions on Database Objects

Creating a Login
To access the Database Engine, users require a login. The login can represent the user's identity as a Windows account or as a member of a Windows group, or the login can be a SQL Server login that exists only in SQL Server. Whenever possible you should use Windows Authentication. By default, administrators on your computer have full access to SQL Server. For this lesson, we want to have a less privileged user; therefore, you will create a new local Windows Authentication account on your computer. To do this, you must be an administrator on your computer. Then you will grant that new user access to SQL Server.
Procedures
·         To create a new Windows account
1. Click Start, click Run, in the Open box, type %SystemRoot%\system32\compmgmt.msc /s, and then click OK to open the Computer Management program.
2. Under System Tools, expand Local Users and Groups, right-click Users, and then click New User.
3. In the User name box type Deepanshu.
4. In the Password and Confirm password box, type a strong password, and then click Create to create a new local Windows user.(as show below)



·         To create a login
1. In a Query Editor window of SQL Server Management Studio, type and execute the following code replacing computer_name with the name of your computer. FROM WINDOWS indicates that Windows will authenticate the user. The optional DEFAULT_DATABASE argument connects Deepanshu to the TestData database, unless her connection string indicates another database. This statement introduces the semicolon as an optional termination for a Transact-SQL statement. CREATE LOGIN [computer_name\Deepanshu] FROM WINDOWS WITH DEFAULT_DATABASE = [TestData]; GO This authorizes a user name Deepanshu, authenticated by your computer, to access this instance of SQL Server. If there is more than one instance of SQL Server on the computer, you must create the login on each instance that Deepanshu must access.
Note Because
Deepanshu is not a domain account, this user name can only be authenticated on this computer.








Granting Access to a Database
Deepanshu now has access to this instance of SQL Server, but does not have permission to access the databases. She does not even have access to her default database TestData until you authorize her as a database user. To grant Deepanshu access, switch to the TestData database, and then use the CREATE USER statement to map her login to a user named Deepanshu.

Procedures
1.       Type and execute the following statements (replacing computer_name with the name of your computer) to grant Deepanshu access to the TestData database. USE [TestData]; GO CREATE USER [Deepanshu] FOR LOGIN [computer_name\Deepanshu]; GO Now, Deepanshu has access to both SQL Server and the TestData database.


Granting Access to a Database Object
As an administrator, you can execute the SELECT from the Products table and the vw_Names view, and execute the pr_Names procedure; however, Deepanshu cannot. To Deepanshu the necessary permissions, use the GRANT statement.

1. Execute the following statement to give Deepanshu the EXECUTE permission for the pr_Names stored procedure. GRANT EXECUTE ON pr_Names TO Deepanshu; GO
Note : If the table, the view, and the stored procedure are not owned by the same schema, granting permissions becomes more complex.

About GRANT
You must have EXECUTE permission to execute a stored procedure. You must have SELECT, INSERT, UPDATE, and DELETE permissions to access and change data. The GRANT statement is also used for other permissions, such as permission to create tables.

Summary: Configuring Permissions on Database Objects

Logins give users permissions to connect to SQL Server. Users are logins that can access a specific database. Use the GRANT statement to give users permission to read and to access and change the data. A view is a single SELECT statement and looks like a table to the user. A stored procedure is one or more Transact-SQL statements that execute as a batch.

Serialization In C#

Serialization In C#
Serialization/De-serialization is a very important feature of an application, especially when it needs to communicate with another application by sending and receiving data. Because, generally, two different applications (also may be of different platforms) can’t understand one another one’s internal data structure. In which case, XML data (Extensible Markup Language) can be a good bearer to make the communication between them easier. So, now comes the requirement to creation of the XML data and constructing/retrieving data to/from XML. Although, it’s possible to create the XML file manually with own defined tag and manipulate them with LINQ to XML or so, there is a great and more efficient/quick solution from .NET for this purpose, where we can serialize/de-serialize a .NET class (here c# class) very easily without worrying that much.
In this blog, I am going to show you how to do xml serialization with c# code examples. Here I will be reading and writing a settings class. If you need similar settings class and read/write that from your application, then you can re-use the complete class that i am going to put at the end of the post.

 

Serialize A C# Class To XML File:

For performing a complete XML serialization of c# class and save it to a physical XML file, we will need help of 2 different types of .NET classes.
One is System.Xml.Serialization.XmlSerializer class (same class will be needed in De-serialization, so better importing the System.Xml.Serialization name space at the top of the class page.).
Another is System.IO.StreamWriter (corresponding reader class will be used on De-serialization, both are under common name space System.IO). XmlSerializer instance will do the main task of serialization and ‘StreamWriter’object will write the resultant serialized XML to a given file. Following are the code snippet for accomplish this:
string path = "MySettings.xml";
XmlSerializer x = new XmlSerializer(settings.GetType());
StreamWriter writer = new StreamWriter(path);
x.Serialize(writer, settings);


See it’s very simple isn’t it? We just have to call the ‘Serialize’ method with parameters of the writer and object to serialize. Just for your information, you can also use other type of write classes (such as ‘TextWriter’) also instead of ‘StreamWriter’ , checkout the available overloaded methods of the ‘Serialize’ function for more details.
After the serialization completes, you will see a XML file named ‘MySettings.xml’ in the debug directory (as it’s treated as the current directory by the application). Let’s Assume we are using a settings class that we are creating a XML file of, is as like following code sample:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyApplication.Config
{
    public class MySettings
    {
        #region Properties
         
        /// <summary>
        /// get/set the property 1
        /// </summary>
        private string property1= "";       
        public string Property1
        {
            get
            {
                return property1;
            }
            set
            {
                property1= value;
            }
        }

        /// <summary>
        /// get/set property 2
        /// </summary>
        private string property2= "";
        public string Property2
        {
            get
            {
                return property2;
            }
            set
            {
                property2= value;
            }
        }

        #endregion

        public MySettings()
        {
        }
    }
}

For the class like above, the resultant XML file should contains texts as like follows:
<?xml version="1.0" encoding="utf-8"?>
  <Property1>Property1 Value</Property1>
  <Property2>Property2 Value</Property2>
</MySettings>


De-Serialize A XML File To C# Class:

This is also almost similar as the serialization. This time, we will be using two classes, XmlSerializer and StreamReader (instead of StreamWriter). Here is the sample code to accomplish this:
MySettings settings = new MySettings();
string path = "MySettings.xml";
XmlSerializer x = new XmlSerializer(typeof(MySettings));
StreamReader reader = new StreamReader(path);
settings = (TVSettings)x.Deserialize(reader);


Notice that, we have to pass the type of object we are trying to De-serialize (as well as serialize), so you must have to know the type of object that will be created from the XML file.

Custom XML Serialization/De-serializer Class:

Here is the code block of a complete custom class that will read/write XML file from/to c# classes:
public class SettingsManager
    {
        /// <summary>
        /// Write Configuration To XML File
        /// </summary>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static bool Write(MySettings settings,string path)
        {
            try
            {
                XmlSerializer x = new XmlSerializer(settings.GetType());
                StreamWriter writer = new StreamWriter(path);
                x.Serialize(writer, settings);
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// Read Settings
        /// </summary>
        /// <returns></returns>
        public static MySettings Read()
        {           
            TVSettings settings = new MySettings(string path);
            try
            {
                XmlSerializer x = new XmlSerializer(typeof(MySettings));
                StreamReader reader = new StreamReader(path);
                settings = (TVSettings)x.Deserialize(reader);
                return settings;
            }
            catch
            {
                return settings;
            }
        }
    }


Purpose Of ISerializable Interface In Serialization:

You will notice that, we haven’t implemented any ISerializable interface or use any ‘Serializable’/’NonSerializable’ attribute. If we can do without them, why they exist in .NET? Ans is, of course it has quite significance. There are several points to consider regarding this matter:
·         Extending ISerializable interface is required in the cases where .NET objects need to control their own serialization and De-serialization. And also, its used to provide custom binary serialization, usually for ‘BinaryFormatter’.
·         What we just practiced, XmlSerialization, only use properties for the process, ISerializable isn’t required here as XMLSerializer can take care of it very well.
But still, its always best to extend the classes from this and mark ‘NonSerialized’ for which serialization won’t use for.

XML Serialization with IXMLSerializable:




If you are writing a class that will need majorly for XML serialization, you can also follow another simple procedure then described above. Simply, just implement IXMLSerializable interface. Then you will need to implement 3 methods which will be as like following code example:


public System.Xml.Schema.XmlSchema GetSchema()
{
    throw new NotImplementedException();
}

public void ReadXml(System.Xml.XmlReader reader)
{
    throw new NotImplementedException();
}

public void WriteXml(System.Xml.XmlWriter writer)
{
    throw new NotImplementedException();
}

You just need to pass the write/reader (XMLReader/XMLWrite) as parameter to do the read/write operation.