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. Design and Architecture
  4. Command pattern implementation for testing

Command pattern implementation for testing

Scheduled Pinned Locked Moved Design and Architecture
csharpasp-netdatabasedesigntesting
6 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.
  • N Offline
    N Offline
    Nathan Gloyn
    wrote on last edited by
    #1

    I'm curently trying to simplify testing in my company by enabling the use of the command pattern. So I need: Command - interfact/abstract class defining public contract for concrete commands ConcreteCommand - and command to use Receiver - class that receives command to execute Invoker - class that invokes the command on the receiver. Ok so this is all standard GOF stuff, where I'm scratching my head is the implementation of the command and receiver classes. We use selenium for testing the web apps UI and will make a call something like: selenium.Click("link") or selenium.GetXPathCount("//div[@id='ctl00_MainContent_pnlWork']/table/tbody/tr") What I want to do is enable a developer to create a command to perform a selenium action such as the code above (ok technically they're 2 different commands since one has a return and one doesn't) but I don't want to have to create a concrete class for each type of selenium action i.e. method but at the same time in my receiver class I don't want to have a huge switch statement that caters for each type of command. I didn't want to pass the receiver to the concrete command object as I have other types of command I need, such as db commands, which need different receivers and where possible would like to use a generic interface for the receivers to enable easy expansion in the future (I already have 3 potential receivers and this may grow). I'm using C# and Asp.Net with the .Net 3.5 framework. Any help appreciated.

    L 1 Reply Last reply
    0
    • N Nathan Gloyn

      I'm curently trying to simplify testing in my company by enabling the use of the command pattern. So I need: Command - interfact/abstract class defining public contract for concrete commands ConcreteCommand - and command to use Receiver - class that receives command to execute Invoker - class that invokes the command on the receiver. Ok so this is all standard GOF stuff, where I'm scratching my head is the implementation of the command and receiver classes. We use selenium for testing the web apps UI and will make a call something like: selenium.Click("link") or selenium.GetXPathCount("//div[@id='ctl00_MainContent_pnlWork']/table/tbody/tr") What I want to do is enable a developer to create a command to perform a selenium action such as the code above (ok technically they're 2 different commands since one has a return and one doesn't) but I don't want to have to create a concrete class for each type of selenium action i.e. method but at the same time in my receiver class I don't want to have a huge switch statement that caters for each type of command. I didn't want to pass the receiver to the concrete command object as I have other types of command I need, such as db commands, which need different receivers and where possible would like to use a generic interface for the receivers to enable easy expansion in the future (I already have 3 potential receivers and this may grow). I'm using C# and Asp.Net with the .Net 3.5 framework. Any help appreciated.

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Lowest of the Low wrote:

      Any help appreciated.

      Ok, I suggest you ask at least one question. That way people here might be able to help you. ;)

      led mike

      N 1 Reply Last reply
      0
      • L led mike

        Lowest of the Low wrote:

        Any help appreciated.

        Ok, I suggest you ask at least one question. That way people here might be able to help you. ;)

        led mike

        N Offline
        N Offline
        Nathan Gloyn
        wrote on last edited by
        #3

        Thought I had :confused: To be clear I'm asking the best way to implement the ConcreteCommand & Invoker (which sort of go hand in hand as command passed through needs to be interpreted by the invoker). Once specific example of this is utilising selenium and being able to pass a command to an invoker than will execute that command by calling a method on an instance of the selenium. Hope thats clearer.

        L 1 Reply Last reply
        0
        • N Nathan Gloyn

          Thought I had :confused: To be clear I'm asking the best way to implement the ConcreteCommand & Invoker (which sort of go hand in hand as command passed through needs to be interpreted by the invoker). Once specific example of this is utilising selenium and being able to pass a command to an invoker than will execute that command by calling a method on an instance of the selenium. Hope thats clearer.

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          Lowest of the Low wrote:

          To be clear I'm asking the best way

          My experience in forum discussions on design issues indicates that it's normally not possible to gain sufficient understanding of the problem domain (due to the limits of text messaging conversations) to definitively know what the "best" solution is. Most likely what you can get is some ideas. Some may not be based on a correct understanding of your problem domain and therefore won't seem very good to you because you do have a more comprehensive understanding of the problem domain. Ultimately it will be up to you to determine which is the "best" solution.

          Lowest of the Low wrote:

          but I don't want to have to create a concrete class for each type of selenium action i.e. method but at the same time in my receiver class I don't want to have a huge switch statement that caters for each type of command.

          Keep in mind what I said above about not having a clear picture, but that statement seems to say something like, we have options A and B and I don't want to do either. So I guess you are asking if someone knows of a another option. I suppose delegates or since you are in 3.5 maybe Lambda expressions could be leveraged to provide a solution that is neither a class for each selenium action nor conditional statements for each selenium action. I am doubtful that delegates are superior to classes and I have not yet ventured into 3.5 and Lambda. However many people that have seem enamored with it, so you might want to spend some time looking at it.

          led mike

          N 1 Reply Last reply
          0
          • L led mike

            Lowest of the Low wrote:

            To be clear I'm asking the best way

            My experience in forum discussions on design issues indicates that it's normally not possible to gain sufficient understanding of the problem domain (due to the limits of text messaging conversations) to definitively know what the "best" solution is. Most likely what you can get is some ideas. Some may not be based on a correct understanding of your problem domain and therefore won't seem very good to you because you do have a more comprehensive understanding of the problem domain. Ultimately it will be up to you to determine which is the "best" solution.

            Lowest of the Low wrote:

            but I don't want to have to create a concrete class for each type of selenium action i.e. method but at the same time in my receiver class I don't want to have a huge switch statement that caters for each type of command.

            Keep in mind what I said above about not having a clear picture, but that statement seems to say something like, we have options A and B and I don't want to do either. So I guess you are asking if someone knows of a another option. I suppose delegates or since you are in 3.5 maybe Lambda expressions could be leveraged to provide a solution that is neither a class for each selenium action nor conditional statements for each selenium action. I am doubtful that delegates are superior to classes and I have not yet ventured into 3.5 and Lambda. However many people that have seem enamored with it, so you might want to spend some time looking at it.

            led mike

            N Offline
            N Offline
            Nathan Gloyn
            wrote on last edited by
            #5

            Thanks for the feedback. I think I'll post in the C# forum about Linq and see if anybody can offer some advice there.

            L 1 Reply Last reply
            0
            • N Nathan Gloyn

              Thanks for the feedback. I think I'll post in the C# forum about Linq and see if anybody can offer some advice there.

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #6

              Lowest of the Low wrote:

              I think I'll post in the C# forum about Linq

              Dude, there's a LINQ and .NET 3.5 forum


              Last modified: after originally posted -- hahaha Link! That was a good one!

              led mike

              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