Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

Take a look at how unit testing is done, it gives you a framework to do just that. When you create a new measure, there's automatically a folder 'tests' created with it.

Basically, you can translate the following ruby code to c#.

If your measure.rb starts with :

 class NameOfMyMeasureClass< OpenStudio::Ruleset::ModelUserScript

Then here's basically how you would run a measure on a model:

# create an instance of the measure
measure = NameOfMyMeasureClass.new

# create an instance of a runner
runner = OpenStudio::Ruleset::OSRunner.new

# get arguments
arguments = measure.arguments(model)
argument_map = OpenStudio::Ruleset.convertOSArgumentVectorToMap(arguments)

# create hash of argument values.
# If the argument has a default that you want to use, you don't need it in the hash
args_hash = {}
args_hash["space_name"] = "New Space"
# using defaults values from measure.rb for other arguments

# populate argument with specified hash value if specified
arguments.each do |arg|
  temp_arg_var = arg.clone
  if args_hash.keys.include?(arg.name)
    assert(temp_arg_var.setValue(args_hash[arg.name]))
  end
  argument_map[arg.name] = temp_arg_var
end

# run the measure (supposes you already have your current model in the variable `model`)
measure.run(model, runner, argument_map)
result = runner.result

# show the output
show_output(result)

# assert that it ran correctly
assert_equal("Success", result.value.valueName)