Skip to content

Commit

Permalink
Fixing build error for test unit
Browse files Browse the repository at this point in the history
  • Loading branch information
JBrenesSimpat committed Jan 26, 2024
1 parent f279490 commit 953f189
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFrameworkTesting.FakeItEasy" Version="1.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="FakeItEasy" Version="8.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
Expand Down
33 changes: 19 additions & 14 deletions tests/EdFi.Security.DataAccess.UnitTests/StubSecurityContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// See the LICENSE and NOTICES files in the project root for more information.

using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using EdFi.Security.DataAccess.Contexts;
using EdFi.Security.DataAccess.Models;
using FakeItEasy;
using Microsoft.EntityFrameworkCore;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace EdFi.Security.DataAccess.UnitTests
{
Expand All @@ -23,22 +23,27 @@ public static ISecurityContext GetMockedSecurityContext()
{
var securityContext = A.Fake<ISecurityContext>();
// The underlying SecurityRepository implementation expects this application, so force it to be there in the fake
securityContext.Applications = GetFakeDbSet<Application>().SetupData(new List<Application> { new Application { ApplicationId = 1, ApplicationName = "Ed-Fi ODS API" } });
securityContext.Actions = GetFakeDbSet<Action>().SetupData();
securityContext.AuthorizationStrategies = GetFakeDbSet<AuthorizationStrategy>().SetupData();
securityContext.ClaimSets = GetFakeDbSet<ClaimSet>().SetupData();
securityContext.ClaimSetResourceClaimActions = GetFakeDbSet<ClaimSetResourceClaimAction>().SetupData();
securityContext.ResourceClaims = GetFakeDbSet<ResourceClaim>().SetupData();
securityContext.ResourceClaimActions = GetFakeDbSet<ResourceClaimAction>().SetupData();
securityContext.ClaimSetResourceClaimActionAuthorizationStrategyOverrides = GetFakeDbSet<ClaimSetResourceClaimActionAuthorizationStrategyOverrides>().SetupData();
securityContext.ResourceClaimActionAuthorizationStrategies = GetFakeDbSet<ResourceClaimActionAuthorizationStrategies>().SetupData();

securityContext.Applications = GetFakeDbSet<Application>();
securityContext.Actions = GetFakeDbSet<Action>();
securityContext.AuthorizationStrategies = GetFakeDbSet<AuthorizationStrategy>();
securityContext.ClaimSets = GetFakeDbSet<ClaimSet>();
securityContext.ClaimSetResourceClaimActions = GetFakeDbSet<ClaimSetResourceClaimAction>();
securityContext.ResourceClaims = GetFakeDbSet<ResourceClaim>();
securityContext.ResourceClaimActions = GetFakeDbSet<ResourceClaimAction>();
securityContext.ClaimSetResourceClaimActionAuthorizationStrategyOverrides = GetFakeDbSet<ClaimSetResourceClaimActionAuthorizationStrategyOverrides>();
securityContext.ResourceClaimActionAuthorizationStrategies = GetFakeDbSet<ResourceClaimActionAuthorizationStrategies>();

return securityContext;

}


private static DbSet<T> GetFakeDbSet<T>() where T : class
{
return A.Fake<DbSet<T>>(o => o.Implements(typeof(IQueryable<T>)).Implements(typeof(IDbAsyncEnumerable<T>)));
}
var fake = A.Fake<DbSet<T>>(o => o.Implements(typeof(IQueryable<T>)).Implements(typeof(IAsyncEnumerable<T>)));

return fake;
}
}
}
}

0 comments on commit 953f189

Please sign in to comment.