473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

NUnit testing of eventlog entry?

Hi

I am trying to engineer a way of testing that my logging framework is
capable of writing to my eventlog. I want to include this test in my already
existing NUnit tests - but I'm a little low on ideas as how to assert that I
actually did write to the eventlog successfully.

Naturally I want this assertion without having to open my eventlog and
visually verify the writing.

Any ideas???

Thanks!
Nov 16 '05 #1
3 3185
Ole,
Naturally I want this assertion without having to open my eventlog and
visually verify the writing. Have you considered using a snippet of C# code (within the unit test itself)
to "open" the eventlog & "read" the entries to see if the entry you expect
was written?

You can use the EventLog.Entries property to "read" the entries from an
EventLog...

http://msdn.microsoft.com/library/de...triesTopic.asp

Alternatively you might be able to use the EventWritten event to see if an
entry was written during the test...

If possible I would attempt to use a private test Event Log above so as to
have total control on outside programs interferring with the test...

Hope this helps
Jay
"Ole Hanson" <no@spam.com> wrote in message
news:uv**************@tk2msftngp13.phx.gbl... Hi

I am trying to engineer a way of testing that my logging framework is
capable of writing to my eventlog. I want to include this test in my
already existing NUnit tests - but I'm a little low on ideas as how to
assert that I actually did write to the eventlog successfully.

Naturally I want this assertion without having to open my eventlog and
visually verify the writing.

Any ideas???

Thanks!

Nov 16 '05 #2
nUnit rides along with exceptions from the .NET framework and you may be
able to assert your test on an event log exception. A handled exception by
your code would by default cause nUnit to fail an assertion test unless you
override it with an ExpectedException parameter in your test method.

You could also use a conditional assertion in nUnit to check the return
value of the write method in your logging classes, that way you could at
least evaluate against a succesful write. NUnit also recognizes unhandled
exceptions as an indicator that the code has failed in some way. As such, it
reports unhandled exceptions as failures of any test itself - you could
likely assume that any other result permutation is a success without having
to actually open the event log

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Ole Hanson" <no@spam.com> wrote in message
news:uv**************@tk2msftngp13.phx.gbl...
Hi

I am trying to engineer a way of testing that my logging framework is
capable of writing to my eventlog. I want to include this test in my already existing NUnit tests - but I'm a little low on ideas as how to assert that I actually did write to the eventlog successfully.

Naturally I want this assertion without having to open my eventlog and
visually verify the writing.

Any ideas???

Thanks!

Nov 16 '05 #3
Great stuff!

Just what I needed.
Thanks

/Ole
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl...
Ole,
Naturally I want this assertion without having to open my eventlog and
visually verify the writing.

Have you considered using a snippet of C# code (within the unit test
itself) to "open" the eventlog & "read" the entries to see if the entry
you expect was written?

You can use the EventLog.Entries property to "read" the entries from an
EventLog...

http://msdn.microsoft.com/library/de...triesTopic.asp

Alternatively you might be able to use the EventWritten event to see if an
entry was written during the test...

If possible I would attempt to use a private test Event Log above so as to
have total control on outside programs interferring with the test...

Hope this helps
Jay
"Ole Hanson" <no@spam.com> wrote in message
news:uv**************@tk2msftngp13.phx.gbl...
Hi

I am trying to engineer a way of testing that my logging framework is
capable of writing to my eventlog. I want to include this test in my
already existing NUnit tests - but I'm a little low on ideas as how to
assert that I actually did write to the eventlog successfully.

Naturally I want this assertion without having to open my eventlog and
visually verify the writing.

Any ideas???

Thanks!


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: zorro | last post by:
I need to read the entire eventlog and parse it. The application uses vb.net and the EventLog object. The problem i'm having is that it can take less then a second up to 15 seconds to read all...
0
by: sangui | last post by:
..Net provide the class to read eventlog (EventLog class) but I try to read the window eventlog per file. without using EventLog Class. is it possible to read the log per file? public...
5
by: zorro | last post by:
I need to read the entire eventlog and parse it. The application uses vb.net and the EventLog object. The problem i'm having is that it can take less then a second up to 15 seconds to read all...
12
by: zorro | last post by:
I need to read the entire eventlog and parse it. The application uses vb.net and the EventLog object. The problem i'm having is that it can take less then a second up to 15 seconds to read all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.