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

Added tests to Odata filter generation #974

Merged
merged 2 commits into from
Apr 23, 2016
Merged
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 @@ -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,44 @@ 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"))));
filter.Add(string.Format("state ne '{0}'", param.State));
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 +297,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 +360,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 +398,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