473,779 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3566
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
7047
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
2527
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 http://www.dofactory.com/Patterns/PatternAbstract.aspx). Could anybody try to explain me in his own words how this pattern work and what the purpose is? thanks in advance
14
2757
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
3088
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 c# application, with the events coming up and being caught (The idea is to use this to Set a ManualResetEvent which will alow the rest of the processign to happen). However, when I put an event after the call to start the async process off,
3
2039
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, but this does not seem to be possible, because I get the compiler error: The event 'SelectionChanged' can only appear on the left hand side of += or -=.
13
3519
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 following issues still exist. The article shows how to find methods on a receiver that match the pattern OnXXXX given the sender. It loops through the sender events and tries to get methods from the receiver that match the pattern. For each one...
72
5280
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: http://geosoft.no/development/unittesting.html Thanks.
3
5669
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 (VB.NET preferred)? thanks herbert
0
1429
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 server side asynchronous web service. So, we can only implement asynchronous webmethod with BeginXXX/EndXXX pattern, right? The only server side asynchronous web method post is http://msdn2.microsoft.com/en-us/library/aa480516.aspx. I don't...
0
9633
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10137
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9928
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.