.NET Client Profile is supported by .NET Ver. 3.5 and 4.0. It is designed for client applications like Windows Forms. Client Profile version of .NET Framework is lightweight subset of Framework. This enables quicker deployment and small installation packages. 

Web Application doesn’t support Client Profile version of the Framework.

 

Microsoft has removed Client Profile from latest version of .NET Framework 4.5 and hence with .NET 4.5 there is no Client Profile as shown in the image below.

 

 

Microsoft just introduced a new certification track MTA, Microsoft Technology Associate.
This is designed for the people who are seeking an entry point into the Microsoft technology world.

This track has exams especially designed for topics like:

  • .NET Fundamentals
  • Windows Development Fundamentals
  • Web Development Fundamentals
  • Security Fundamentals
  • Networking Fundamentals
  • Windows Operating System Fundamentals

etc…..

These exams will establish  a solid base for new Microsoft technology aspirants to become MCTS or MCSD certified later on.

An already experienced developer/professional in Microsoft Technologies, does need to earn this MTA exam, but having one won’t hurt, as all that matters is Rock Solid Fundamentals.

 

 

Nuget-Visual Studio Package

October 27th, 2012 | Posted by Vidya Vrat in Visual Studio - (0 Comments)

NuGet Package Manager Download URLProblem- Many times during development it become tedious to look for right assemblies to be added to the project’s references. For example, Entity Framework, Enterprise Library blocks, JSON etc.
Due to the nature of application’s dependency on right assemblies; developers spend a good amount of time in searching the right installer URL of the utility packages, or look for assemblies in the machine and then reference those.Solution- NuGet is an open source based developement focused system for implementing packages in the .NET platform based applications. NuGet is designed to simplify the process of bringing/adding Microsoft (Enterprise Blocks etc.) and various third party(Ninjectm JSON etc.) libraries into a .NET application during development.

Once you have installed Nuget, you no longer need to worry about looking for assembly references for various frameworks, blocks etc. for example, JSON, Enterprise Library, Entity Framework etc.

You just need to right-click on the References and click on Manage NuGet Package as shown in the figure below:

This will open a new window, in which you can search your desired package and install it as shown in the figure below:

Now if you will look under thre References, you will notice that assembly references are added through NuGet. NuGet helped you save the time and effrot to add existing assemblies or install and then add in case it was new.

Now, you have got the assemblies your application requires, you can begin with code now to invoke the functionality from added assemblies.

It’s productive isn’t it?
 

EnterpriseLibrary version- 5.0 Download url
Language used in code sample below – C#Logging is a very important feature for many applications and serves the very critical purpose in a software application’s life. Logging enables to look for monitoring data and also document what is happening in-side and out-side of the application; also known as auditing.

Most common places to log such activities, information and data are:
1- Flat files (.log/.txt)
2- Event logs (Windows event viewer) and
3- Database.

In the absence of logging application block, the logging code needs to be repeated in the application at many places. This code will also include .NET library and function calls based on type of place you want to log the information. Hence, logging application block simply de-couples the logging functionality from the application code.

Configuring the Logging Application Block

1- Open your Visual Studio project, if not already available, add an app.config file
2- Open Microsoft Enterprise Library console.
3- In the Blocks menu, choose “Add Logging Settings” option, this will appear as shown here:
 

 

4- Based on your requirements add listners (File, Event, Database etc.).

 

 

 

5- Describe “Event Log” target listner


6- Describe “Flat File” trace listner

7- Describe “Message Formatter”

 

Now save this configuraton by clicking File–> Save option. and choose your added .config file,
this will be modified and will appear as shown here.

 

 

Now you can add the code to enable the Logging from your application into the defined “Target Trace Listners” in our case “Flat File” and “Event Log”.

I have designed a Windows Form application which reads a file, from provided path location, if file is found it loads the cntent into the text box, else in case of an exception “FileNotFoundException” the error info is logged into the Log file (c:\exception.log) and Event Log.

 

 

C# Code will look like this

 

using Microsoft.Practices.EnterpriseLibrary.Logging;

 

private voidbtnReadFile_Click(object sender, EventArgs e)

{

StreamReader sr = null;

 

try

{

sr = new StreamReader(txtFilePath.Text);

 

txtFileContent.Text = sr.ReadToEnd();

}

catch (FileNotFoundException)

{

txtFileContent.Text=“Exception details logged log file
and Event Viewer”;

 

LogEntry objLog = new LogEntry();

 

objLog.Message = “Please provide valid Filename”;

objLog.Categories.Add(“File Read Error”);

 

Logger.Write(objLog);

}

 

finally

{

if (sr != null)

{

sr.Close();

}

}

}

 

 

Now if you open the C:\Exception.log you will see:

 

—————————————-
Timestamp: 10/1/2012 7:35:03 PM

Message: There is no explicit mapping for the categories ‘File Read Error’. The log entry was:
Timestamp: 10/1/2012 7:35:03 PM
Message: Please provide valid Filename
Category: File Read Error
Priority: -1
EventId: 0
Severity: Information
Title:
Machine: VIDYAVRAT-PC
App Domain: LoggingApplicationBlock.vshost.exe
ProcessId: 9164
Process Name: C:\VidyaVrat\Microsoft .NET\Application Code POCs\EnterpriseLibrary-Application Blocks\LoggingApplicationBlock\LoggingApplicationBlock\bin\Debug\LoggingApplicationBlock.vshost.exe
Thread Name:
Win32 ThreadId:13588
Extended Properties:

Category:

Priority: -1

EventId: 6352

Severity: Error

Title:

Machine: VIDYAVRAT-PC

App Domain: LoggingApplicationBlock.vshost.exe

ProcessId: 9164

Process Name: C:\VidyaVrat\Microsoft .NET\Application Code POCs\EnterpriseLibrary-Application Blocks\LoggingApplicationBlock\LoggingApplicationBlock\bin\Debug\LoggingApplicationBlock.vshost.exe

Thread Name:

Win32 ThreadId:13588

Extended Properties:
—————————————-

 

Also, if you open the EventVwr.exe then you will see:

 

This concludes that how Logging application block enables you to write small amount of code to do such a critical task of auditing.

 

 

 

 

 

 

using System;
using System.IO;
namespace FileRead_ExceptionHandling
{
class Program
{
static void Main(string[] args)
{
// declaring stream-reader here so it become accessible to the
// code blocks of try { } and finally { }
StreamReader sr = null;
try
{
// this assume you will have a file on C:\ as mentioned below
sr = new StreamReader(@”c:\TestCode2.log”);
string text = sr.ReadToEnd();

Console.WriteLine(text);
}

catch (FileNotFoundException ex)
{
Console.WriteLine(ex.Message + “\n
The wrong file name or path is provided!! Try Again”);
}
catch (Exception ex)
{
Console.WriteLine(“Try again” + ex.Message);
}

finally
{
if (sr != null)
{
sr.Close();
Console.WriteLine(“Stream closed”);
}
else
{
Console.WriteLine(“Stearm is Null”);
Console.WriteLine(“Try Again”);
}

// Performing stream-write operation to the same file
StreamWriter sw = new StreamWriter(@”c:\TestCode.log”, true);
sw.WriteLine(“Line 1”);
sw.Close();

Console.ReadLine();
}
}
}
}

 

 

There is a live .NET Web Service which offers all the curreny conversion eg. USD to INR etc.

This WS is available via live URL http://www.webservicex.net/CurrencyConvertor.asmx

This WS has a class CurrecnyConvertor which exposes one Function named ConversionRate and an enum named Currency which exposed the list of all the currencies like USD, INR, AED etc.

As you know Currency conversion will depend on two parameters ConvertFrom and ConvertTo and so the same is expected to be passsed while invoking ConversionRate function.

Here is a detailed list of steps:

1- Add a Web Reference to http://www.webservicex.net/CurrencyConvertor.asmx
2- Rename the Reference name to something more friendly like CurrencyConversionWS
3- In your project create an instance of the added Web service reference
4- On the created object invoke the ConversionRate function.
5- As mentioned above there is an enum which lists all the currencies and so access it directly from the object created.
6- Save the result into a double variable and multiply with your passed amount.
7- Multiply the amount you want to convert to the received conversion rate.

Here is the code you will require to have it all working:

CurrencyConversionWS.CurrencyConvertor objWS = new CurrencyConversionWS.CurrencyConvertor();

double usdToinr = objWS.ConversionRate(CurrencyConversionWS.Currency.USD, CurrencyConversionWS.Currency.INR);

double totalAmount = usdToinr * Double.Parse(textBox1.Text);

MessageBox.Show(totalAmount.ToString(),“Total Indian Rupees”);

This is how it will look like:

 

Microsoft Visual Studio and .NET has its own UnitTest framework which is separate from the NUnit or other Automation Testing Frameworks.

First of all, let’s understand What is a Framework? Framework is an Architectural term and it means “Collection of Components”.

Code Example of Test Automation using Microsoft Visual Studio 2010

Business Logic which we want to test using Automation
I have a business logic which does some maths calculation and is available via a MathLibrary.dll

The source code of this MathLibrary business logic component is as shown below:

using System;
namespace MathLibrary
{
public class MathClass
{
public int Sum(int n1, int n2)
{
if(n1<=0 && n2<=0)
{
throw new ArgumentException(“No Zero or Negative are allowed”);
}
else
{
return n1 + n2;
}
}
}

As it’s a dll component so test coverage of this is very critical to make sure that business logic is intact and returning right results.

To do so, instead of relying on a Manual Test Process through a UI which will be very cumbersome and tedious to continuously test the sanity of business logic, we can choose to Automate this test process.

As you might have noticed, we have written the Sum function (in MathLibrary.dll) in a Test Driven, style I.e the parameters passed are also being validated for all the possible test scenarios:
1- If aregument is +ve and non-zero then return the sum of passed arguments.
2– If argument passed is 0 “zero” then throw an exception
3- if argument passed is -ve then throw an exception

How to approach Test Automation in general

Irrespective of what Unit Test tool and development technology you use Test process depends on two things.

1- Expected – Before we really perform a test our Test case tells us what to expect by this test case to verify success in case of a Sum taking two ints, we expect it to return exact result of adding two numbers.

2- Actual – When you perform the test what your result is.

If Expected meets the Actual then your Test Case is Passed, otherwise your Test Case is Failed

Hence we have to achieve Test Coverage for all the Test Cases in the above mentioned test scenarios.

To do so, we will use Microsoft Visual Studio 2008 or 2010 and then open a New Test Project as shown in the image below:

Now Once you will have this project Loaded, it will have a file UnitTest1.cs in it, this is the file you will be automating all the Test Cases for the MathLibrary.dll (our business logic) we have created.

In order to Automate the Test Cases in Microsoft Visual Studio using Unit Testing Framework, you need to understand few more things:

1- Test Automation Framework – Microsoft has its Unit Testing Framework implemented in a namespace which is Microsoft.VisualStudio.TestTools.UnitTesting

2- [TestMethod] attribute – This is the attribute which needs to be present on each method which will actually represent a TestCase.

3- Assert class – This class is part of Microsoft’s Unit Testing framework, and we can use this class to verify if our Actual and Expected are same or not etc.

As mentioned above for each and every Test Case we have to write Automation code.

Note: Before we start coding the Automated TestCases, don’t forget to add all the References,
WebReferences etc. which your Test infrastructure will use.

I have covered Four Test Cases for Sum Function in MathLibrary.dll

// Test Case#1: to verify if passed ints are returning Right Result
[TestMethod]
public void TestSumResultAreEqual()
{
MathLibrary.MathClass objMath = new MathClass();

Assert.AreEqual(24, objMath.Sum(12, 12));
}

// Test Case#2: to verify if passed ints are Not returning Right Result
[TestMethod]
public void TestSumResultAreNotEqual()
{
MathLibrary.MathClass objMath = new MathClass();

Assert.AreNotEqual(25, objMath.Sum(12, 12));
}

// Test Case#3: to verify if passed ints are actually Zero
[TestMethod]
public void TestSumThrowExceptionWhenZero()
{
MathLibrary.MathClass objMath = new MathClass();

try
{
objMath.Sum(0, 0);
}
catch (ArgumentException)
{
// logging code will go here
}
}

// Test Case#4: to verify if passed ints are actually Negative
[TestMethod]
public void TestSumThrowExceptionWhenNegative()
{
MathLibrary.MathClass objMath = new MathClass();

try
{
objMath.Sum(-123, -456);
}
catch (ArgumentException)
{
// logging code will go here
}
}

Once you have coded all the Test Cases to Test the functionality, its time to build the code and a TestProjectName.dll will be produced.

There are two ways to Test your automation code now:

1- Using Visual Studio IDE

Build and then Run the project within Visual Studio, you will see all the TestMethods being executed and showing Test Results as shown in the image below:

2- Using Visual Studio’s command promptOpen Visual Studio’s command prompt and navigate to the folder where the TestProjectName.dll is located

and then run this command:mstest /testcontainer:TestProjectName.dll

Summary: This article explained the aproach to Test Automagtion using Microsoft Visual Studio’s Unit Testing Framework. Some basic fundamentals about Framework, what is expected out of a test and how to automate a business logic in a .dll form. The same approach can be used to even automate a WebService component etc.

 

 

If you are looking for Web Service project template in Visual Studio 2010 under .NET Framework 4.0 as shown in the image below, you will not find it.

In order to create a WebService using Visual Studio 2010 you need to switch back to .NET Framework 3.5, as shown in the image below, and you will be able to crate a WebServeice project.

VS 2010 Goes International

April 28th, 2010 | Posted by Vidya Vrat in Visual Studio - (0 Comments)

Read Somasegar’s blog post about this

If you have VS 2010 RC installed and now you try to uninstall it, it begins but hangs after sometime.
You continue to wait but neither it does anything nor it progress to the next step.
Most obvious solution to this problem is to shut down the system, restart and then un-install it again, it will pick from the features/options where it got hung last time.

This time there are bright chances that it will finish until the end, and you will see a Successful Un-Installation message