I am using specflow and I have a rather large table in my examples:
it has around 14 fields.
is there a better way of passing all of those filds into a method that is item1 and item2 and item4
I can see that there is a create set method, but this doesn't seem to cater for examples, and only in step....well steps.
is there a way to pass the data in an object rather than sending 14 strings?
Hope that makes sense.
Ta,
Steve
** Edit ** adding an example
Here is the headers for my exmaple file
| propLocation | locPropToBuy | propertyType | newBuild | appsLiveProprty | ownershipType | purchPrice | totLoanAmount | intOnlyAmount | prefLoanTermYrs | prefLoanTermMths |
the method generated for this will look like this:
[When(#"the user provides input for the Property and Loan Requirements Section (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*)")]
public void WhenTheUserProvidesInputForThePropertyAndLoanRequirementsSectionEnglandAndYesAndTerracedHouseAndYesAndYesAndStandardAndAndAndAndAndAndAndAndSAnd(string propLocation,
string locPropToBuy, string propertyType, string newBuild, string legalOwnership,
string ownershipType, string equityShreScheme, string purchPrice, string fullMarketVal,
string termShareLoanYrs, string termShareLoanMths, string totLoanAmount,
string intOnlyAmount, string prefLoanTermYrs, string prefLoanTermMths)
Although I will eventually change the coded values to (.*) etc.
It would be easier for me if I could just pass an object or a list of all the values rather than long instances of strings.
Take a look at Specflow tables
When the user provides input for the Property and Loan Requirements Section
| Key | Value |
| propLocation| NYC |
| locPropToBuy| House123 |
| propertyType| House |
| newBuild | Nope |
and so on and so on
Create a new class with PropertyLoanData and then interpret the table
public class PropertyLoanData
{
public string propLocation { get; set; }
public string locPropToBuy { get; set; }
public string propertyType { get; set; }
public string newBuild { get; set; }
}
.
[When(#"the user provides input for the Property and Loan Requirements Section
public void WhenUserprovidesinputforPropertyAndLoanSection(Table table)
{
var proploandata = table.CreateInstance<PropertyLoanData>();
driver.FindElement(By.Id("propLocation")).SendKeys(proploandata.propLocation);
driver.FindElement(By.Id("locPropToBuy")).SendKeys(proploandata.locPropToBuy);
driver.FindElement(By.Id("propertyType")).SendKeys(proploandata.propertyType);
driver.FindElement(By.Id("newBuild")).SendKeys(proploandata.newBuild);
}
Related
I have two tables department and teacher like this:
Department table (DeptID is the primary key)
DeptID | DeptName
1 P
2 C
3 M
Teacher table (DeptID is a foreign key)
DeptID | TeacherName
1 ABC
1 PQR
2 XYZ
I have used database first approach to create a single model out of these two tables. I want to display both details in a single view like this:
TeacherName | DeptName
ABC P
PQR P
XYZ C
I tried to create controllers using scaffolding but it would provide views and CRUD operations for a single table in the model.
Is there any method using which I can map these two tables together in a single view ? or is it possible (easily achievable) when I use different models for each table in the database ?
You have to create Viewmodel.
public class DepartmentTeacher
{
public int DeptID {get;set;}
public string DeptName {get;set;}
public int TeachID {get;set;}
public string TeachName {get;set;}
}
using (var db = new SchoolContext())
{
var query = (from tc in db.Teacher
join dp in db.Department on tc.DeptID equals dp.DeptID
//where st.STUDENT_ID == Customer_Id maybe you need
select new
{
dp.DeptName,
tc.TeachName
});
foreach (var item in query)
{
DepartmentTeacher.DeptName = item.DeptName;
DepartmentTeacher.TeachName = item.TeachName;
}
}
return View(DepartmentTeacher);
You can use every process this viewmodel.However you have to description this Viewmodel on your view page.
I have the following in my Google cloud storage
Advertiser | Event
__________________
100 | Click
101 | Impression
100 | Impression
100 | Impression
101 | Impression
My output of the pipeline should be something like
Advertiser | Clicks | Impressions
100 | 1 | 2
101 | 0 | 2
First I used groupByKey, the output is like
100 Click, Impression, Impression
101 Impression, Impression
Now is it possible to count the value in KV?
Currently I just used comparing strings to count the clicks and impressions.
Is it possible to use count transforms over here?
Or do we any other transforms to be used here?
Or the way that I did is the only way?
Thanks,
Sam.
I'm assuming your input is available as a PCollection<KV<Long, EventType>> input where the Long is the advertiser ID and EventType is an enum { CLICK, IMPRESSION, possibly something else }.
I'm also assuming you want the output to be a PCollection> where AdvertiserStats is a class with fields "numClicks", "numImpressions".
In that case one way to achieve what you want is to use Combine - input.apply(Combine.<Long, AdvertiserStats>perKey(new ComputeAdvertiserStatsFn())), where ComputeAdvertiserStatsFn is defined something like this:
public class ComputeAdvertiserStatsFn
extends CombineFn<EventType, AdvertiserStats, AdvertiserStats> {
public AdvertiserStats createAccumulator() { return new AdvertiserStats(); }
public void addInput(AdvertiserStats stats, EventType input) {
switch (input) {
case CLICK: stats.numClicks++; break;
case IMPRESSION: stats.numImpressions++; break;
default: (depending on your application?)
}
}
public AdvertiserStats mergeAccumulators(Iterable<AdvertiserStats> stats) {
AdvertiserStats merged = createAccumulator();
for (AdvertiserStats item : stats) {
merged.numClicks += item.numClicks;
merged.numImpressions += item.numImpressions;
}
return merged;
}
public AdvertiserStats extractOutput(AdvertiserStats stats) { return stats; }
}
This should perform very well because most of the grouping and counting will happen locally.
Currently, AFAIK, there is no PTransform that would do the work of ComputeAdvertiserStatsFn for you. I think the ideal interface would look something like input.apply(Combine.perKey(Count.perElement())), but it wouldn't work with the way these are currently defined.
I have created a domain class as given below, which contains an int and list of Integer properties.
class User {
int UserId
List<Integer> UserFriendsId
static constraints = {
}
User() {
this.UserId = 21
this.UserFriendsId=[1,2,3]
}
}
The table generated for this domain class while saving is as follows
mysql> select * from user;
+----+---------+---------------------+
| id | version | UserId |
+----+---------+---------------------+
| 1 | 0 | 21 |
| 2 | 0 | 21 |
| 3 | 0 | 21 |
+----+---------+---------------------+
3 rows in set (0.00 sec)
column for userFriendsId (ie: for list of integers) is not generated in this table user.
so how can solve this issue or can add list of integer in grails domain class.
The UserFriendsId List should be mapped as a GORM basic collection type and not simply be a list in the User domain class:
class User {
int userId
static hasMany = [userFriendsIds: Integer]
static mapping = {
userFriendsIds joinTable: [name: "user_id", column: "friend_id", type: Integer]
}
static constraints = {
}
User() {
}
}
Why not just make UserFriendsId a comma separated String?
class User {
int UserId
String UserFriendsId
static constraints = {
}
User() {
this.UserId = 21
this.UserFriendsId = "1,2,3"
}
}
Then:
for (userId in UserFriendsId.get(21).split(','))
{
println userId.toInteger()
/// Or do whatever ...
}
I have a Model like so:
class Model
{
public String Text { get; set; }
public AnotherType[] Values { get; set; }
}
And a View that takes an IEnumerable<Model> that I am displaying in a WebGrid using Razor and asp.net MVC 4.
So far I have:
#{ var grid = new WebGrid(Model); }
<div id="grid">
#grid.GetHtml(
columns:
grid.Columns(
grid.Column("Text")))
</div>
What I would like is to create a list of comma separated list of links based on the value of Values in my model in the second column.
I have tried just creating a Linq query to project them into ActionLinks, (or even a String Array and use String.Join() to test it) but that doesn't compile at Runtime.
For example:
grid.Column("Values",
format: (item) => String.Join(item.Select(v => v.Property).ToArray()))))
The error I get is (I think):
error CS1977: Cannot use a lambda expression as an argument to a
dynamically dispatched operation without first casting it to a
delegate or expression tree type
I'd like my output to look like:
|--------------------------------|
|**Text** | **Values** |
|--------------------------------|
|Text A | Val 1, Val 2, Val 3 |
|--------------------------------|
Where Val n is a link that can navigate you away to view more detail.
Does anyone know of a way to do this?
As a workaround, I have combined the values in my Model and expose a String property with the result, but this doesn't allow me to create ActionLinks.
You have to cast the item (dynamic) as AnotherType
(item).Cast<AnotherType>()
I have a quick question about Dapper. I have a query that returns 4 tables.
Three tables have just one integer column. Call them field1, field2, and field3.
The 4th table has 5 columns say:
A,B,C,D,E.
I have made an object called ResultSet that has all the fields from the 4 tables
public class ResultSet
{
int field1;
int field2;
int field3;
string A;
string B;
string C;
string D;
string E
}
How do I map the results to the ResultSet object?
Currently I am using QueryMultiple to get the desired result. But it is only mapping the 1st 3 columns. A,B,C,D,and E are all null.
I do not want to use a Union to get all the Fields in just one single table.
You should be able to achieve this by handing the connection.Query extension method an appropriate parameterised SQL statement, and pass it your object as the Type parameter.
Dapper will then map your query to the object magically, assuming you alias the items in the select list appropriately (ie, alias them with the corresponding property name of your object).
Something along these lines should work:
public class SomeObject
{
public int Field1 {get; set;}
public int Field2 {get; set;}
public int A {get; set;}
public int B {get; set;}
public int C {get; set;}
public int D {get; set;}
}
using(var connection = SomeConnectionFactory.GetConnection())
{
var yourObject =
connection.Query<SomeObject>("select tab1.someThing as Field1, " +
"tab2.someThing as Field2, " +
"tab4.onePotato as A, " +
"tab4.twoPotato as B, " +
"tab4.threePotato as C, " +
"tab4.four as D " +
"from someTable tab1 " +
"join someTable2 tab2 on tab1.Id = tab2.Id " +
"$$ etc etc for the other joins $$" +
"where tab1.Id = :ID " + ,new {ID = someId});
};
One note is that i've used the bind variable syntax for an Oracle database (:). You'll need to replace this with the equivalent for your DB.
Hope that's useful.