Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

(#604) Fix for negative search comparison in offline table. #605

Merged
merged 2 commits into from
Feb 10, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private QueryNode ParseUnary()
{
lexer.Token.Text = $"-{lexer.Token.Text}";
lexer.Token.Position = operatorPosition;
ParsePrimary();
return ParsePrimary();
}

QueryNode expression = ParseUnary();
Expand Down
1 change: 1 addition & 0 deletions sdk/dotnet/test/Datasync.Common.Test/Models/KitchenSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class KitchenSink : EntityTableData
public decimal DecimalValue { get; set; }
public double DoubleValue { get; set; }
public float FloatValue { get; set; }
public double? NullableDouble { get; set; }

// String
public char CharValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ public void QueryTokenKind_ToBinaryOperatorKind_ThrowsOnInvalid(QueryTokenKind k
[InlineData("$filter=(not(bestPictureWinner) and (ceiling((duration div 60.0)) eq 2.0))")]
[InlineData("$filter=(not(bestPictureWinner) and (floor((duration div 60.0)) eq 2.0))")]
[InlineData("$filter=(year lt 1990.5f)")]
[InlineData("$filter=(nullableValue le -0.5)")]
public void ODataExpressionParser_Roundtrips(string original)
{
var query = QueryDescription.Parse("movies", original);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,39 @@ public void ToODataString_DefaultIncludeParameters()
Assert.Equal("$orderby=releaseDate&foo=bar", actual);
}

[Fact]
public void ToODataString_NegativeDouble_Works()
{
var client = GetMockClient();
var table = new RemoteTable<KSV>("ksv", client);
var query = new TableQuery<KSV>(table).Where(x => x.Value <= -0.5) as TableQuery<KSV>;
var actual = query.ToODataString();
Assert.Equal("$filter=(value le -0.5)", actual);
}

[Fact]
public void ToODataString_NegativeNullableDouble_Works()
{
var client = GetMockClient();
var table = new RemoteTable<KSV>("ksv", client);
var query = new TableQuery<KSV>(table).Where(x => x.NullableValue <= -0.5) as TableQuery<KSV>;
var actual = query.ToODataString();
Assert.Equal("$filter=(nullableValue le -0.5)", actual);
}

#region Models
public class SelectResult
{
public string Id { get; set; }
public string Title { get; set; }
}

public class KSV : DatasyncClientData
{
public double Value { get; set; }

public double? NullableValue { get; set; }
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class KitchenSinkDto : DatasyncClientData
public decimal DecimalValue { get; set; }
public double DoubleValue { get; set; }
public float FloatValue { get; set; }
public double? NullableDouble { get; set; }

// String
public char CharValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,30 @@ public async Task KS1_NullRoundtrips()
}

[Fact]
public async Task KS2_DeferredTableDefinition()
public async Task KS2_NullDoubleSearch()
{
// On client 1
KitchenSinkDto client1dto = new() { NullableDouble = -1.0 };
await remoteTable.InsertItemAsync(client1dto);
var remoteId = client1dto.Id;
Assert.NotEmpty(remoteId);

// On client 2
await InitializeAsync();
var pullQuery = offlineTable!.CreateQuery();
await offlineTable!.PullItemsAsync(pullQuery, new PullOptions());
var client2dto = await offlineTable.GetItemAsync(remoteId);
Assert.NotNull(client2dto);
Assert.True(client2dto.NullableDouble < -0.5);

// Finally, let's search!
var elements = await offlineTable!.Where(x => x.NullableDouble < -0.5).ToListAsync();
Assert.Single(elements);
Assert.Equal(elements[0].Id, remoteId);
}

[Fact]
public async Task KS3_DeferredTableDefinition()
{
var filename = Path.GetTempFileName();
var connectionString = new UriBuilder(filename) { Query = "?mode=rwc" }.Uri.ToString();
Expand Down