Skip to content

Commit

Permalink
Add DataGrid props ColumnCount and RowCount
Browse files Browse the repository at this point in the history
  • Loading branch information
tkurnosova committed Aug 3, 2015
1 parent 71a6e70 commit 945596c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 11 deletions.
41 changes: 34 additions & 7 deletions src/Tests/Winium.Elements.Desktop.Tests/DataGridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@ public class DataGridTests
[Test]
public void GetDataGridCell()
{
var driverMock = new Mock<RemoteWebDriver>(
new Mock<ICommandExecutor>().Object,
new Mock<ICapabilities>().Object);
var driverMock = new DriverMocked();

driverMock.Protected()
.Setup<Response>("Execute", "getDataGridCell", ItExpr.IsAny<Dictionary<string, object>>())
.Returns(Response.FromJson(@"{value: {ELEMENT: ""dGridCellElementId""}}"));

driverMock.Protected()
.Setup<Response>("Execute", "newSession", ItExpr.IsAny<Dictionary<string, object>>())
.Returns(Response.FromJson(@"{sessionId : ""AvesomeSession""}"));

var elementMock = new Mock<RemoteWebElement>(driverMock.Object, "dGridElementId");

var dataGrid = elementMock.Object.ToDataGrid();
Expand All @@ -43,6 +37,39 @@ public void GetDataGridCell()
Assert.That(cell, Is.TypeOf(typeof(RemoteWebElement)));
}

[Test]
public void GetDataGridColumnCount()
{
var driverMock = new DriverMocked();

driverMock.Protected()
.Setup<Response>("Execute", "getDataGridColumnCount", ItExpr.IsAny<Dictionary<string, object>>())
.Returns(Response.FromJson(@"{value: 2}"));

var elementMock = new Mock<RemoteWebElement>(driverMock.Object, "dGridElementId");

var dataGrid = elementMock.Object.ToDataGrid();

Assert.That(dataGrid.ColumnCount, Is.EqualTo(2));
}

[Test]
public void GetDataGridRowCount()
{
var driverMock = new DriverMocked();

driverMock.Protected()
.Setup<Response>("Execute", "getDataGridRowCount", ItExpr.IsAny<Dictionary<string, object>>())
.Returns(Response.FromJson(@"{value: 2}"));

var elementMock = new Mock<RemoteWebElement>(driverMock.Object, "dGridElementId");

var dataGrid = elementMock.Object.ToDataGrid();

Assert.That(dataGrid.RowCount, Is.EqualTo(2));
}

#endregion
}

}
29 changes: 29 additions & 0 deletions src/Tests/Winium.Elements.Desktop.Tests/DriverMocked.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Winium.Elements.Desktop.Tests
{
#region using

using System.Collections.Generic;

using Moq;
using Moq.Protected;

using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

#endregion

public class DriverMocked : Mock<RemoteWebDriver>
{
#region Constructors and Destructors

public DriverMocked()
: base(new Mock<ICommandExecutor>().Object, new Mock<ICapabilities>().Object)
{
this.Protected()
.Setup<Response>("Execute", "newSession", ItExpr.IsAny<Dictionary<string, object>>())
.Returns(Response.FromJson(@"{sessionId : ""AvesomeSession""}"));
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq, Version=4.2.1507.118, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll</HintPath>
<HintPath>..\..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<HintPath>..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="WebDriver, Version=2.46.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.2.46.0\lib\net40\WebDriver.dll</HintPath>
<HintPath>..\..\packages\Selenium.WebDriver.2.46.0\lib\net40\WebDriver.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DriverMocked.cs" />
<Compile Include="DataGridTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
40 changes: 39 additions & 1 deletion src/Winium.Elements.Desktop/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class DataGrid : DesktopElement

private const string GetDataGridCell = "getDataGridCell";

private const string GetDataGridColumnCount = "getDataGridColumnCount";

private const string GetDataGridRowCount = "getDataGridRowCount";

#endregion

#region Constructors and Destructors
Expand All @@ -23,7 +27,15 @@ static DataGrid()
{
CommandInfoRepository.Instance.TryAddCommand(
GetDataGridCell,
new CommandInfo("POST", "/session/{sessionId}/element/{id}/cell/{row}/{column}"));
new CommandInfo("POST", "/session/{sessionId}/element/{id}/datagrid/cell/{row}/{column}"));

CommandInfoRepository.Instance.TryAddCommand(
GetDataGridColumnCount,
new CommandInfo("POST", "/session/{sessionId}/element/{id}/datagrid/column/count"));

CommandInfoRepository.Instance.TryAddCommand(
GetDataGridRowCount,
new CommandInfo("POST", "/session/{sessionId}/element/{id}/datagrid/row/count"));
}

public DataGrid(IWebElement element)
Expand All @@ -33,6 +45,32 @@ public DataGrid(IWebElement element)

#endregion

#region Public Properties

public int ColumnCount
{
get
{
var parameters = new Dictionary<string, object> { { "id", this.WrappedElement.GetId() } };
var response = this.WrappedElement.Execute(GetDataGridColumnCount, parameters);

return int.Parse(response.Value.ToString());
}
}

public int RowCount
{
get
{
var parameters = new Dictionary<string, object> { { "id", this.WrappedElement.GetId() } };
var response = this.WrappedElement.Execute(GetDataGridRowCount, parameters);

return int.Parse(response.Value.ToString());
}
}

#endregion

#region Public Methods and Operators

public RemoteWebElement GetCell(int row, int column)
Expand Down

0 comments on commit 945596c

Please sign in to comment.