Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7779643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:41:29+00:00 2026-06-01T18:41:29+00:00

I’m receiving event notifications from web services that trigger event handlers with data regarding

  • 0

I’m receiving event notifications from web services that trigger event handlers with data regarding what triggered the event. I’m trying to test that once an event handler is called that a, b and c are all called with the proper values. This isn’t possible without relying on the web service

My solution is to create converters that convert the EventArgs that are returned to my via the services library (Exchange Web Services) to something my dumb objects can understand without relying on third part services. My issue is that the EventArgs class given to my by the EWS library has an internal constructor so there’s no easy way to generate an instance of it with random property values without much work with reflection.

For example, I have a simply interface:

public interface IConverter<TFrom, TTo>
{
    TTo Convert(TFrom from);
}

and a simple implementation:

public class NotificationEventArgsConverter : IConverter<NotificationEventArgs, NewNotification>
{
    public NewNotification Convert(NotificationEventArgs from)
    {
        return new NewNotification
                   {
                       ItemIds = from.Events.Cast<ItemEvent>().Select(x => x.ItemId.ToString())
                   };
    }
}

Question is how can I generate an instance of NotificationEventArgs with random values. Is there a library for this that I missed in my searches?

The entire goal of this is to emulate if I receive an instance of NotificationEventArgs with the following values then NewNotification should resemble x.

Edit

In the meantime I will simply use typeof(T).GetConstructor().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:41:30+00:00Added an answer on June 1, 2026 at 6:41 pm

    You might want to take a look at AutoFixture:

    AutoFixture makes it easier for developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case.

    After doing some decompilation of Microsoft.Exchange.WebServices and playing bit with reflection, you can do it for example like this:

    var fixture = new Fixture();
    
    // retrieve internal FolderEvent(EventType, DateTime) ctor
    // using FolderEvent class as NotificationEvent is abstract
    var notificationEventCtor = typeof(FolderEvent).GetConstructor(
        BindingFlags.NonPublic | BindingFlags.Instance,
        null,
        new Type[] { typeof(EventType), typeof(DateTime) },
        null
    );
    
    // generate 10 random events with some help of LINQ and AutoFixture
    var trashData = Enumerable
        .Range(1, 10)
        .Select(i => new object[]
            {
                fixture.CreateAnonymous<EventType>(),
                fixture.CreateAnonymous<DateTime>() 
            })
        .Select(p => notificationEventCtor.Invoke(p))
        .Cast<NotificationEvent>()
        .ToList();
    

    Code above will generate 10 FolderEvents in a list, ready to pass to NotificationEventArgs constructor (which is internal again, so same code applies):

    var notificationEventArgsCtor = typeof(NotificationEventArgs).GetConstructor(
        BindingFlags.NonPublic | BindingFlags.Instance,
        null,
        new Type[] 
        { 
            typeof(StreamingSubscription),
            typeof(IEnumerable<NotificationEvent>) 
        },
        null
    );
    
    var instance = notificationEventArgsCtor
        .Invoke(new object[] { null, trashData });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.