Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MOQ unit test

MOQ unit test

Scheduled Pinned Locked Moved C#
questiontestingtutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    michaelgr1
    wrote on last edited by
    #1

    Hello, I am writing unit test to a method named methodName for example. The tested class extends another base class. The tested method uses a method that is implemented in the base class, But i want to use Mock in order to Mock this method. How can i do it?

    L 1 Reply Last reply
    0
    • M michaelgr1

      Hello, I am writing unit test to a method named methodName for example. The tested class extends another base class. The tested method uses a method that is implemented in the base class, But i want to use Mock in order to Mock this method. How can i do it?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Something like this;

      class MyBaseClass
      {
          public virtual string methodName()
          {
              return "This is base calling";
          }
      }
      class MyTestedClass: MyBaseClass
      {
          public override string methodName()
          {
              return "This is the testing value calling";
          }
      
      }
      class MyTestedClassMock: MyBaseClass
      {
          public override string methodName()
          {
              return "Whaahaha, I'm not the real one, just a mock-stand in.";
          }
      }
      

      //..in the test-bit
      MyBaseClass someObject = new MyTestedClassMock();
      // or new MyTestedClass();
      MessageBox.Show(someObject.methodName());

      Bastard Programmer from Hell :suss:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups