public async Task QueryAsync_DoesNotReturnsSoftDeletedRows_IfIncludeDeletedIsFalse() { // Arrange List <Person> persons = TestData.Persons.Take(2).ToList(); persons[0].PartitionKey = persons[0].LastName; persons[0].RowKey = persons[0].FirstName; await this.manager.InsertAsync(persons[0]); persons[1].PartitionKey = persons[1].LastName; persons[1].RowKey = persons[1].FirstName; persons[1].Deleted = true; await this.manager.InsertAsync(persons[1]); this.manager.IncludeDeleted = false; // Act ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Person>("Persons"), typeof(Person)); ODataQueryOptions query = new ODataQueryOptions(context, this.request); IEnumerable <Person> actual = await this.manager.QueryAsync(query); // Assert Assert.Equal(1, actual.Count()); Assert.Equal(actual.First().Id, persons[0].Id); }
public async Task QueryAsync_WithPaging_ReturnsAllData() { // Arrange int pageSize = 5; int numPersons = (pageSize * 3) + 2; // 4 pages of data int numPages = (int)Math.Ceiling((double)numPersons / pageSize); Collection <Person> persons = TestData.CreatePersons(numPersons); await this.InsertPersons(persons); // Act ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Person>("Persons"), typeof(Person)); this.manager.QuerySettings.PageSize = pageSize; List <Person> allResults = new List <Person>(); string rootUri = "https://localhost/tables/persons"; Uri nextLinkUri = new Uri(rootUri); int actualPageCount = 0; do { // query for the next page and append the results HttpRequestMessage currRequest = new HttpRequestMessage(HttpMethod.Get, nextLinkUri); ODataQueryOptions query = new ODataQueryOptions(context, currRequest); this.manager.Request = currRequest; IEnumerable <Person> results = await this.manager.QueryAsync(query); allResults.AddRange(results); actualPageCount++; // follow the next link nextLinkUri = currRequest.ODataProperties().NextLink; if (nextLinkUri != null) { // ensure that the root path has been maintained Assert.True(nextLinkUri.ToString().StartsWith(rootUri)); } }while (nextLinkUri != null); // Assert Assert.Equal(numPages, actualPageCount); Assert.Equal(persons.Count, allResults.Count()); foreach (Person person in persons) { allResults.Single(i => i.FirstName == person.FirstName); } }
public async Task QueryAsync_ThrowsOnBadQuery() { // Arrange this.request.RequestUri = new Uri("http://localhost?$top=top"); // Act ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Person>("Persons"), typeof(Person)); ODataQueryOptions query = new ODataQueryOptions(context, this.request); HttpResponseException ex = await AssertEx.ThrowsAsync <HttpResponseException>(async() => await this.manager.QueryAsync(query)); HttpError error; ex.Response.TryGetContentValue(out error); Assert.Equal(HttpStatusCode.BadRequest, ex.Response.StatusCode); Assert.Equal("The query specified in the URI is not valid: 'Failed to convert 'top' to an integer.'.", error.Message); }
public async Task QueryAsync_Succeeds_WithDateTimeOffsetInFilter() { // Arrange this.request.RequestUri = new Uri("http://localhost/?$filter=createdAt gt datetimeoffset'2014-08-28T14:22:48.8650825-07:00'&$select=firstName"); Collection <Person> persons = TestData.Persons; await this.InsertPersons(persons); // Act ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Person>("Persons"), typeof(Person)); ODataQueryOptions query = new ODataQueryOptions(context, this.request); IEnumerable <Person> actual = await this.manager.QueryAsync(query); // Assert Assert.Equal(5, actual.Count()); }
public async Task QueryAsync_Succeeds_WithSystemPropertiesInFilter(string filter, int expectedCount) { // Arrange this.request.RequestUri = new Uri("http://localhost/?$filter=" + filter + "&$select=firstName"); Collection <Person> persons = TestData.Persons; await this.InsertPersons(persons); // Act ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Person>("Persons"), typeof(Person)); ODataQueryOptions query = new ODataQueryOptions(context, this.request); IEnumerable <Person> actual = await this.manager.QueryAsync(query); // Assert Assert.Equal(expectedCount, actual.Count()); }
public async Task QueryAsync_Succeeds_WithCamelCaseMembersInFilter() { // Arrange this.request.RequestUri = new Uri("http://localhost/?$filter=age eq 20&$select=firstName"); Collection <Person> persons = TestData.Persons; await this.InsertPersons(persons); // Act ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Person>("Persons"), typeof(Person)); ODataQueryOptions query = new ODataQueryOptions(context, this.request); IEnumerable <Person> actual = await this.manager.QueryAsync(query); // Assert Assert.Equal(1, actual.Count()); persons.Single(i => i.FirstName == actual.Single().FirstName); }
public void GetResultSize_ReturnsEffectivePageSize(string top, int?pageSize, int expected) { // Arrange ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Movie>("Movies"), typeof(Movie)); Uri address = new Uri("http://localhost?{0}".FormatInvariant(top)); ODataQueryOptions query = new ODataQueryOptions(context, new HttpRequestMessage { RequestUri = address }); ODataQuerySettings settings = new ODataQuerySettings() { PageSize = pageSize }; // Act int actual = TableUtils.GetResultSize(query, settings); // Assert Assert.Equal(expected, actual); }
public async Task QueryAsync_All_ReturnsData() { // Arrange Collection <Person> persons = TestData.Persons; await this.InsertPersons(persons); // Act ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Person>("Persons"), typeof(Person)); ODataQueryOptions query = new ODataQueryOptions(context, this.request); IEnumerable <Person> actual = await this.manager.QueryAsync(query); // Assert Assert.Equal(persons.Count, actual.Count()); foreach (Person person in persons) { actual.Single(i => i.FirstName == person.FirstName); } }
public async Task QueryAsync_Filter_ReturnsData() { // Arrange this.request.RequestUri = new Uri("http://localhost/?$filter=Age eq 20"); Collection <Person> persons = TestData.Persons; await this.InsertPersons(persons); // Act ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Person>("Persons"), typeof(Person)); ODataQueryOptions query = new ODataQueryOptions(context, this.request); IEnumerable <Person> actual = await this.manager.QueryAsync(query); // Assert Assert.Equal(1, actual.Count()); foreach (Person a in actual) { persons.Single(i => i.FirstName == a.FirstName); } }
public async Task QueryAsync_CreatesStorageTable() { var isolatedManager = new StorageDomainManagerMock(this, "queryTableNotFound"); try { await isolatedManager.Table.DeleteIfExistsAsync(); Assert.False(isolatedManager.Table.Exists()); ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Person>("Persons"), typeof(Person)); ODataQueryOptions query = new ODataQueryOptions(context, this.request); IEnumerable <Person> actual = await isolatedManager.QueryAsync(query); Assert.Equal(0, actual.Count()); Assert.True(isolatedManager.Table.Exists()); } finally { isolatedManager.Dispose(); } }