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 1115083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:06:15+00:00 2026-05-17T03:06:15+00:00

I have a Silverlight testing project using the Silverlight Unit Test Framework . I

  • 0

I have a Silverlight testing project using the Silverlight Unit Test Framework.

I want to test a method in my view model which takes FileInfo objects. This seems to work fine when I test it manually through the UI.

Now I want a unit test just for the AddDocument method. I don’t want to test actually clicking the button or simulate clicking a button – I just want to test that the AddDocument method.

Here’s the code behind from the view. The mySessionViewModel object is in the DataContext. The method I want to test is mySessionViewModel.AddDocument();

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    OpenFileDialog openFileDialog1 = new OpenFileDialog();

    openFileDialog1.Filter = 
        "Text Files (.txt)|*.txt|All Files (*.*)|*.*";
    openFileDialog1.FilterIndex = 1;

    openFileDialog1.Multiselect = true;

    bool? userClickedOK = openFileDialog1.ShowDialog();

    if (userClickedOK == true)
    {
        IList<FileInfo> files = new List<FileInfo>();
        foreach (FileInfo file in openFileDialog1.Files)
        {
            mySessionViewModel.AddDocument(file);
        }
    } 
}

I put some test files in a subdirectory of the web project and tried this, but it throws a SecurityException consistent with Silverlight’s security model:

SessionView sessionViewModel = new SessionViewModel();

DirectoryInfo di = new DirectoryInfo("testFiles");
var files = di.EnumerateFiles();
foreach (var file in files)
{
    sessionViewModel.AddDocument(file);
}

// assert some stuff
  • 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-17T03:06:16+00:00Added an answer on May 17, 2026 at 3:06 am

    The main problem here is you want to Unit Test a method that takes a FileInfo as a parameter. However there is no automated way to create an instance of FileInfo.

    Hence to unit test this method you should consider changing the type of the parameter. Its quite likely that the internals of this method only access a handful of the properties and methods on the FileInfo. Hence create an interface that represents those members and change the method to use the interface rather than the FileInfo directly.

    Now you can create a wrapper class for FileInfo that implements the interface and you can also create another class for use in unit testing that implements the same interface but gets its content elsewhere.

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

Sidebar

Related Questions

I am using the Silverlight Unit Testing Framework to test some View Manager classes.
I am running unit testing in silverlight. I have the test data and I
I have a Silverlight project calling a WCF service. The service method GetData has
I am using Silverlight 3.0 Unit Testing, version Silverlight Toolkit November 2009. Apart from
[unit testing newbie] [c#] Consider the following scenario: I'm using Silverlight and calling a
I want to use dynamic mocks when testing a Silverlight application. I have tried
I use the Silverlight Unit Testing Framework and it works pretty well. However every
I have a silverlight mvvm with ria project. I have a UI in which
I have a Silverlight project that uses MVVM with Prism. I followed http://www.telerik.com/help/silverlight/patterns-and-practices-eventtocommand-prism.html I
I have a Silverlight ModelViewViewModel project that I would like to expose a property

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.