473,287 Members | 1,866 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,287 software developers and data experts.

Event Based Async Pattern Unit Testing

Hello,

I am in need of assistance trying to figure out how to 'Unit Test' my Event
Based Async Pattern (http://msdn2.microsoft.com/e7a34yad.aspx) web service
calls. Specifically how to test the event handler.

So as I see it, the auto generated web service proxy will create the custom
event arg class that is passed to the event handler. That is all in good,
the problem is that the custom event arg class is not publicly creatable. So
I can't create a mock object nor can I create an instance of it to populate
myself.

So there is no way that I can without hacking apart the reference.cs file
(which gets re-gened often enough to be a problem) and making the event arg
class publicly creatable.

Can MS provde any ideas on how I could unit test this? I tried creating a
'private accessor' and it gen'd correctly but I can't create an instance of
the accessor without having an instance of the eventarg class.

Thanks for any help in advance.
--
Rich
Feb 8 '06 #1
3 3538
Hi Rich,

Welcome to the MSDN newsgroup.

Regarding on the Unit Test with .NET autogenerated proxy class, based on my
understanding, since the "internal" accessor flag is generated by default,
so currently the simplest means to resolve the problem is customizing the
generate class's source(add a public constructor...). And if you're
worrying about the autogenerated class files are changed frequently, I
think you can consider take advantage of the partial class feature in .NET
2.0, as we can find those generated classes for webservice proxy are all
marked as partial, then we can create a separate source file associated
with that certain class(in your case it's the custom EventArgs class), then
we can add a public constructor or any other method as we like there...)
and this separate source file will not be changed if we updated webservice
proxy. This can work as long as the webservice's name doesn't change :)

In addition, in .net ,we can also use .NET reflection to create class
instance, so I think this is also one possible approach for creating
non-public classes' instances.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Feb 9 '06 #2
Steven,

Once again, you have managed to point out a solution that I had not
considered. I had not found a good use for Partial classes yet other than
what the IDE does for me automatically.

Your solution of creating a partial class worked like a charm. I was able
to create a partial class and then pass it to my event handler unit test. I
even updated the web ref just to make sure it would continue to work.

As a side note, I had already gone down the road of using reflection to
create the event arg class with sucess, but in the end I found the partial
class implementation easier.
Thanks again!
--
Rich
"Steven Cheng[MSFT]" wrote:
Hi Rich,

Welcome to the MSDN newsgroup.

Regarding on the Unit Test with .NET autogenerated proxy class, based on my
understanding, since the "internal" accessor flag is generated by default,
so currently the simplest means to resolve the problem is customizing the
generate class's source(add a public constructor...). And if you're
worrying about the autogenerated class files are changed frequently, I
think you can consider take advantage of the partial class feature in .NET
2.0, as we can find those generated classes for webservice proxy are all
marked as partial, then we can create a separate source file associated
with that certain class(in your case it's the custom EventArgs class), then
we can add a public constructor or any other method as we like there...)
and this separate source file will not be changed if we updated webservice
proxy. This can work as long as the webservice's name doesn't change :)

In addition, in .net ,we can also use .NET reflection to create class
instance, so I think this is also one possible approach for creating
non-public classes' instances.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



Feb 10 '06 #3
Thanks for your followup Rich,

Glad that my suggestion is of assistance. Please feel free to post here
when there is anything we can help.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Feb 13 '06 #4

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

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
4
by: max | last post by:
Hello, I analyze this design pattern for a long time but I do not understand how this pattern work and what the purpose is? (I looked a this site...
14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
6
by: Iain | last post by:
I've got a (VC++ 6.0) com object which does something asynchronously (writes a DVD image, actually). It rasies COM events to indicate progress, including completion. I've got this running in a...
3
by: Stig | last post by:
I have declared an interface containing an event. The class implementing the interface should implement the event by referring to an event on an object owns, instead of implementing the event,...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
3
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I need to build an event-based asynchronous pattern (around a send/receive messaging API). Is there a step-by-step guidance about how to write code for the EBAP ? Does any book cover this theme...
0
by: Morgan Cheng | last post by:
Since ASP.NET 2.0, asynchronous web service client can be implemented with event-based pattern, instead of original BeginXXX/EndXXX pattern. However, I didn't find any material about event-based...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.