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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:28:26+00:00 2026-06-01T21:28:26+00:00

I’m looking for the best way to verify that a given method (the unit)

  • 0

I’m looking for the best way to verify that a given method (the unit) is executing the correct logic.

In this case, I have a method similar to:

public void GoToMyPage()
{
    DispatcherHelper.BeginInvoke(() =>
    {
        navigationService.Navigate("mypage.xaml", "id", id);
    });
}

The navigationService is a injected mocked version of a interface, INavigationService. Now, I want to verify in my unit tests, that Navigate(...) is called with the correct parameters.

However, on Windows Phone IL emitting is not supported to a degree, where a mocking framework can create a dynamic proxy, and analyze the call. Therefor I need to analyze this manually.

A simple solution would be to save the values called in the Navigate(...) method in public properties, and check them in the unit tests. However, this is rather tiresome having to do for all different kinds of mocks and methods.

So my question is, is there a smarter way to create analyze calls using C# features (such as delegates), without using a reflection based proxy, and without having to saving the debug info manually?

  • 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-01T21:28:27+00:00Added an answer on June 1, 2026 at 9:28 pm

    My approach would be to manually create a testable implementation of the INavigationService that catches the calls and parameters and allows you to verify them later.

    public class TestableNavigationService : INavigationService
    {
        Dictionary<string, Parameters> Calls = new Dictionary<string, Parameters>();
    
        public void Navigate(string page, string parameterName, string parameterValue)
        {
            Calls.Add("Navigate" new Parameters()); // Parameters will need to catch the parameters that were passed to this method some how
        }
    
        public void Verify(string methodName, Parameters methodParameters)
        {
            ASsert.IsTrue(Calls.ContainsKey(methodName));
            // TODO: Verify the parameters are called correctly.
        }
    }
    

    this could then be used in your test something like:

    public void Test()
    {
        // Arrange
        TestableNavigationService testableService = new TestableNavigationService ();
        var classUnderTest = new TestClass(testableService );
    
        // Act
        classUnderTest.GoToMyPage();
    
        // Assert
        testableService.Verify("Navigate");
    }
    

    I havent thought about the Parameters that are passed into the method, but I guess this is a good start.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.