.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan
Santhakumar Munuswamy
Fauzul Azmi
Asad Ali
Post New Web Links

NUnit and public static readonly

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net
 

I have an app that I am testing with NUNit.  The project im testing has several helper classes that are created as public static readonly.  When I run the NUnit tests, they all fail with the same error


Systems.Code.Test.TransactionTest.CreateDataContext_ConnectionString_ReturnsDataContextObject:
SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.
  ----> System.NullReferenceException : Object reference not set to an instance of an object.
Systems.Code.Test.TransactionTest.CreateDataContext_ConnectionString_ReturnsDataContextObject:
SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.
  ----> System.NullReferenceException : Object reference not set to an instance of an object.

I kept getting this error despite stripping out all


View Complete Post


More Related Resource Links

Static Class for Beginners

  
In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static

abstract away the source of the connection string using a class with a static property.

  
ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Encapsulation
Let's abstract away the source of the connection string using a class with a static property.

Public Shared function doubt????

  
Hi
I am using VB.net/ASP.NET and SQL Server 2000 for a web application.

For populating the dropdowns, I wrote a Public Shared function LoadDDL(), in which I pass the dataset and dropdown name to set.

I have my doubts that this function will produce unexpected results for concurrent users. And will mix the results among sessions because it is a Shared function.

I am confused here. Is it the right way to go?

Please advice. Thanks in advance.

Pankaj

NUnit

  

Im pretty new to NUnit and am beginning the process of setting up my tests.  Some of these test involve a database, specifically checking a particular value against a value in a database and if its not greater than the last retrieved value, flag an error.  Whats the best way to test in this scenario ?  should I write one value to a database then create another value thats out of sequence and run a database query ?  This would involve putting a known value into the table, then running the query with another value.

There is no rollback attribute for nunit, so I gues using TransactionScope would work, that way I could return the database to a known state after the test.  There tables have foreign keys so that means adding a lot of extra 'dummy' data first to some of the other tables.  Is this sort of 'testing' the best way ?  I basically need to perform the test based on an existing data value and I guess this must be pretty standard stuff, so whats the best way ?


As I understand it, the tests should be self contained, so any data i insert into the database during the test should be removed afterwards, is this correct ?  If so, it means I need to insert test data into 6 additional tables just to test one function, then remove it after the test has completed, is this the normal way to to this ?


reading values from config files in NUnit tests

  

One of my NUnit tests has to read in some values from config files.  In my main application this process works perfectly well, however when I run the unit test, the code that reads in the values from the config files doesnt read anything in.  Ive tried putting app.config in my unit test project (I even tried web.config) but nothing seems to work.  Are there any special steps involved when reading from config files in an nunit test ?


NUnit and config files

  

Ive created an NUnit test project in my solution and have added 3 tests.  They all fail with the same error


Systems.Code.Test.TransactionTest.CreateDataContext_ConnectionString_ReturnsDataContextObject:
SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.
  ----> System.NullReferenceException : Object reference not set to an instance of an object.

Systems.Code.Test.TransactionTest.CreateDataContext_ConnectionString_ReturnsDataContextObject:

SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.

  ----> System.NullReferenceException : Object reference not set to an instance of an object.


heres the test method


[Test]
        public void CreateDataContext_ConnectionString_ReturnsDataCon

Toolbox: Static Analysis Database Tools, Managing Remote Computers, And More

  

If you want to apply static analysis to your databases, connect to remote computers, find out more about the Entity Framework, or just check into some cool podcasts for your daily commute, then you'll want to read more about these latest tools and resources.

Scott Mitchell

MSDN Magazine July 2009


Toolbox: Static Analysis Tools For .NET, Matt Berseth's Blog

  

This month we take a look at FxCop and other tools that enforce your design rules, along with jQuery.

Scott Mitchell

MSDN Magazine December 2008


Basic Instincts: Static Event Binding Using WithEvents

  

This month's Basic Instincts column builds upon my last three columns in which I introduced and explained the fundamental concepts and syntax associated with delegates and events. Last month I showed you how to design and write a simple class that defines and raises events.

Ted Pattison

MSDN Magazine March 2003


ReadOnly DateTime attribute stores correct date but only retrieves DateTime.MinValue on Delete

  

Hey everyone,

I have a dynamic data site that stores Event data using LINQ-to-SQL. When someone requests an event, it is first stored as a PendingEvent (which is a child of Event) with a column/attribute called receivedAt, which is [ReadOnly(true)] and which is assigned in InsertEvent as shown.

        partial void InsertEvent(Event instance)
        {
            instance.requestedAt = DateTime.Now;

            SendEmail(instance);

            instance.AddEventToCalendar();

            this.ExecuteDynamicInsert(instance);
        }


This works fine. The event displays with the correct receivedAt date, and it's correct in my database. It shows up just fine on my Display, Edit, and List pages. However, if I try to delete, the receivedAt in the instance (retrieved with my debugger) in my delete function is 01/01/0001 12:00am, also known as DateTime.MinValue. My other dates appear correct.

If I remove "ReadOnly(true)" from the received at, everything works fine. Why won't "ReadOnly" allow me to have a time?
Thanks in advance,

Andrew

Addendum:

I forgot to mention why I care. I can't submit the instance to be deleted because DateTime.MinValue is outside SQL's available datetime, so I get a SQL error. The delete also takes place in a custom dele

NUnit debugging no longer working

  

Hi,

I moved from VS2008 running on XP 32 bit to VS2010 running on Win7 64 bit and just noticed that I can't debug in NUnit like I used to.

On my old system, I just went to Debug|Attach to Process, chose NUnit.exe, and ran my tests from the NUnit GUI. VS2008 would stop at the breakpoints just as normal.

Now when I try this using NUnit 2.5.5.10112 on the new configuraiton it just skips over my breakpoints. Any help would be great.

Thanks,

John


chnage data of input type with readonly attribute

  


Hi 
I have webform where i have different input type as text controls with a readonly attribute. I have option to edit the data so through javascript i remove the readonly attribute through javascript, here's the code 
function EditBillAddress()
        {
          

Changing a textbox's readonly property right before update on a gridview

  

I have a gridview with a date field. I don't want the user to be able to type in their own date and mess up the format so I made the property readonly. That date is then set by a point and click interface. This is all working fine but when the user clicks update this field doesn't update because it's readonly. If i turn readonly off it works so is there a way to turn off the readonly property right before submit?


public object on asp,net page

  

in asp.net can i make public objects on my page, for example

public Customer cust1 = new customer();

and use this object on my entire code???


what are the drawbacks of creating public objects??

a single object will be created for all users??? or each user will have a different object????


is there any impact of using static methods in Business Access layer in 3 tier applciation

  

is there any impact of using static methods in Business Access layer in 3 tier applciation,


Please suggest me what are the best practices and standards


Static property. how does this work?

  
I want to understand how this works? public class UtilityDate {         public UtilityDate ()         {         }           public static UtilityDate Instance         {             get             {                 return new UtilityDateFacade();             }         } public DateTime GetDate(long userId) { //SomeImplementation //which gets datetime from database }  }     What heppens when i say   UtilityDate     .Instance.GetDate(1); Thanks 
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend