locked
Share parameters RRS feed

  • Question

  • On my model class, I have:
    [Action]
    public static void UpdateUser(Profile ProfileToUpdate)
    {
                /**......**/
    }

    [Action]
    public static bool VerifyUser(Profile ProfileToVerify)
    {
             /** ... **/
    }

    On the cord file, I have
    config ProfileParameters : ProfileConfig 
    {
        action static void ProfileAdapter.UpdateUser(Profile ProfileToUpdate)
            where 
            {.
               Combination.In<string>(ProfileToUpdate.FirstName, "a", "A");
               Combination.In<string>(ProfileToUpdate.LastName, "b", "B");
               Combination.In<string>(UserProfileToUpdate.Email, "c", "C");       
               Combination.Pairwise(ProfileToUpdate.FirstName, ProfileToUpdate.LastName, UserProfileToUpdate.Email);
            .};
    }
    
    To verify profile, I need the same parameter ProfileToUpdate to pass to Verify, is there a way to define action Verify on the config with the same parameters as in action UpdateUser? Thanks
    Wednesday, January 27, 2010 11:44 PM

Answers

  • You won't find an example, because it's not the recommended practice. Your special case (same parameter combinations used for more than one action) can be addressed in this way, though. The method would not be declared in Cord or inside a configuration, but elsewhere:

    For example, you could have a method in your model as follows:

    namespace ModelHelpers
    {
      public class ParameterCombinationLibrary
      {
        public static void ProfileParameterCombinations(Profile p)
        {
            Combination.In<string>(p.FirstName, "a", "A");
            Combination.In<string>(p.LastName, "b", "B");
            Combination.In<string>(Userp.Email, "c", "C");       
            Combination.Pairwise(p.FirstName, p.LastName, Userp.Email);        
        }

        //other methods
      }

    }

    And then your config would have

    action static void ProfileAdapter.UpdateUser(Profile ProfileToUpdate)
      where {.
        ModelHelpers.ParameterCombinationLibrary.ProfileParameterCombinations(ProfileToUpdate);
      .};
    action static bool ProfileAdapter.VerifyUser(Profile ProfileToVerify)
      where {.
        ModelHelpers.ParameterCombinationLibrary.ProfileParameterCombinations(ProfileToVerify);
      .};

    Thursday, January 28, 2010 12:37 AM
    Moderator

All replies

  • You could use procedural abstraction for this. Everything between {. and .} is C# code. So if you move all parameter combinations into a method, you can invoke it from the "where" clause for both actions.
    Thursday, January 28, 2010 12:14 AM
    Moderator
  • Could you please eleborate more or give code example? I tried to find the example of writing a method inside a config but couldn't find it anywhere. Thanks.
    Thursday, January 28, 2010 12:23 AM
  • You won't find an example, because it's not the recommended practice. Your special case (same parameter combinations used for more than one action) can be addressed in this way, though. The method would not be declared in Cord or inside a configuration, but elsewhere:

    For example, you could have a method in your model as follows:

    namespace ModelHelpers
    {
      public class ParameterCombinationLibrary
      {
        public static void ProfileParameterCombinations(Profile p)
        {
            Combination.In<string>(p.FirstName, "a", "A");
            Combination.In<string>(p.LastName, "b", "B");
            Combination.In<string>(Userp.Email, "c", "C");       
            Combination.Pairwise(p.FirstName, p.LastName, Userp.Email);        
        }

        //other methods
      }

    }

    And then your config would have

    action static void ProfileAdapter.UpdateUser(Profile ProfileToUpdate)
      where {.
        ModelHelpers.ParameterCombinationLibrary.ProfileParameterCombinations(ProfileToUpdate);
      .};
    action static bool ProfileAdapter.VerifyUser(Profile ProfileToVerify)
      where {.
        ModelHelpers.ParameterCombinationLibrary.ProfileParameterCombinations(ProfileToVerify);
      .};

    Thursday, January 28, 2010 12:37 AM
    Moderator
  • Hi Nico,

    I have a similar issue but not sure how to handle it right. I place my config cord for your reference. For example, when Subscribe is given "test.*.>" how can I pass the same value to Unsubscribe. Please note that I cannot use the let statement because my scenario involves "+" and I do not want to use the same value for repetition. In the past, I parametrized my machine but then because of "+", it used the same parameter values. So, I did not follow-up on using the let nor the parametrized machines.

    I have other scenarios where there are relations between parameter values among actions. For example, if Subscribe is given "test.*" how can I pass "test.xy" for the Publish action because test.xy matches test.* 

    I am not sure how to handle parameter combinations involving multiple actions. Please point me to some examples, if possible.

    // Test Scenario: Subscribe and UnSubscribe methods with one connection instance
    
    config SubUnsubCfg : Main
    {
      action void SoftwareBusAdapterImpl.Subscribe(string subject, bool result) 
            where subject in {"gmsec.abc.uvw", "test.*.>"};
    
      action void SoftwareBusAdapterImpl.SubscribeCallback(string subject, int callbackId, bool result) 
            where subject in {"gmsec.abc.uvw", "test.*.>"},
                  callbackId in {1, 2},
                  {. Combination.Strategy(Microsoft.Modeling.CombinationStrategy.Coverage); .};
    
      action void SoftwareBusAdapterImpl.UnSubscribe(string subject, bool result)
           where subject in {"gmsec.abc.uvw", "test.*.>"};
    
      action void SoftwareBusAdapterImpl.UnSubscribeCallback(string subject, int callbackId, bool result) 
            where subject in {"gmsec.abc.uvw", "test.*.>"},
                  callbackId in {1, 2},
                  {. Combination.Strategy(Microsoft.Modeling.CombinationStrategy.Coverage); .};
    }
    
    machine SubUnSubModelProgram() : Main where ForExploration = false
    {
        construct model program from SubUnsubCfg where scope = "SoftwareBus_TestProject.Connection"
    }
    
    
    machine SubUnsubScenario() : Main where ForExploration = true
    {
        let SoftwareBusAdapterImpl conn in
    
        new conn.SoftwareBusAdapterImpl;
        conn.Create;
        (
            conn.Connect;
            (conn.SubscribeCallback+ ||| conn.Subscribe+ ||| conn.UnSubscribeCallback+ ||| conn.UnSubscribe+);
            conn.Disconnect;
        )+;
        conn.Destroy
    }
    
    machine SubUnsubProgram() : Main where ForExploration = true
    {
       construct accepting paths for
    
       (SubUnsubScenario;exit) || SubUnSubModelProgram
    }
    
    machine SubUnsubTestSuite() : Main where TestEnabled = true
    {
        construct test cases where strategy = "shorttests" for SubUnsubProgram
    }

    Sunday, October 28, 2012 2:31 AM
  • I found one solution. I handled parameter relationships among actions inside the model. It appears not possible or too difficult to handle on the cord level.
    Sunday, November 4, 2012 3:35 PM