Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
public sealed class AllExceptionHandler : IHttpModule
    {

        void IHttpModule.Init(HttpApplication context)
        {
            context.Error += new EventHandler(UncaughtException);
        }

        void IHttpModule.Dispose()
        {

        }

        private void UncaughtException(object sender, EventArgs e)
        {
            log.Error("Test Message");  
        }
    }



I Wrote :

C#
[TestMethod, CategorizeByConvention]
        public void WhenValidParameter_ShouldSetHandleUnCaughtException()
        {
            //Arrange
            var target = new AllExceptionHandler() as IHttpModule;
            var context = new Mock<HttpApplication>(MockBehavior.Strict);

            context.Raise(e => e.Error += null, new EventArgs());

            //Assert

        }


I am getting exception :

An exception of type 'System.ArgumentException' occurred in Moq.dll but was not handled in user code

Additional information: Expression is not an event attach or detach, or the event is declared in a class but not marked virtual.
Posted
Updated 23-Sep-14 0:31am
v3
Comments
Sergey Alexandrovich Kryukov 19-Sep-14 15:46pm    
Not clear. First code fragment won't even compile, say, because exceptionMessage is not declared anywhere.
If the second fragment says "I wrote" what is the first one? Exception in what line? How to reproduce it? And so on...
—SA
hemant malpote 22-Sep-14 2:25am    
correction in code :: consider 'exceptionMessage' as "Test Message".
Sergey Alexandrovich Kryukov 22-Sep-14 2:31am    
I don't see your code corrected. Please just do it.
—SA
Bernhard Hiller 22-Sep-14 3:18am    
Try to describe what you want to test - in simple English. Then we can try to help you create a proper test for that purpose.
hemant malpote 23-Sep-14 6:37am    
now i makes it correct, please find it.
thanks in advance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900