Skip to content

Commit

Permalink
Camel Case the world (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Nov 24, 2018
1 parent 547e178 commit 6bfb270
Show file tree
Hide file tree
Showing 81 changed files with 288 additions and 492 deletions.
11 changes: 1 addition & 10 deletions lib/PuppeteerSharp.DevicesFetcher/Models.cs
Expand Up @@ -4,40 +4,31 @@ namespace PuppeteerSharp.DevicesFetcher
{
public class RootObject
{
[JsonProperty("extensions")]
public Extension[] Extensions { get; set; }

public class Extension
{
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("device")]
public Device Device { get; set; }
}

public class Device
{
[JsonProperty("show-by-default")]
public bool ShowByDefault { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("screen")]
public Screen Screen { get; set; }
[JsonProperty("capabilities")]
public string[] Capabilities { get; set; }
[JsonProperty("user-agent")]
public string UserAgent { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
public string Type { get; set; }
}

public class Screen
{
[JsonProperty("horizontal")]
public ViewportPayload Horizontal { get; set; }
[JsonProperty("device-pixel-ratio")]
public double DevicePixelRatio { get; set; }
[JsonProperty("vertical")]
public ViewportPayload Vertical { get; set; }
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/PuppeteerSharp.DevicesFetcher/Program.cs
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;

namespace PuppeteerSharp.DevicesFetcher
{
Expand Down
3 changes: 0 additions & 3 deletions lib/PuppeteerSharp.DevicesFetcher/ViewportPayload.cs
Expand Up @@ -4,10 +4,7 @@ namespace PuppeteerSharp.DevicesFetcher
{
public class ViewportPayload
{
[JsonProperty("width")]
public double Width { get; set; }

[JsonProperty("height")]
public double Height { get; set; }
}
}
4 changes: 0 additions & 4 deletions lib/PuppeteerSharp.Tests/InputTests/Dimensions.cs
Expand Up @@ -5,13 +5,9 @@ namespace PuppeteerSharp.Tests.InputTests
{
public class Dimensions
{
[JsonProperty("x")]
public decimal X { get; set; }
[JsonProperty("y")]
public decimal Y { get; set; }
[JsonProperty("width")]
public decimal Width { get; set; }
[JsonProperty("height")]
public decimal Height { get; set; }
}
}
29 changes: 26 additions & 3 deletions lib/PuppeteerSharp.Tests/PageTests/EvaluateTests.cs
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
using Xunit.Abstractions;
using PuppeteerSharp.Helpers;

namespace PuppeteerSharp.Tests.PageTests
{
Expand Down Expand Up @@ -69,6 +69,24 @@ public async Task SouldReturnComplexObjects()
Assert.Equal("bar!", result.foo.ToString());
}

[Fact]
public async Task ShouldWorkWithDifferentSerializerSettings()
{
var result = await Page.EvaluateFunctionAsync<ComplexObjectTestClass>("() => { return { foo: 'bar' }}");
Assert.Equal("bar", result.Foo);

result = (await Page.EvaluateFunctionAsync<JToken>("() => { return { Foo: 'bar' }}"))
.ToObject<ComplexObjectTestClass>(new JsonSerializerSettings());
Assert.Equal("bar", result.Foo);

result = await Page.EvaluateExpressionAsync<ComplexObjectTestClass>("var obj = { foo: 'bar' }; obj;");
Assert.Equal("bar", result.Foo);

result = (await Page.EvaluateExpressionAsync<JToken>("var obj = { Foo: 'bar' }; obj;"))
.ToObject<ComplexObjectTestClass>(new JsonSerializerSettings());
Assert.Equal("bar", result.Foo);
}

[Theory]
[InlineData("() => NaN", double.NaN)] //ShouldReturnNaN
[InlineData("() => -0", -0)] //ShouldReturnNegative0
Expand Down Expand Up @@ -265,5 +283,10 @@ public async Task ShouldWorkWithoutGenerics()
Assert.Equal(11111111111111, await Page.EvaluateExpressionAsync("11111111111111"));
Assert.Equal(1.1, await Page.EvaluateExpressionAsync("1.1"));
}

public class ComplexObjectTestClass
{
public string Foo { get; set; }
}
}
}
2 changes: 0 additions & 2 deletions lib/PuppeteerSharp.Tests/TargetTests/CreateCDPSessionTests.cs
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Xunit;
Expand Down
10 changes: 5 additions & 5 deletions lib/PuppeteerSharp.sln
Expand Up @@ -2,15 +2,15 @@
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2035
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PuppeteerSharp", "PuppeteerSharp\PuppeteerSharp.csproj", "{19B9B1ED-AF6C-4DAF-8B73-401570111F88}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuppeteerSharp", "PuppeteerSharp\PuppeteerSharp.csproj", "{19B9B1ED-AF6C-4DAF-8B73-401570111F88}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PuppeteerSharp.Tests", "PuppeteerSharp.Tests\PuppeteerSharp.Tests.csproj", "{1682289E-5ED3-405F-8ABC-01A3ED58CBC6}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuppeteerSharp.Tests", "PuppeteerSharp.Tests\PuppeteerSharp.Tests.csproj", "{1682289E-5ED3-405F-8ABC-01A3ED58CBC6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PuppeteerSharp.TestServer", "PuppeteerSharp.TestServer\PuppeteerSharp.TestServer.csproj", "{0CC393AB-10C2-4CDB-8353-78924D3DD5D3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuppeteerSharp.TestServer", "PuppeteerSharp.TestServer\PuppeteerSharp.TestServer.csproj", "{0CC393AB-10C2-4CDB-8353-78924D3DD5D3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PuppeteerSharp.Tests.DumpIO", "PuppeteerSharp.Tests.DumpIO\PuppeteerSharp.Tests.DumpIO.csproj", "{B1892212-CEE3-4DC3-ADB8-04A2D9A081A0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuppeteerSharp.Tests.DumpIO", "PuppeteerSharp.Tests.DumpIO\PuppeteerSharp.Tests.DumpIO.csproj", "{B1892212-CEE3-4DC3-ADB8-04A2D9A081A0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PuppeteerSharp.Tests.CloseMe", "PuppeteerSharp.Tests.CloseMe\PuppeteerSharp.Tests.CloseMe.csproj", "{B1B0358F-88A2-4038-9974-7850D906C76B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuppeteerSharp.Tests.CloseMe", "PuppeteerSharp.Tests.CloseMe\PuppeteerSharp.Tests.CloseMe.csproj", "{B1B0358F-88A2-4038-9974-7850D906C76B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuppeteerSharp.DevicesFetcher", "PuppeteerSharp.DevicesFetcher\PuppeteerSharp.DevicesFetcher.csproj", "{A500694A-3649-4474-BC71-C835FA19B865}"
EndProject
Expand Down
4 changes: 0 additions & 4 deletions lib/PuppeteerSharp/BoundingBox.cs
Expand Up @@ -13,25 +13,21 @@ public class BoundingBox : IEquatable<BoundingBox>
/// The x coordinate of the element in pixels.
/// </summary>
/// <value>The x.</value>
[JsonProperty("x")]
public decimal X { get; set; }
/// <summary>
/// The y coordinate of the element in pixels.
/// </summary>
/// <value>The y.</value>
[JsonProperty("y")]
public decimal Y { get; set; }
/// <summary>
/// The width of the element in pixels.
/// </summary>
/// <value>The width.</value>
[JsonProperty("width")]
public decimal Width { get; set; }
/// <summary>
/// The height of the element in pixels.
/// </summary>
/// <value>The height.</value>
[JsonProperty("height")]
public decimal Height { get; set; }

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions lib/PuppeteerSharp/Browser.cs
Expand Up @@ -152,7 +152,7 @@ public class Browser : IDisposable
/// <summary>
/// Dafault wait time in milliseconds. Defaults to 30 seconds.
/// </summary>
public int DefaultWaitForTimeout { get; set; } = 30000;
public int DefaultWaitForTimeout { get; set; } = 30000;

#endregion

Expand Down Expand Up @@ -397,15 +397,15 @@ private async void Connect_MessageReceived(object sender, MessageEventArgs e)
switch (e.MessageID)
{
case "Target.targetCreated":
await CreateTargetAsync(e.MessageData.ToObject<TargetCreatedResponse>()).ConfigureAwait(false);
await CreateTargetAsync(e.MessageData.ToObject<TargetCreatedResponse>(true)).ConfigureAwait(false);
return;

case "Target.targetDestroyed":
await DestroyTargetAsync(e.MessageData.ToObject<TargetDestroyedResponse>()).ConfigureAwait(false);
await DestroyTargetAsync(e.MessageData.ToObject<TargetDestroyedResponse>(true)).ConfigureAwait(false);
return;

case "Target.targetInfoChanged":
ChangeTargetInfo(e.MessageData.ToObject<TargetCreatedResponse>());
ChangeTargetInfo(e.MessageData.ToObject<TargetCreatedResponse>(true));
return;
}
}
Expand Down
6 changes: 4 additions & 2 deletions lib/PuppeteerSharp/CDPSession.cs
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using PuppeteerSharp.Helpers;
using PuppeteerSharp.Messaging;

Expand Down Expand Up @@ -118,7 +119,7 @@ public async Task<T> SendAsync<T>(string method, dynamic args = null)
{
JObject content = await SendAsync(method, args).ConfigureAwait(false);

return content.ToObject<T>();
return content.ToObject<T>(true);
}

/// <summary>
Expand Down Expand Up @@ -147,7 +148,8 @@ public async Task<JObject> SendAsync(string method, dynamic args = null, bool wa
{ MessageKeys.Id, id },
{ MessageKeys.Method, method },
{ MessageKeys.Params, args }
});
}, JsonHelper.DefaultJsonSerializerSettings);

_logger.LogTrace("Send ► {Id} Method {Method} Params {@Params}", id, method, (object)args);

MessageTask callback = null;
Expand Down
7 changes: 4 additions & 3 deletions lib/PuppeteerSharp/Connection.cs
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using PuppeteerSharp.Helpers;
using PuppeteerSharp.Messaging;
using PuppeteerSharp.Transport;
Expand Down Expand Up @@ -102,7 +103,7 @@ internal async Task<JObject> SendAsync(string method, dynamic args = null, bool
{ MessageKeys.Id, id },
{ MessageKeys.Method, method },
{ MessageKeys.Params, args }
});
}, JsonHelper.DefaultJsonSerializerSettings);

_logger.LogTrace("Send ► {Id} Method {Method} Params {@Params}", id, method, (object)args);

Expand All @@ -125,7 +126,7 @@ internal async Task<JObject> SendAsync(string method, dynamic args = null, bool
internal async Task<T> SendAsync<T>(string method, dynamic args = null)
{
JToken response = await SendAsync(method, args).ConfigureAwait(false);
return response.ToObject<T>();
return response.ToObject<T>(true);
}

internal async Task<CDPSession> CreateSessionAsync(TargetInfo targetInfo)
Expand Down Expand Up @@ -195,7 +196,7 @@ private async void Transport_MessageReceived(object sender, MessageReceivedEvent

try
{
obj = JObject.Parse(response);
obj = JsonConvert.DeserializeObject<JObject>(response, JsonHelper.DefaultJsonSerializerSettings);
}
catch (JsonException exc)
{
Expand Down
6 changes: 2 additions & 4 deletions lib/PuppeteerSharp/ContextPayload.cs
Expand Up @@ -4,9 +4,7 @@ namespace PuppeteerSharp
{
internal class ContextPayload
{
[JsonProperty("id")]
internal int Id { get; set; }
[JsonProperty("auxData")]
internal ContextPayloadAuxData AuxData { get; set; }
public int Id { get; set; }
public ContextPayloadAuxData AuxData { get; set; }
}
}
6 changes: 2 additions & 4 deletions lib/PuppeteerSharp/ContextPayloadAuxData.cs
Expand Up @@ -4,9 +4,7 @@ namespace PuppeteerSharp
{
internal class ContextPayloadAuxData
{
[JsonProperty("frameId")]
internal string FrameId { get; set; }
[JsonProperty("isDefault")]
internal bool IsDefault { get; set; }
public string FrameId { get; set; }
public bool IsDefault { get; set; }
}
}
18 changes: 8 additions & 10 deletions lib/PuppeteerSharp/CookieParam.cs
Expand Up @@ -14,61 +14,59 @@ public class CookieParam
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>The value.</value>
[JsonProperty("value")]
public string Value { get; set; }
/// <summary>
/// Gets or sets the domain.
/// </summary>
/// <value>The domain.</value>
[JsonProperty("domain", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Domain { get; set; }
/// <summary>
/// Gets or sets the URL.
/// </summary>
/// <value>The URL.</value>
[JsonProperty("url", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Url { get; set; }
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
[JsonProperty("path", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Path { get; set; }
/// <summary>
/// Gets or sets the expiration.
/// </summary>
/// <value>Expiration.</value>
[JsonProperty("expires", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public double? Expires { get; set; }
/// <summary>
/// Gets or sets the size.
/// </summary>
/// <value>The size.</value>
[JsonProperty("size", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public int? Size { get; set; }
/// <summary>
/// Gets or sets if it's HTTP only.
/// </summary>
/// <value>Whether it's http only or not.</value>
[JsonProperty("httpOnly", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public bool? HttpOnly { get; set; }
/// <summary>
/// Gets or sets if it's secure.
/// </summary>
/// <value>Whether it's secure or not.</value>
[JsonProperty("secure", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public bool? Secure { get; set; }
/// <summary>
/// Gets or sets if it's session only.
/// </summary>
/// <value>Whether it's session only or not.</value>
[JsonProperty("session", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public bool? Session { get; set; }
}
}
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp/ElementHandle.cs
Expand Up @@ -134,7 +134,7 @@ public async Task<string> ScreenshotBase64Async(ScreenshotOptions options)
Width = (int)Math.Max(viewport.Width, Math.Ceiling(boundingBox.Width)),
Height = (int)Math.Max(viewport.Height, Math.Ceiling(boundingBox.Height))
});
await Page.SetViewportAsync(newRawViewport.ToObject<ViewPortOptions>()).ConfigureAwait(false);
await Page.SetViewportAsync(newRawViewport.ToObject<ViewPortOptions>(true)).ConfigureAwait(false);
needsViewportReset = true;
}
await ExecutionContext.EvaluateFunctionAsync(@"function(element) {
Expand Down
14 changes: 0 additions & 14 deletions lib/PuppeteerSharp/EvaluateExceptionDetails.cs

This file was deleted.

0 comments on commit 6bfb270

Please sign in to comment.