Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves PR80, prep for new driver release #82

Merged
merged 2 commits into from
Aug 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Source/RethinkDb.Driver.Tests/NLog.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
<target xsi:type="File" name="f" fileName="${basedir}/TRACE.log"
layout="${uppercase:${level}} ${message}" deleteOldFileOnStartup="true" />
<target name="memory" xsi:type="Memory" layout="${uppercase:${level}} ${message}" />
<target name="console" xsi:type="Console" layout="${uppercase:${level}} ${message}"/>
</targets>
Expand All @@ -40,6 +42,6 @@
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
<logger name="*" minlevel="Trace" writeTo="console, memory" />
<logger name="*" minlevel="Trace" writeTo="console, memory, f" />
</rules>
</nlog>
1 change: 1 addition & 0 deletions Source/RethinkDb.Driver.Tests/QueryTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void AfterRunningTestSession()
[SetUp]
public virtual void BeforeEachTest()
{
Converter.InitializeDefault();
EnsureConnection();

try
Expand Down
6 changes: 6 additions & 0 deletions Source/RethinkDb.Driver.Tests/ReQL/GroupingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public class Game
[TestFixture]
public class GroupingTests : QueryTestFixture
{
public override void BeforeEachTest()
{
base.BeforeEachTest();
ClearDefaultTable();
}

[Test]
public void can_read_grouping_reql_type()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;
using System.Dynamic;
using System.Linq;
using FluentAssertions;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using NUnit.Framework;
using RethinkDb.Driver.Ast;
using RethinkDb.Driver.Model;
using RethinkDb.Driver.Tests.Utils;

namespace RethinkDb.Driver.Tests.ReQL
{
public class GitterQuestions : QueryTestFixture
public class SlackIssues : QueryTestFixture
{

public class Person
Expand Down Expand Up @@ -68,5 +68,51 @@ public void jakes_serilization_of_jobject_issue()
var result = R.Db(DbName).Table(TableName).Insert(poco).RunResult(conn);
result.AssertInserted(1);
}


[Test]
public void olivers_datetimeoffset_issue()
{
ClearDefaultTable();

var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
DateFormatHandling = DateFormatHandling.IsoDateFormat,
DateParseHandling = DateParseHandling.None,
DateTimeZoneHandling = DateTimeZoneHandling.Unspecified,
Converters = new JsonConverter[] {new StringEnumConverter()},
NullValueHandling = NullValueHandling.Ignore,
};

Net.Converter.Converters = settings.Converters.ToArray();

Net.Converter.Serializer = JsonSerializer.Create(settings);


var obj = new JObject
{
["time"] = "2016-08-04T00:00:00+00:00"
};

var insertResult = R.Db(DbName).Table(TableName).Insert(obj)
.RunResult(conn);

insertResult.Dump();

var key = insertResult.GeneratedKeys[0];

var getResult = R.Db(DbName).Table(TableName).Get(key)
.RunResult<JObject>(conn);

var timeThing = getResult["time"];

timeThing.Type.Should().Be(JTokenType.String);

var putBack = R.Db(DbName).Table(TableName).Update(getResult)
.RunResult(conn);

putBack.Dump();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
<Compile Include="ReQL\Examples.cs" />
<Compile Include="ReQL\ExperimentalTests.cs" />
<Compile Include="ReQL\GitHubIssues.cs" />
<Compile Include="ReQL\GitterIssues.cs" />
<Compile Include="ReQL\GroupingTests.cs" />
<Compile Include="ReQL\JObjectTests.cs" />
<Compile Include="ReQL\MapTests.cs" />
Expand All @@ -133,6 +132,7 @@
<Compile Include="ReQL\BinaryTests.cs" />
<Compile Include="ReQL\RunHelperTests.cs" />
<Compile Include="ReQL\RxReactiveExtensionTests.cs" />
<Compile Include="ReQL\SlackIssues.cs" />
<Compile Include="ReQL\StackOverflowQuestions.cs" />
<Compile Include="TestLogContext.cs" />
<Compile Include="Utils\ExtensionsForTesting.cs" />
Expand Down
1 change: 0 additions & 1 deletion Source/RethinkDb.Driver.Tests/TestLogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public static string LogText()

public static void ResetContext()
{
//Context = new TestLogContext();
memoryTarget = LogManager.Configuration.FindTargetByName<MemoryTarget>("memory");
memoryTarget.Logs.Clear();
}
Expand Down
13 changes: 12 additions & 1 deletion Source/RethinkDb.Driver/Net/Response.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -67,7 +68,8 @@ private Response(long token, ResponseType responseType)
public static Response ParseFrom(long token, string buf)
{
Log.Trace($"JSON Recv: Token: {token}, JSON: {buf}");
var jsonResp = JObject.Parse(buf);

var jsonResp = ParseJson(buf);
var responseType = jsonResp[TypeKey].ToObject<ResponseType>();
var responseNotes = jsonResp[NotesKey]?.ToObject<List<ResponseNote>>() ?? new List<ResponseNote>();
ErrorType? et = jsonResp[ErrorKey]?.ToObject<ErrorType>();
Expand All @@ -87,6 +89,15 @@ public static Response ParseFrom(long token, string buf)
return res;
}

private static JObject ParseJson(string buf)
{
using( var reader = new JsonTextReader(new StringReader(buf)) )
{
return Converter.Serializer.Deserialize<JObject>(reader);
}
}


internal virtual bool IsWaitComplete => this.Type == ResponseType.WAIT_COMPLETE;

/* Whether the response is any kind of feed */
Expand Down
2 changes: 1 addition & 1 deletion Source/RethinkDb.Driver/Utils/ExtensionsForType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static bool IsASubclassOf(this Type type, Type other)
}
public static bool IsJToken(this Type type)
{
return typeof(JToken).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo());
return typeof(JToken) == type || type.IsASubclassOf(typeof(JToken));
}

public static bool IsGenericType(this Type type)
Expand Down