Is there a way to pass an array of parameters instead of passing each parameter individually?
For example I have the following scenarios:
When i login to a site
then <firstname>, <lastname>, <middleName>, <Desingation>, <Street>, <Apartmentno> are valid
The list can go on above. Instead can I pass all the above variables in an array?
You can pass a comma separated string and then transform it into a list:
When i login to a site
then 'Joe,Bloggs,Peter,Mr,Some street,15' are valid
[Then("'(.*)' are valid")]
public void ValuesAreValid(List<String> values)
{
}
[StepArgumentTransformation]
public List<String> TransformToListOfString(string commaSeparatedList)
{
return commaSeparatedList.Split(",").ToList();
}
if you want the values to come from examples then you could do this instead:
When I login to a site
then '<values>' are valid
Examples
| values |
| Joe,Bloggs,Peter,Mr,Some street,15|
| Joe,Bloggs,Peter,Mr,Some street,16,SomethingElse,Blah|
If you want to use a table then you could do this instead:
When I login to a site
then the following values are valid
| FirstName | LastName | MiddleName | Greeting| Etc | Etc |
| Joe | Bloggs | Peter | Mr | you get| The Idea|
(you could omit the headers if you want and just use the row values I think)
you can also use examples with this:
When I login to a site
then the following values are valid
| FirstName | LastName | MiddleName | Greeting | Etc | Etc |
| <name> | <lastName>| <middleName>| <greeting>| <etc> | <etc> |
This might be of help:
https://github.com/techtalk/SpecFlow/wiki/Step-Argument-Conversions
Add the following code snippet to your Common Step Definition File:
[StepArgumentTransformation]
public string[] TransformToArrayOfStrings(string commaSeparatedStepArgumentValues)
{
string sourceString = commaSeparatedStepArgumentValues;
string[] stringSeparators = new string[] { "," };
return sourceString.Split(stringSeparators, StringSplitOptions.None);
}
SpecFlow will then automatically convert all comma-separated values in the SpecFlow Steps data table into an array of strings.
Then in your individual step binding function, change the type of the input parameter as string[] as in snippet below:
[Then(#"the expected value is '(.*)'")]
public void ThenTheExpectedValueIs(string[] p0)
{
//ScenarioContext.Current.Pending();
Assert.AreEqual(25, Convert.ToInt32(p0[0]));
Assert.AreEqual(36, Convert.ToInt32(p0[1]));
Assert.AreEqual(79, Convert.ToInt32(p0[2]));
}
Then, based on your expected value for a test step, you may want to apply the appropriate type conversion.
Just transfer the data as a string Example:
Then LEDS 0, 1, 7 are on
[Then(#"LEDS (.*) are on(.*)]
public void ThenLEDAreOn(string p0)
{
int count = p0.Split(',').Length - 1;
string[] Leds_on = p0.Split(',');
foreach (string s in LEDs_on)
{
int.TryParse(s, out LEDS[index]);
index++;
}
}
Then you have your values as integers in an array
Related
I have an Object Array scheduleTable__c, with the below fields:
Product | Description | Jan | Feb | Mar | ...
right now, it will create one record and filling all the fields accordingly. I would like to change this by creating one record for each month inside the Array. I guess the right way to do so is to create another array by iterating over the current array and insert that value.
Replace my function
#AuraEnabled
public static List<scheduleTable__c> createPSs(List<scheduleTable__c> psList){
insert psList;
return psList;
}
by that
#AuraEnabled
public static List<scheduleTable__c> createPSs(List<scheduleTable__c> psList){
String [] arraySC = new List<String>();
for(Integer i = 2; i < psList.size(); i++){
arraySC.push(psList[0]);
arraySC.push(psList[1]);
arraySC.push(psList[i]);
}
insert arraySC;
return arraySC;
}
It doesn't seems to like the fact that it is an array of an object and I am creating a String Array...
I then replaced the array with this but still not able to make it work...
List<scheduleTable__c> arraySC = new List<scheduleTable__c>();
any help will be appreciated.
A simple select of this form:
$select = $this->select();
return $rowset = $this->fetchAll($select);
Now, There is an inherit column in the array, so the table is of the form:
id | role | inherits |
1 | admin | 2 |
2 | player | 3 |
And When displayed I would like the inherirs column to show the Role it actually inherits from instead of the id.
The array returned by Zend_Db_Table_Abstract is extremely convoluted, so I can't just say:
$array[0][inherits]
First of all $this->fetchAll will not return array it is going to return Zend_Db_Table_Rowset_Abstract object. You can learn more about it here in Zend_Db_Table_Rowset Zend Docs.
You can get data from it as an object
// use Zend_Db_Table_Row_Abstract object
$array[0]->inherits
Or if you want to get an array you can do this:
// get rowset and convert it to array
$rowset = $this->fetchAll($select);
$data = ($rowset) ? $rowset->toArray() : array();
Better solution would be to write a left join on the same table and get the role in the dataset without any PHP code.
$sql = $this->getAdapter()->select()
->from(array('r1' => 'your_roles_table'), '*')
->joinLeft(array('r2' => 'your_roles_table'), 'r2.id = r1.inherits', array(
'inherits_role' => 'r2.role',
));
$data = $this->getAdapter()->fetchAll($sql);
var_dump($data);
This seems like a simple task, but somewhere in searching the docs- I've missed the connection.
I have a menu stored in GAE and can return the results of a query:
public String[] getMeals() throws NotLoggedInException {
checkLoggedIn();
PersistenceManager pm = getPersistenceManager();
List<String> meals = new ArrayList<String>();
try {
Query q = pm.newQuery(Meal.class, "user == u");
q.declareParameters("com.google.appengine.api.users.User u");
q.setOrdering("createDate");
List<Meal> myMeals = (List<Meal>) q.execute(getUser());
for (Meal myMeal : myMeals) {
meals.add(myMeal.getMealID());
}
} finally {
pm.close();
}
return (String[]) meals.toArray(new String[0]);
}
With those results, I'd like to bind it to a FlexTable. Using the stockwatcher sample, I've managed to get my ID bound to the FlexTable, but am missing the concept of how I tie the other fields in my result set to it. (The fields I have in the GAE are mealID, mealType and mealDate)
From above, we can see that I'm tossing mealID into a List.
I also know that my other fields must exist in the query because I haven't done anything to filter them. As a matter of fact, if I change my code to:
meals.Add(myMeal.getMealID(), myMeal.getMealType(), myMeal.getMealDate());
it returns all the data, but the flex table treats each item as a new row instead of the three fields on one row.
So my question is: how should I be capturing my records and sending them to my FlexTable so that I can bind the FlexTable to the resultset?
For reference, client side code:
private void loadMeals() {
// load meals from server service MealService
mealService.getMeals(new AsyncCallback<String[]>() {
public void onFailure(Throwable error) {
handleError(error);
}
public void onSuccess(String[] meals) {
displayMeals(meals);
}
});
}
private void displayMeals(String[] meals) {
for (String meal : meals) {
displayMenu(meal, meal, meal);
}
}
The flextable gets populated like this:
mealID | mealType | mealDate
1 | 1 | 1
2 | 2 | 2
3 | 3 | 3
I want it to populate like this:
mealID | mealType | mealDate
1 | Breakfast | 12/22/2012
2 | Lunch | 12/22/2012
3 | Snack | 12/23/2012
Thanks in advance for your input!
This question is a duplicate of Problems passing class objects through GWT RPC
Following the details in that link, and little hired help from oDesk got me going.
Main oversight was needing the entrypoint class in {appname}.gwt.xml and placing the model classes in shared packages.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to query flags stored as enum in NHibernate
I have three tables - Recipient, Message, MessageType
MessageType looks like this:
| ID | Description |
|====|==============|
| 1 | JobAlert |
| 2 | Newsletter |
| 3 | SpecialOffer |
| 4 | Survey |
Recipient contains an integer column which is used as a bitfield; recipients can choose what types of message they want to receive; If a recipient wants to receive newsletters and special offers, we'll set their bitfield to (2 ^ 2) | (2 ^ 3)
Message contains a reference to MessageTypeId, and computed column MessageTypeBitFlag which is defined as POWER(2, MessageTypeId)
My query expressed in SQL looks something like:
SELECT * FROM Message, Recipient
WHERE Recipient.MessageTypeBitField & Message.MessageTypeBitFlag > 0
by doing a bitwise-AND on the bitfield and bitflag columns, it's easy to select only the messages that a particular recipient is interested in.
Problem is, I'm not doing this in SQL - I need to add this as an additional option to a fairly rich system built on the NHibernate Criteria API.
Is there any way to express this criteria via the NHibernate API - either using the API or by adding an SQL/HQL clause to the existing criteria?
OK, here's a specific implementation based on this linked post submitted by Firo, because I had to adapt this a little to make it work:
/// <summary>An NHibernate criterion that does bitwise comparison to match a bit flag against a bitmask.</summary>
public class BitMask : LogicalExpression {
private BitMask(string propertyName, object value, string op) :
base(new SimpleExpression(propertyName, value, op), Expression.Sql("?", 0, NHibernateUtil.Int64)) {
}
protected override string Op {
get { return ">"; }
}
/// <summary>Create a bitwise filter criterion - i.e. one that will be satisified if <code><paramref name="propertyName"/> & <paramref name="bits"/> > 0</code></summary>
public static BitMask Matches(string propertyName, long bits) {
return new BitMask(propertyName, bits, " & ");
}
}
and then use it via the Criteria API as follows:
public IEnumerable<Message> GetMessagesForRecipient(Recipient r) {
var messages = session.CreateCriteria<Message>()
.Add(BitMask.Matches("MessageTypeBitFlag ", r.MessageTypeBitField))
.List<Message>();
return(messages);
}
Okay, I have what I think is a simple question.. or just a case of me being a C# beginner.
I have an array of custom objects (clsScriptItem) that I am populating from a database. Once the items are loaded, I want to back them up to "backup" array so I can revert the information back after changing the main array. However, when I use CopyTo to copy the array and then alter the original array, the backup array is also being altered... I thought CopyTo merely copied values + structure from one array to another.
private void backupItems()
{
//lastSavedItems and items are both of type clsScriptItem[]
//(declaration not shown)
lastSavedItems = new clsScriptItem[items.Length];
items.CopyTo(lastSavedItems, 0);
//items[0].nexts[0] is 2
//lastSavedItems[0].nexts[0] is 2
items[0].nexts[0] = "-1";
//items[0].nexts[0] is -1
//lastSavedItems[0].nexts[0] is also -1
}
How do I backup this data without having the two arrays be 'linked'??
UPDATE :
I have updated the backup function to this
private void backupItems()
{
lastSavedItems = new clsScriptItem[items.Length];
for (int i = 0; i < items.Length; i++)
lastSavedItems[i] = (clsScriptItem)items[i].Clone();
items[0].nexts[0] = "-1";
}
And I have update my class thusly....
public class clsScriptItem : ICloneable
{
//other declarations...
object ICloneable.Clone() { return Clone(); }
public clsScriptItem Clone()
{
return ((clsScriptItem)MemberwiseClone());
}
}
** - and the same thing is happening.. Any thoughts?**
they aren't linked, you are using references to objects (So the second array contains 'pointers' to elements, which are the same as 'pointers' in first array..) so declare clsScriptItem as struct, or implement ICloneable interface and use
for(int i = 0; i < items.Length; i++)
lastSavedItems[i] = (clsScriptItem)items[i].Clone();
try this:-
public static MyType[] DeepClone(MyType[] obj)
{
using (MemoryStream ms = new MemoryStream())
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(ms, obj);
ms.Position = 0;
return (MyType[])formatter.Deserialize(ms);
}
}
This is a classic shallow copy vs deep copy problem. When you copy an array of reference types it is merely the references that are copied, not the objects those references point to. So your end result is two arrays that contain references to the same objects.
So when you copy an array that looks like this
Original
----
| |
| 0 |---> Cls
| |
----
| |
| 1 |---> Cls
| |
----
You get this
Original Copy
---- ----
| | | |
| 0 |---> Cls <--- | 0 |
| | | |
---- ----
| | | |
| 1 |---> Cls <--- | 1 |
| | | |
---- ----
If you change the referenced object in any way and it will look like you've changed the contents of both arrays when really all you've done is change the single object pointed to by both arrays.