Skip to content

Commit

Permalink
Added tests to Odata filter generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hovsep Mkrtchyan committed Apr 23, 2016
1 parent f76e16f commit 72ba2d6
Showing 1 changed file with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Rest.Azure.OData;
using Newtonsoft.Json;
using Xunit;
using System.Collections.Generic;

namespace Microsoft.Rest.ClientRuntime.Azure.Test
{
Expand Down Expand Up @@ -248,14 +249,43 @@ public void ODataQuerySupportsEmptyState()
{
Value = null
};
var paramEncoded = new InputParam1
{
Value = "bar/car"
};
query = new ODataQuery<Param1>(p => p.Foo == param.Value);
Assert.Equal("", query.ToString());
query = new ODataQuery<Param1>(p => p.Foo == param.Value && p.AssignedTo(param.Value));
Assert.Equal("", query.ToString());
query = new ODataQuery<Param1>(p => p.AssignedTo(param.Value));
Assert.Equal("", query.ToString());
query = new ODataQuery<Param1>(p => p.AssignedTo(paramEncoded.Value));
Assert.Equal("$filter=assignedTo('bar%2Fcar')", query.ToString());
}

[Fact]
public void ODataQuerySupportsCustomDateTimeOffsetFilter()
{
var param = new Param1
{
SubmitTime = DateTimeOffset.Parse("2016-03-28T08:15:00.0971693+00:00"),
State = "Ended"

};

var filter = new List<string>();
filter.Add(string.Format("submitTime lt datetimeoffset'{0}'", Uri.EscapeDataString(param.SubmitTime.Value.ToString("O"))));
var filterString = string.Join(" and ", filter.ToArray());


var query = new ODataQuery<Param1>
{
Filter = filterString
};
Assert.Equal("$filter=submitTime lt datetimeoffset'2016-03-28T08%3A15%3A00.0971693%2B00%3A00'' and state ne 'Ended'", query.ToString());
}


[Fact]
public void ODataQuerySupportsPartialState()
{
Expand All @@ -266,6 +296,17 @@ public void ODataQuerySupportsPartialState()
Assert.Equal("$filter=foo eq 'bar'&$top=100", query.ToString());
}

[Fact]
public void ODataQuerySupportsPartialStateWithSlashes()
{
var queryString = "$filter=foo eq 'bar%2Fclub'&$top=100";
var query = new ODataQuery<Param1>(p => p.Foo == "bar/club")
{
Top = 100
};
Assert.Equal(queryString, query.ToString());
}

[Fact]
public void ODataQuerySupportsImplicitConversionFromFilterString()
{
Expand Down Expand Up @@ -318,7 +359,7 @@ public void ODataQuerySupportsMethod()
var filterString = FilterString.Generate<Param1>(parameters => parameters.AtScope() &&
parameters.AssignedTo(param.Value));

Assert.Equal(filterString, "atScope() and assignedTo('Microsoft.Web%2Fsites')");
Assert.Equal("atScope() and assignedTo('Microsoft.Web%2Fsites')", filterString);
}
}

Expand Down Expand Up @@ -356,6 +397,10 @@ public class Param1
[JsonProperty("d")]
public DateTime Date { get; set; }
public DateTime Date2 { get; set; }
[JsonProperty("submitTime")]
public DateTimeOffset? SubmitTime { get; set; }
[JsonProperty("state")]
public string State { get; set; }
[JsonProperty("vals")]
public string[] Values { get; set; }
[JsonProperty("param2")]
Expand Down

0 comments on commit 72ba2d6

Please sign in to comment.