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

  • Home
  • SEARCH
  • 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 217103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:37:34+00:00 2026-05-11T18:37:34+00:00

I have been writing unit tests using NUnit and Moq with my Silverlight code

  • 0

I have been writing unit tests using NUnit and Moq with my Silverlight code for some time now. One problem I keep running into has to do with DependencyObjects.

If anything is derived from DependencyObject, then I can’t instantiate it in my test. For instance, MouseEventArgs derives from DependencyObject. If I have code that takes these args, I can’t create the args for several reasons… one of them being that it is a DependencyObject.

As far as I understand, the base constructor of DependencyObject is trying to work with some statics that don’t exist unless the entire Silverlight system is up and running. Any construction of a class that derives from DependencyObject throws an exception. Bummer.

I do not use the Silverlight Unit Test Framework, because it really isn’t unit testing and requires a UI. I run need real, headless unit tests.

Anyways, The best I have come up with is to wrap these objects and give them interfaces like ITimelineMarker and I give them extension methods to do it: timelineMarker.ToInterface(). This works well, and I can mock them out… but I was wondering:

Has anyone come up with a better way to deal with DepencencyObjects in Silverlight Unit Tests?

  • 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-05-11T18:37:34+00:00Added an answer on May 11, 2026 at 6:37 pm

    Why do you have application logic tied directly to SilverLight events and objects? The caveats of trying to test an application’s logic through it’s UI are well known anti-patterns and have given way to patterns that solve this problem in a more effective manner.

    Your UI really should only be concerned with UI events and pass any processing to another layer, the only thing then left to test in your UI would be graphical responses (such as when you click a button does a panel slide in from the side), and the only good way to test interactions like that is to actually do the clicking.

    Perhaps a more appropriate answer to your question would be that you need to refactor your code to use a patter such as MVC, MVP, or MVVM so that you can test your application logic independently of your UI layer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 117k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The release notes for v1.5 answer this question. It explains… May 11, 2026 at 10:49 pm
  • Editorial Team
    Editorial Team added an answer You could just reset your session table. This would logout… May 11, 2026 at 10:49 pm
  • Editorial Team
    Editorial Team added an answer There are three ways to do it. 1) Return a… May 11, 2026 at 10:49 pm

Related Questions

I want to be better at using NUnit for testing the applications I write,
Our development databases (Oracle 9i) use a remote database link to a remote shared
G'day, I am working with a group of offshore developers who have been using
I have some basic classes with cloning methods: public class SimpleClass { public int

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.