Testing/Debugging/Logging

Unit, integration and regression testing

2 options to write tests for WCF Services

When writing Integration Tests for WCF Services, you have 2 options to access SUT(system under test)1. Inproc – Test Classes are calling methods from application DLLs directly.2. External – Tests are calling external services using client proxy with specified URL.If you own the code of the service, the Inproc method is preferred as it is allow to test units rather the whole object as black-box.If your tests are external clients of the service determined by URL, you need to have the service installed ......

Number of Unit test projects in Visual Studio solution

Some time ago I have discussion with my co-worker how to organize test projects. Should we have a single test project that does all sorts of things and references every project?It is good to have one integration test dll, but for unit tests, what is the point merging everything into one.In ideal world I agree that small independent projects are better. Unfortunately we have solution size limitations From http://stackoverflow.com/qu... ......

Override ToString() using Json serialization or something else.

When creating a new data class, it’s a good idea to override ToString() method to output most of the data.It will help to see details in logs.The only exception if the class has a sensitive data like CreditCard number or password.For DataContract classes just usepublic override string ToString() { //Use JSON as the simplest serializer string sRet = this.ToExtJsJsonItem(); return sRet; } Sometimes it is useful to create extensions to standard .Net classes.E.g. In CookieHelper class I've created public ......

Deploy PDB files into production to ease exception report investigation.

For a long time I believed that PDB as a part of debugging information should not be included in production deployment. Recently my colleague suggested to copy them to simplify exception investigations. The following SO discussion convinced us that it is a good idea ( at least for web sites). http://stackoverflow.com/qu... These files will not be exposed to the public if kept in the right places (website\bin). ......

Default Enum initialisation by MS Create Unit Tests wizard.

VS 2012 doesn't show Create Unit Tests wizard. However it can be used - see Where is the “Create Unit Tests” selection? andhttp://dl.my/2013/create... found the Wizard creates quite funny default for enumerator- to use constructor.PaymentType paymentType = new PaymentType (); // TODO: Initialize to an appropriate valueI would prefer t have first/default enum value, e.g. PaymentType paymentType =PaymentType.None ;I should suggest it to ALM Rangers, who ......

EntLIb editor corrupts config files

I've tried to use Microsoft Enterprise Library(EntLIb) editor, as it was suggested in http://weblogs.asp.net/suku... but after changes all comments in config files were removed. Always consider to move any Enterprise Library configurations to a separate file before editing ......

Static methods not always bad for testability

Some time ago I've posted a few links about What is testable code?Reading the links someone can feel that any static methods are bad for testability. However it is a wrong impression- static methods without external dependencies are good for testing. http://programmers.stackexc... is nothing wrong with static methods and they are easy to test (so long as they don't change any static data). For ......

Enterprise Instrumentation: The 'sessionName' parameter of value 'TraceSession' is not valid

We are still using Enterprise Instrumentation(that was created during .Net 1.1 time)In new Server 2008 environment and IIS 7 we have the following errors:The 'sessionName' parameter of value 'TraceSession' is not valid. A trace session of this name does not exist in the TraceSessions configuration file for Windows Trace Session Manager service. Ensure that a session of this name exists in the TraceSessions configuration file and that the Windows Trace Session Manager service is started. at Microsoft.EnterpriseInstrum... ......

Adding PostSharp to new projects, when it's installed for some projects in solution.

Recently I've posted my experience with installation of PostSharp Once PostSharp is installed in solution's packages folder for some project(s), I often need to add PostSharp to another project in the same solutionSection "Adding PostSharp to your project using PostSharp HQ" of documentation described the process quite well.I only want to add that the actual location of PostSharp HQ ( if it was installed from NuGet) is[solution root ]packages\PostSharp.2.1.7.1... ......

Assign multiple test categories using TestCategoryAttribute

I am using TestCategoryAttribute to filter which tests to run during builds and wandered, how to -how to assign multiple test categories.According to constructor documentation only single category can be specified. However TestCategories Property (plural!)can return multiple categories.Grouping Tests into Test Categories: You can add an automated test to one or multiple test categories using a test attribute. Each test can belong to multiple test categories.The recommended approach from MSDN How ......

What is testable code?

We are improving quality of code and trying to develop more unit tests. The question that developers asked was "How to make code testable ?" From http://openmymind.net/2010/... First and foremost, its loosely coupled, taking advantage of dependency injection (and auto-wiring), composition and interface-programming. Testable code is also readable - meaning it leverages single responsibility principle and Liskov substitution principle.A few practical ......

Dump an arbitrary object To Html String

For debugging purposes me and my collegue wanted to dump details of the arbitrary object, and created function that uses LINQPad Dump functionality (thanks to http://stackoverflow.com/a/... and original http://linqpad.uservoice.co... discussion) public static string DumpToHtmlString<T>(this T objectToSerialize) { string strHTML = ""; try { var writer = LINQPad.Util.CreateXhtmlWri... ......

Extract substrings starting with known text from long lines

I’ve received a .csv report from TripWire logs, where each entry is a long text strings.I needed to extract some substring from each row, e.g “ErrorCode: ABC1234” where preceding text is constant, but actual error code could be different. In TSQL I can do someting similar using patIndex and substring, e.g.select text,substring(TEXT,PATINDEX ('%ErrorCode:%',TEXT),10)In C# I can do it using RightAfter and TrimLength from My StringHelperRightAfter(Text... But I was able to ......

How to disable messages for category based on severity in EnterpriseLibrary logging configuration

Microsoft documentation article Source Schema for the Logging Application Block is very hard to follow,the set of articles http://www.education.vic.go... is much betterFinally I found Log Event to Listener Routing in Enterprise Library article, that very clear described available options , how to disable/enable logging There are three Filters provided out of the box including a LogEnabledFilter which is a very effective ......

Compiler doesn’t report missing 'Microsoft.Practices.ServiceLocation”

I’ve upgraded Enterprise Library form 4. to 5 and replaced references to the DLLs (in particular we are using EnterpriseLibrary.Logging”) Compiler doesn’t report any errors about missing dependencies however at run time I’ve got Could not load file or assembly 'Microsoft.Practices.Servic... I had to add the library explicitly. It will be good if the error will be shown during the build. Related links http://stackoverflow.com/qu... ......

DDD Melbourne -lessons learned

I've attended DDD Melbourne and want to list the interesting points, that I've learned and want to follow. To read more: * Moles-Mocking Isolation framework for .NET. Documentation is here. (See also Mocking frameworks comparison created October 4, 2009 ) * WebFormsMVP * PluralSight http://www.pluralsight-trai... * ELMAH: Error Logging Modules and Handlers Great for new sites or sites without error logging/monitoring. However if you site already have working error ......

Command prompt utility to copy files for specified time range

I've tried to find an utility that will allow to copy files from big folder for specified time range. The discussion in experts-exchange suggested to use RoboCopy (http://www.microsoft.com/d... For the specified date command e.g 2009-11-24 command should be: Robocopy FolderFrom FolderTo /MINAGE:20091125 /MAXAGE:20091124 Note that for 1 day selection MINAGE should be one day BIGGER than required date. I still wish ......

Do not check-in DEBUG specific code.

We are using .Net Remoting to interact beteeen client and back end server. I needed to call a method from services class. For debugging purposes I decided to create the class directly. It was easier to debug without starting extra back-end process. The code was like the following: IMyServices services = (IMyServices)RemotingHelper... #if DEBUG services = new MyServices(); #endif // Process the task services.ProcessItems(Items... During the development I checked ......

Windows Workflow: Concatenate all parents QualifiedNames- instead of call stack

MSDN Debugging Workflows tells that The entries in the Call Stack window are a depth-first search of executing activities. You can double-click an entry to put focus on the selected activity.-It doesn't work for me. The text on stack trace is not meaningful, when activities are described. > codeRaiseEvent_ExecuteCode(... sender = {codeRaiseEvent_CAGPNRIterate [System.Workflow.Activities... System.EventArgs e = {System.EventArgs}) Line 671 C# System.Workflow.ComponentMo... ......

Logging application block-how configure different listeners for different level of message.

I've asked on codeplex EntLib forum logging application block-how configure different listeners for different severity? and AvanadeSupport gave me the answer to use "Filter" property of the tracelistener. MSDN Source Schema for the Logging Application Block documents listeners Child Element (loggingConfiguration)/add Child Element Now I am able to make configuration like the following <loggingConfiguration name="Logging Application Block" tracingEnabled="true"> <categorySources> <add ......

Full Testing/Debugging/Logging Archive

«August»
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456