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

[ADMINAPI-1038] Make offset and limit collections optional and set to their defaults when not provided #141

Merged
merged 4 commits into from
Aug 13, 2024
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 @@ -77,7 +77,7 @@ public void ShouldUpdateResourcesOnClaimSet()
using var context = CreateDbContext();
var addOrEditResourcesOnClaimSetCommand = new AddOrEditResourcesOnClaimSetCommand(
new EditResourceOnClaimSetCommand(context),
new GetResourceClaimsQuery(context),
new GetResourceClaimsQuery(context, Testing.GetAppSettings()),
new OverrideDefaultAuthorizationStrategyCommand(context));

var command = new UpdateResourcesOnClaimSetCommand(context, addOrEditResourcesOnClaimSetCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace EdFi.Ods.AdminApi.DBTests.Database.CommandTests;
[TestFixture]
public class AddApplicationCommandTests : PlatformUsersContextTestBase
{
private IOptions<AppSettings> _options { get; set; }
private IOptions<AppSettings> _options { get; set; }

[OneTimeSetUp]
public virtual async Task FixtureSetup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System.Linq;
using EdFi.Ods.AdminApi.Infrastructure;
using EdFi.Ods.AdminApi.Infrastructure.Database.Queries;
using NUnit.Framework;
using Shouldly;
using System.Linq;

namespace EdFi.Ods.AdminApi.DBTests.Database.QueryTests;

Expand All @@ -17,9 +18,8 @@ public class GetAllActionsQueryTests : SecurityDataTestBase
public void ShouldGetAllActions()
{
LoadSeedData();

using var securityContext = TestContext;
var query = new GetAllActionsQuery(securityContext);
var query = new GetAllActionsQuery(securityContext, Testing.GetAppSettings());
var resultNames = query.Execute().Select(x => x.ActionName).ToList();

resultNames.Count.ShouldBe(4);
Expand All @@ -36,8 +36,10 @@ public void ShouldGetAllActions_With_Offset_and_Limit()
var limit = 2;

using var securityContext = TestContext;
var query = new GetAllActionsQuery(securityContext);
var resultNames = query.Execute(offset, limit, null, null).Select(x => x.ActionName).ToList();
var query = new GetAllActionsQuery(securityContext, Testing.GetAppSettings());
var resultNames = query.Execute(
new CommonQueryParams(offset, limit, null, null),
null, null).Select(x => x.ActionName).ToList();

resultNames.Count.ShouldBe(2);

Expand All @@ -49,13 +51,12 @@ public void ShouldGetAllActions_With_Offset_and_Limit()
public void ShouldGetAllActions_With_Name()
{
LoadSeedData();
var offset = 0;
var limit = 25;
var name = "Delete";

using var securityContext = TestContext;
var query = new GetAllActionsQuery(securityContext);
var resultNames = query.Execute(offset, limit, null, name).Select(x => x.ActionName).ToList();
var query = new GetAllActionsQuery(securityContext, Testing.GetAppSettings());
var resultNames = query.Execute(
new CommonQueryParams(),
null, name).Select(x => x.ActionName).ToList();

resultNames.Count.ShouldBe(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.Linq;
using EdFi.Ods.AdminApi.Infrastructure;
using EdFi.Ods.AdminApi.Infrastructure.Database.Queries;
using EdFi.Security.DataAccess.Models;
using NUnit.Framework;
Expand All @@ -29,7 +30,7 @@ public void Should_Retreive_ClaimSetNames()

var claimSetNames = Transaction<string[]>(securityContext =>
{
var query = new GetAllClaimSetsQuery(securityContext);
var query = new GetAllClaimSetsQuery(securityContext, Testing.GetAppSettings());
return query.Execute().Select(x => x.Name).ToArray();
});

Expand All @@ -44,13 +45,13 @@ public void Should_Retreive_ClaimSetNames_With_Offset_And_Limit()
var claimSet2 = GetClaimSet();
Save(claimSet1, claimSet2);

var offset = 0;
var limit = 2;

var claimSetNames = Transaction<string[]>(securityContext =>
{
var query = new GetAllClaimSetsQuery(securityContext);
return query.Execute(offset, limit, null, null).Select(x => x.Name).ToArray();
var query = new GetAllClaimSetsQuery(securityContext, Testing.GetAppSettings());
return query.Execute(
new CommonQueryParams(),
null,
null).Select(x => x.Name).ToArray();
});

claimSetNames.ShouldContain(claimSet1.ClaimSetName);
Expand All @@ -64,13 +65,12 @@ public void Should_Retreive_ClaimSetNames_With_Id()
var claimSet2 = GetClaimSet();
Save(claimSet1, claimSet2);

var offset = 0;
var limit = 2;

var claimSetNames = Transaction<string[]>(securityContext =>
{
var query = new GetAllClaimSetsQuery(securityContext);
return query.Execute(offset, limit, claimSet2.ClaimSetId, null).Select(x => x.Name).ToArray();
var query = new GetAllClaimSetsQuery(securityContext, Testing.GetAppSettings());
return query.Execute(new CommonQueryParams(),
claimSet2.ClaimSetId,
null).Select(x => x.Name).ToArray();
});

claimSetNames.Length.ShouldBe(1);
Expand All @@ -84,13 +84,12 @@ public void Should_Retreive_ClaimSetNames_With_Name()
var claimSet2 = GetClaimSet();
Save(claimSet1, claimSet2);

var offset = 0;
var limit = 2;

var claimSetNames = Transaction<string[]>(securityContext =>
{
var query = new GetAllClaimSetsQuery(securityContext);
return query.Execute(offset, limit, null, claimSet2.ClaimSetName).Select(x => x.Name).ToArray();
var query = new GetAllClaimSetsQuery(securityContext, Testing.GetAppSettings());
return query.Execute(new CommonQueryParams(),
null,
claimSet2.ClaimSetName).Select(x => x.Name).ToArray();
});

claimSetNames.Length.ShouldBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System.Linq;
using EdFi.Ods.AdminApi.Infrastructure;
using EdFi.Ods.AdminApi.Infrastructure.Database.Queries;
using EdFi.Security.DataAccess.Contexts;
using EdFi.Security.DataAccess.Models;
using NUnit.Framework;
using Shouldly;
using System.Linq;

namespace EdFi.Ods.AdminApi.DBTests.Database.QueryTests;

Expand All @@ -35,7 +36,7 @@ public void Should_Retrieve_AuthStrategies()

Transaction(securityContext =>
{
var command = new GetAuthStrategiesQuery(securityContext);
var command = new GetAuthStrategiesQuery(securityContext, Testing.GetAppSettings());
var allAuthStrategies = command.Execute();

allAuthStrategies.ShouldNotBeEmpty();
Expand Down Expand Up @@ -64,12 +65,12 @@ public void Should_Retrieve_AuthStrategies_With_Offset_And_Limit()

Transaction(securityContext =>
{
var command = new GetAuthStrategiesQuery(securityContext);
var command = new GetAuthStrategiesQuery(securityContext, Testing.GetAppSettings());

var offset = 0;
var limit = 2;

var authStrategiesAfterOffset = command.Execute(offset, limit);
var authStrategiesAfterOffset = command.Execute(new CommonQueryParams(offset, limit, null, null));

authStrategiesAfterOffset.ShouldNotBeEmpty();
authStrategiesAfterOffset.Count.ShouldBe(2);
Expand All @@ -79,7 +80,7 @@ public void Should_Retrieve_AuthStrategies_With_Offset_And_Limit()

offset = 2;

authStrategiesAfterOffset = command.Execute(offset, limit);
authStrategiesAfterOffset = command.Execute(new CommonQueryParams(offset, limit, null, null));

authStrategiesAfterOffset.ShouldNotBeEmpty();
authStrategiesAfterOffset.Count.ShouldBe(2);
Expand All @@ -88,7 +89,7 @@ public void Should_Retrieve_AuthStrategies_With_Offset_And_Limit()
authStrategiesAfterOffset.ShouldContain(v => v.AuthorizationStrategyName == "Test Auth S 4");
offset = 4;

authStrategiesAfterOffset = command.Execute(offset, limit);
authStrategiesAfterOffset = command.Execute(new CommonQueryParams(offset, limit, null, null));

authStrategiesAfterOffset.ShouldNotBeEmpty();
authStrategiesAfterOffset.Count.ShouldBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System.Collections.Generic;
using System.Linq;
using EdFi.Admin.DataAccess.Models;
using EdFi.Ods.AdminApi.Infrastructure;
using EdFi.Ods.AdminApi.Infrastructure.Database.Queries;
using NUnit.Framework;
using Shouldly;
using System.Collections.Generic;
using System.Linq;

namespace EdFi.Ods.AdminApi.DBTests.Database.QueryTests;

Expand Down Expand Up @@ -37,7 +38,7 @@ public void Should_Retreive_OdsInstancesContext()
List<OdsInstanceContext> results = null;
Transaction(usersContext =>
{
var query = new GetOdsInstanceContextsQuery(usersContext);
var query = new GetOdsInstanceContextsQuery(usersContext, Testing.GetAppSettings());
results = query.Execute();
});

Expand Down Expand Up @@ -76,8 +77,8 @@ public void Should_Retreive_OdsInstancesContext_With_Offset_Limit()
List<OdsInstanceContext> results = null;
Transaction(usersContext =>
{
var query = new GetOdsInstanceContextsQuery(usersContext);
results = query.Execute(1, 1);
var query = new GetOdsInstanceContextsQuery(usersContext, Testing.GetAppSettings());
results = query.Execute(new CommonQueryParams(1, 1));
results.Count.ShouldBe(1);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System.Collections.Generic;
using System.Linq;
using EdFi.Admin.DataAccess.Models;
using EdFi.Ods.AdminApi.Infrastructure;
using EdFi.Ods.AdminApi.Infrastructure.Database.Queries;
using NUnit.Framework;
using Shouldly;
using System.Collections.Generic;
using System.Linq;

namespace EdFi.Ods.AdminApi.DBTests.Database.QueryTests;

Expand Down Expand Up @@ -37,7 +38,7 @@ public void Should_Retreive_OdsInstancesDerivative()
List<OdsInstanceDerivative> results = null;
Transaction(usersContext =>
{
var query = new GetOdsInstanceDerivativesQuery(usersContext);
var query = new GetOdsInstanceDerivativesQuery(usersContext, Testing.GetAppSettings());
results = query.Execute();
});

Expand Down Expand Up @@ -76,8 +77,8 @@ public void Should_Retreive_OdsInstancesDerivative_With_Offset_Limit()
List<OdsInstanceDerivative> results = null;
Transaction(usersContext =>
{
var query = new GetOdsInstanceDerivativesQuery(usersContext);
results = query.Execute(1, 1);
var query = new GetOdsInstanceDerivativesQuery(usersContext, Testing.GetAppSettings());
results = query.Execute(new CommonQueryParams(1, 1));
results.Count.ShouldBe(1);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// See the LICENSE and NOTICES files in the project root for more information.

using EdFi.Admin.DataAccess.Models;
using EdFi.Ods.AdminApi.Infrastructure;
using EdFi.Ods.AdminApi.Infrastructure.Database.Queries;
using NUnit.Framework;
using Shouldly;
Expand All @@ -19,7 +20,7 @@ public void ShouldGetAllInstances()
Transaction(usersContext =>
{
CreateMultiple(2);
var command = new GetOdsInstancesQuery(usersContext);
var command = new GetOdsInstancesQuery(usersContext, Testing.GetAppSettings());
var results = command.Execute();
results.Count.ShouldBe(2);
});
Expand All @@ -34,8 +35,8 @@ public void ShouldGetAllInstancesWithOffsetAndLimit()
var offset = 0;
var limit = 2;

var command = new GetOdsInstancesQuery(usersContext);
var odsInstancesAfterOffset = command.Execute(offset, limit, null, null);
var command = new GetOdsInstancesQuery(usersContext, Testing.GetAppSettings());
var odsInstancesAfterOffset = command.Execute(new CommonQueryParams(offset, limit), null, null);

odsInstancesAfterOffset.ShouldNotBeEmpty();
odsInstancesAfterOffset.Count.ShouldBe(2);
Expand All @@ -45,7 +46,7 @@ public void ShouldGetAllInstancesWithOffsetAndLimit()

offset = 2;

odsInstancesAfterOffset = command.Execute(offset, limit, null, null);
odsInstancesAfterOffset = command.Execute(new CommonQueryParams(offset, limit), null, null);

odsInstancesAfterOffset.ShouldNotBeEmpty();
odsInstancesAfterOffset.Count.ShouldBe(2);
Expand All @@ -54,7 +55,7 @@ public void ShouldGetAllInstancesWithOffsetAndLimit()

offset = 4;

odsInstancesAfterOffset = command.Execute(offset, limit, null, null);
odsInstancesAfterOffset = command.Execute(new CommonQueryParams(offset, limit), null, null);

odsInstancesAfterOffset.ShouldNotBeEmpty();
odsInstancesAfterOffset.Count.ShouldBe(1);
Expand All @@ -68,8 +69,8 @@ public void ShouldGetAllInstancesWithId()
Transaction(usersContext =>
{
var odsInstances = CreateMultiple();
var command = new GetOdsInstancesQuery(usersContext);
var odsInstancesAfterOffset = command.Execute(0, 25, odsInstances[2].OdsInstanceId, null);
var command = new GetOdsInstancesQuery(usersContext, Testing.GetAppSettings());
var odsInstancesAfterOffset = command.Execute(new CommonQueryParams(), odsInstances[2].OdsInstanceId, null);

odsInstancesAfterOffset.ShouldNotBeEmpty();
odsInstancesAfterOffset.Count.ShouldBe(1);
Expand All @@ -84,8 +85,8 @@ public void ShouldGetAllInstancesWithName()
Transaction(usersContext =>
{
var odsInstances = CreateMultiple();
var command = new GetOdsInstancesQuery(usersContext);
var odsInstancesAfterOffset = command.Execute(0, 25, null, odsInstances[2].Name);
var command = new GetOdsInstancesQuery(usersContext, Testing.GetAppSettings());
var odsInstancesAfterOffset = command.Execute(new CommonQueryParams(), null, odsInstances[2].Name);

odsInstancesAfterOffset.ShouldNotBeEmpty();
odsInstancesAfterOffset.Count.ShouldBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using EdFi.Admin.DataAccess.Models;
using EdFi.Ods.AdminApi.Infrastructure;
using EdFi.Ods.AdminApi.Infrastructure.Database.Queries;
using NUnit.Framework;
using Shouldly;
Expand All @@ -27,7 +28,7 @@ public void Should_retreive_profiles()
List<Profile> results = null;
Transaction(usersContext =>
{
var query = new GetProfilesQuery(usersContext);
var query = new GetProfilesQuery(usersContext, Testing.GetAppSettings());
results = query.Execute();
});

Expand Down Expand Up @@ -56,8 +57,8 @@ public void Should_retreive_profiles_with_offset_limit()
List<Profile> results = null;
Transaction(usersContext =>
{
var query = new GetProfilesQuery(usersContext);
results = query.Execute(1,1, null, null);
var query = new GetProfilesQuery(usersContext, Testing.GetAppSettings());
results = query.Execute(new CommonQueryParams(1, 1), null, null);
results.Count.ShouldBe(1);
});
results.Any(p => p.ProfileName == profile2.ProfileName).ShouldBeTrue();
Expand All @@ -74,8 +75,8 @@ public void Should_retreive_profiles_with_id()
List<Profile> results = null;
Transaction(usersContext =>
{
var query = new GetProfilesQuery(usersContext);
results = query.Execute(0, 5, profile2.ProfileId, null);
var query = new GetProfilesQuery(usersContext, Testing.GetAppSettings());
results = query.Execute(new CommonQueryParams(0, 5), profile2.ProfileId, null);
results.Count.ShouldBe(1);
});
results.Any(p => p.ProfileName == profile2.ProfileName).ShouldBeTrue();
Expand All @@ -92,8 +93,8 @@ public void Should_retreive_profiles_with_name()
List<Profile> results = null;
Transaction(usersContext =>
{
var query = new GetProfilesQuery(usersContext);
results = query.Execute(0, 5, null, profile2.ProfileName);
var query = new GetProfilesQuery(usersContext, Testing.GetAppSettings());
results = query.Execute(new CommonQueryParams(0, 5), null, profile2.ProfileName);
results.Count.ShouldBe(1);
});
results.Any(p => p.ProfileName == profile2.ProfileName).ShouldBeTrue();
Expand Down
Loading
Loading