Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Unit tests (#3)
Browse files Browse the repository at this point in the history
* Compare operators tests

* Removed mono.cecil, my bad

* CompareOperators dates tests, aggregation tests

* Refactor tests, my bad

* Working on subset and net452 test

* Helping Israel, because he doesn't know how to code....

* Process response subset test

* Fix unit test run

* Check Travis formats

* Revert test and cleaning build (still not working in Travis)

* Changed columns to have just one column date, travis ci test

* Test date to see on travis

* Travis test dates

* Update CompareOperatorsTest.cs

* Update Extensions.cs

* Minor changes, date tests

* Removed custom test

* Checking test

* Code Review

* Upgrade samples

* Refactor CompareOperatorsTest.cs

* Corrected observations

* Corrected observations

* Added dateUTC and boolean filter tests

* Changed Bool to IsShipped in tests

* Compare operators tests

* Removed mono.cecil, my bad

* CompareOperators dates tests, aggregation tests

* Refactor tests, my bad

* Working on subset and net452 test

* Helping Israel, because he doesn't know how to code....

* Process response subset test

* Fix unit test run

* Check Travis formats

* Revert test and cleaning build (still not working in Travis)

* Changed columns to have just one column date, travis ci test

* Test date to see on travis

* Travis test dates

* Update CompareOperatorsTest.cs

* Update Extensions.cs

* Minor changes, date tests

* Removed custom test

* Checking test

* Code Review

* Upgrade samples

* Refactor CompareOperatorsTest.cs

* Corrected observations

* Corrected observations

* Added dateUTC and boolean filter tests

* Changed Bool to IsShipped in tests

* Fixed tests
  • Loading branch information
geoperez authored Oct 24, 2017
1 parent 64c97df commit 368bfcc
Show file tree
Hide file tree
Showing 20 changed files with 295 additions and 499 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ solution: Unosquare.Tubular.sln
notifications:
slack: unolabs:cbusXPH6pBwZ35rVDzi4k4ve
dotnet: 2.0.0
mono: latest
sudo: required
install:
- dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Please visit the <a href="http://unosquare.github.io/tubular" target="_blank">Tu

## NuGet Installation [![NuGet version](https://badge.fury.io/nu/tubular.svg)](http://badge.fury.io/nu/tubular)

The same Nuget contains `.NET Framework 4.5.2` and `.NET Standard 1.6` targets.
The same Nuget contains `.NET Framework 4.5.2` and `.NET Standard 2.0` targets.

<pre>
PM> Install-Package Tubular.ServerSide
Expand Down
1 change: 1 addition & 0 deletions StyleCop.Analyzers.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1609" Action="None" />
<Rule Id="SA1623" Action="None" />
<Rule Id="SA1008" Action="None" />
</Rules>
</RuleSet>
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ before_build:
build_script:
- msbuild /p:Configuration=%CONFIGURATION%
test_script:
- tools\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"%ProgramFiles%\dotnet\dotnet.exe" -targetargs:"test test\Unosquare.Tubular.Tests -c %CONFIGURATION%" -output:coverage.xml -filter:"+[Unosquare.Tubular*]* -[Unosquare.Tubular.Tests*]*" -register:userdotnet
- tools\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"%ProgramFiles%\dotnet\dotnet.exe" -targetargs:"test test\Unosquare.Tubular.Tests -c %CONFIGURATION% -f net452" -output:coverage.xml -filter:"+[Unosquare.Tubular*]* -[Unosquare.Tubular.Tests*]*" -register:userdotnet
- tools\coveralls.net.0.7.0\tools\csmacnz.Coveralls.exe --opencover -i coverage.xml --serviceName appveyor --jobId %APPVEYOR_BUILD_NUMBER%
after_build:
- ps: |
Expand Down
20 changes: 8 additions & 12 deletions src/Unosquare.Tubular.AspNetCoreSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Startup(IHostingEnvironment env)
builder.AddEnvironmentVariables();
Configuration = builder.Build();

tokenOptions = new TokenValidationParameters
TokenOptions = new TokenValidationParameters
{
// The signing key must match!
ValidateIssuerSigningKey = true,
Expand All @@ -51,7 +51,7 @@ public Startup(IHostingEnvironment env)
}

public IConfigurationRoot Configuration { get; }
private TokenValidationParameters tokenOptions { get; set; }
private TokenValidationParameters TokenOptions { get; }


// This method gets called by the runtime. Use this method to add services to the container
Expand All @@ -60,7 +60,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddDbContext<SampleDbContext>(
options => options.UseSqlServer(Configuration["ConnectionString"]));

services.AddBearerTokenAuthentication(tokenOptions);
services.AddBearerTokenAuthentication(TokenOptions);

// Add framework services.
services.AddMvc()
Expand All @@ -81,18 +81,14 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
app.UseDefaultFiles();
app.UseStaticFiles();

app.UseBearerTokenAuthentication(tokenOptions, (userName, password, grantType, clientId) =>
app.UseBearerTokenAuthentication(TokenOptions, (userName, password, grantType, clientId) =>
{
// TODO: Replace with your implementation
if (userName == "Admin" && password == "pass.word")
{
if (userName != "Admin" || password != "pass.word") return Task.FromResult<ClaimsIdentity>(null);

var identity = new ClaimsIdentity();
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userName));
return Task.FromResult(identity);
}

return Task.FromResult<ClaimsIdentity>(null);
var identity = new ClaimsIdentity();
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userName));
return Task.FromResult(identity);
});

app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
Expand Down
14 changes: 0 additions & 14 deletions src/Unosquare.Tubular.EmbedioSample/App.config

This file was deleted.

34 changes: 19 additions & 15 deletions src/Unosquare.Tubular.EmbedioSample/PeopleController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Unosquare.Net;
using Unosquare.Labs.EmbedIO;
using Unosquare.Labs.EmbedIO.Modules;
using Unosquare.Tubular.ObjectModel;
using Unosquare.Swan;

namespace Unosquare.Tubular.EmbedioSample
namespace Unosquare.Tubular.EmbedioSample
{
using System;
using System.Collections.Generic;
using System.Linq;
using Labs.EmbedIO;
using Labs.EmbedIO.Modules;
using ObjectModel;
using Swan;
#if NETCOREAPP2_0
using System.Net;
#else
using Net;
#endif

/// <summary>
/// A simple model representing a person
/// </summary>
Expand All @@ -32,13 +36,13 @@ public class PeopleController : WebApiController

public static List<Person> People = new List<Person>
{
new Person() {Key = 1, Name = "Mario Di Vece", Age = 31, EmailAddress = "[email protected]"},
new Person() {Key = 2, Name = "Geovanni Perez", Age = 31, EmailAddress = "[email protected]"},
new Person() {Key = 3, Name = "Luis Gonzalez", Age = 29, EmailAddress = "[email protected]"},
new Person() {Key = 4, Name = "Ricardo Salinas", Age = 22, EmailAddress = "[email protected]"},
new Person {Key = 1, Name = "Mario Di Vece", Age = 31, EmailAddress = "[email protected]"},
new Person {Key = 2, Name = "Geovanni Perez", Age = 31, EmailAddress = "[email protected]"},
new Person {Key = 3, Name = "Luis Gonzalez", Age = 29, EmailAddress = "[email protected]"},
new Person {Key = 4, Name = "Ricardo Salinas", Age = 22, EmailAddress = "[email protected]"}
};

[WebApiHandler(HttpVerbs.Post, RelativePath + "people")]
[WebApiHandler(Labs.EmbedIO.Constants.HttpVerbs.Post, RelativePath + "people")]
public bool GetPeople(WebServer server, HttpListenerContext context)
{
try
Expand Down
6 changes: 3 additions & 3 deletions src/Unosquare.Tubular.EmbedioSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class Program
private static void Main(string[] args)
{
var url = args.Length > 0 ? args[0] : "http://localhost:9696/";

// Our web server is disposable. Note that if you don't want to use logging,
// there are alternate constructors that allow you to skip specifying an ILog object.
using (var server = new WebServer(url))
Expand All @@ -39,7 +39,7 @@ private static void Main(string[] args)
UseRamCache = true,
DefaultExtension = ".html"
});

// Once we've registered our modules and configured them, we call the RunAsync() method.
// This is a non-blocking method (it return immediately) so in this case we avoid
// disposing of the object until a key is pressed.
Expand All @@ -60,4 +60,4 @@ private static void Main(string[] args)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,24 @@

<PropertyGroup>
<AssemblyTitle>Tubular with EmbedIO webserver sample</AssemblyTitle>
<TargetFrameworks>netcoreapp1.1;net452</TargetFrameworks>
<AssemblyName>Unosquare.Tubular.EmbedioSample</AssemblyName>
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
<OutputType>Exe</OutputType>
<PackageId>Unosquare.Tubular.EmbedioSample</PackageId>
<RuntimeIdentifiers>win8-x64;ubuntu.14.04-x64;osx.10.11-x64</RuntimeIdentifiers>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">1.1.2</RuntimeFrameworkVersion>
</PropertyGroup>

<ItemGroup>
<None Update="html\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="App.config" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Unosquare.Tubular\Unosquare.Tubular.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="EmbedIO" Version="1.6.10" />
<PackageReference Include="Unosquare.Swan" Version="0.14.7" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
<PackageReference Include="EmbedIO" Version="1.10.0" />
<PackageReference Include="Unosquare.Swan" Version="0.17.1" />
</ItemGroup>

</Project>
78 changes: 36 additions & 42 deletions src/Unosquare.Tubular/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/// </summary>
public static class Extensions
{
private const string DateTimeFormat = "yyyy-MM-dd hh:mm:ss.f";
private const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss.f";
private const string DateFormat = "yyyy-MM-dd";

#if NET452
Expand Down Expand Up @@ -179,10 +179,9 @@ private static Dictionary<GridColumn, PropertyInfo> MapColumnsToProperties(
{
var columnMap = new Dictionary<GridColumn, PropertyInfo>(columns.Length);

foreach (var column in columns)
foreach (var column in columns.Where(column => properties.ContainsKey(column.Name)))
{
if (properties.ContainsKey(column.Name))
columnMap[column] = properties[column.Name];
columnMap[column] = properties[column.Name];
}

return columnMap;
Expand All @@ -203,13 +202,13 @@ private static List<List<object>> CreateGridPayload(

foreach (var column in columnMap.Select(m => new { Value = m.Value.GetValue(item), m.Key }))
{
if (column.Value is DateTime)
if (column.Value is DateTime time)
{
if (column.Key.DataType == DataType.DateTimeUtc ||
TubularDefaultSettings.AdjustTimezoneOffset == false)
payloadItem.Add((DateTime)column.Value);
payloadItem.Add(time);
else
payloadItem.Add(((DateTime)column.Value).AddMinutes(-timezoneOffset));
payloadItem.Add(time.AddMinutes(-timezoneOffset));
}
else
{
Expand Down Expand Up @@ -247,39 +246,33 @@ private static Dictionary<string, object> AggregateSubset(GridColumn[] columns,
var aggregateColumns = columns.Where(c => c.Aggregate != AggregationFunction.None).ToArray();
var payload = new Dictionary<string, object>(aggregateColumns.Length);

Action<GridColumn, Func<IQueryable<double>, double>, Func<IQueryable<decimal>, decimal>, Func<IQueryable<int>, int>, Func<IQueryable<string>, string>, Func<IQueryable<DateTime>, DateTime>> aggregate =
(column, doubleF, decimalF, intF, stringF, dateF) =>
void Aggregate(GridColumn column, Func<IQueryable<double>, double> doubleF, Func<IQueryable<decimal>, decimal> decimalF, Func<IQueryable<int>, int> intF, Func<IQueryable<string>, string> stringF, Func<IQueryable<DateTime>, DateTime> dateF)
{
if (subset.ElementType.GetProperty(column.Name).PropertyType == typeof(double))
{
if (subset.ElementType.GetProperty(column.Name).PropertyType == typeof(double))
{
payload.Add(column.Name,
doubleF(subset.Select(column.Name).Cast<double>()));
}
else if (subset.ElementType.GetProperty(column.Name).PropertyType == typeof(decimal))
{
payload.Add(column.Name,
decimalF(subset.Select(column.Name).Cast<decimal>()));
}
else if (subset.ElementType.GetProperty(column.Name).PropertyType == typeof(int))
{
payload.Add(column.Name,
intF(subset.Select(column.Name).Cast<int>()));
}
else if (subset.ElementType.GetProperty(column.Name).PropertyType == typeof(DateTime))
{
if (dateF == null) return;
payload.Add(column.Name, doubleF(subset.Select(column.Name).Cast<double>()));
}
else if (subset.ElementType.GetProperty(column.Name).PropertyType == typeof(decimal))
{
payload.Add(column.Name, decimalF(subset.Select(column.Name).Cast<decimal>()));
}
else if (subset.ElementType.GetProperty(column.Name).PropertyType == typeof(int))
{
payload.Add(column.Name, intF(subset.Select(column.Name).Cast<int>()));
}
else if (subset.ElementType.GetProperty(column.Name).PropertyType == typeof(DateTime))
{
if (dateF == null) return;

payload.Add(column.Name,
dateF(subset.Select(column.Name).Cast<DateTime>()));
}
else
{
if (stringF == null) return;
payload.Add(column.Name, dateF(subset.Select(column.Name).Cast<DateTime>()));
}
else
{
if (stringF == null) return;

payload.Add(column.Name,
stringF(subset.Select(column.Name).Cast<string>()));
}
};
payload.Add(column.Name, stringF(subset.Select(column.Name).Cast<string>()));
}
}

foreach (var column in aggregateColumns)
{
Expand All @@ -288,19 +281,19 @@ private static Dictionary<string, object> AggregateSubset(GridColumn[] columns,
switch (column.Aggregate)
{
case AggregationFunction.Sum:
aggregate(column, x => x.Sum(), x => x.Sum(), x => x.Sum(), null, null);
Aggregate(column, x => x.Sum(), x => x.Sum(), x => x.Sum(), null, null);

break;
case AggregationFunction.Average:
aggregate(column, x => x.Average(), x => x.Average(), x => x.Sum() / x.Count(), null, null);
Aggregate(column, x => x.Average(), x => x.Average(), x => x.Sum() / x.Count(), null, null);

break;
case AggregationFunction.Max:
aggregate(column, x => x.Max(), x => x.Max(), x => x.Max(), x => x.Max(), x => x.Max());
Aggregate(column, x => x.Max(), x => x.Max(), x => x.Max(), x => x.Max(), x => x.Max());

break;
case AggregationFunction.Min:
aggregate(column, x => x.Min(), x => x.Min(), x => x.Min(), x => x.Min(), x => x.Min());
Aggregate(column, x => x.Min(), x => x.Min(), x => x.Min(), x => x.Min(), x => x.Min());

break;

Expand Down Expand Up @@ -401,6 +394,7 @@ var column in
{
case CompareOperators.Equals:
case CompareOperators.NotEquals:

if (string.IsNullOrWhiteSpace(column.Filter.Text)) continue;

if (column.DataType == DataType.Date)
Expand Down Expand Up @@ -576,4 +570,4 @@ var column in
return subset;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Unosquare.Tubular/Unosquare.Tubular.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.7.7" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.7.9" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.5' ">
Expand Down
Loading

0 comments on commit 368bfcc

Please sign in to comment.