-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ODS-6251] Changes required in Security.DataAccess: EFC / Microsoft.D…
…ata.SqlClient (#964)
- Loading branch information
1 parent
54c8558
commit 9acb49b
Showing
18 changed files
with
779 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
...Fi.Security.DataAccess.IntegrationTests/Contexts/PostgreSQLSecurityContextFactoryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// 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 EdFi.Security.DataAccess.Contexts; | ||
using EdFi.Security.DataAccess.Models; | ||
using Microsoft.Extensions.Configuration; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using System; | ||
using System.Linq; | ||
using System.Transactions; | ||
using EdFi.TestFixture; | ||
using Microsoft.EntityFrameworkCore; | ||
using Action = EdFi.Security.DataAccess.Models.Action; | ||
|
||
namespace EdFi.Security.DataAccess.IntegrationTests.Contexts | ||
{ | ||
|
||
[TestFixture] | ||
public class PostgreSQLSecurityContextFactoryTests | ||
{ | ||
private PostgresSecurityContext _context; | ||
private TransactionScope _transaction; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); | ||
|
||
var builder = new ConfigurationBuilder() | ||
.AddJsonFile($"appSettings.json", true, true) | ||
.AddJsonFile($"appSettings.development.json", true, true); | ||
|
||
var config = builder.Build(); | ||
var connectionString = config.GetConnectionString("PostgreSQL"); | ||
|
||
var optionsBuilder = new DbContextOptionsBuilder(); | ||
optionsBuilder.UseNpgsql(connectionString); | ||
optionsBuilder.UseLowerCaseNamingConvention(); | ||
_context = new PostgresSecurityContext(optionsBuilder.Options); | ||
|
||
_transaction = new TransactionScope(); | ||
} | ||
|
||
[TearDown] | ||
public void Teardown() | ||
{ | ||
_transaction.Dispose(); | ||
} | ||
|
||
[Test] | ||
public void Given_configured_for_Postgres_then_create_PostgresSecurityContext_make_a_change_and_save_it() | ||
{ | ||
|
||
var testAction = new Action() | ||
{ | ||
ActionName = "Test", | ||
ActionUri = "http://ed-fi.org/odsapi/actions/Test" | ||
}; | ||
|
||
int originalCount = _context.Actions.Count(); | ||
_context.Actions.Add(testAction); | ||
_context.SaveChanges(); | ||
_context.Actions.Count().ShouldBe(originalCount + 1); | ||
_context.Actions.Remove(testAction); | ||
_context.SaveChanges(); | ||
_context.Actions.Count().ShouldBe(originalCount); | ||
} | ||
|
||
[TestFixture] | ||
public class When_creating_an_application : PostgreSQLSecurityContextFactoryTests | ||
{ | ||
[Test] | ||
public void Should_persist_the_user_to_the_database() | ||
{ | ||
string applicationName = "Test Application"; | ||
|
||
//Arrange | ||
var application = new Application() { ApplicationName = applicationName }; | ||
|
||
//Act | ||
_context.Applications.Add(application); | ||
_context.SaveChangesForTest(); | ||
|
||
//Assert | ||
_context.Applications.Count(x => x.ApplicationName == applicationName) | ||
.ShouldBe(1); | ||
} | ||
} | ||
|
||
[TestFixture] | ||
public class When_creating_a_claimset : PostgreSQLSecurityContextFactoryTests | ||
{ | ||
private string appName = string.Format("{0}_TestData", DateTime.Now.Ticks); | ||
private const string claimSetName = "ClaimSet"; | ||
private Application applicationTest; | ||
|
||
[Test] | ||
public void Should_create_claimSet() | ||
{ | ||
applicationTest = new Application() { ApplicationName = appName }; | ||
|
||
_context.Applications.Add(applicationTest); | ||
_context.SaveChangesForTest(); | ||
|
||
var testApplication = _context.Applications.Where(v => v.ApplicationName == appName).FirstOrDefault(); | ||
|
||
var testClaimSet = new ClaimSet() | ||
{ | ||
ClaimSetName = claimSetName, | ||
Application = testApplication, | ||
IsEdfiPreset = false, | ||
ForApplicationUseOnly = true | ||
}; | ||
|
||
//Arrange | ||
_context.ClaimSets.Add(testClaimSet); | ||
_context.SaveChangesForTest(); | ||
|
||
//Act | ||
var claimSetFromDb = _context.ClaimSets.Where(v => v.ClaimSetName == claimSetName).Single(); | ||
|
||
//Assert | ||
claimSetFromDb.ShouldNotBeNull(); | ||
} | ||
|
||
[Test] | ||
public void Should_create_resourceClaim() | ||
{ | ||
applicationTest = new Application() { ApplicationName = appName }; | ||
|
||
_context.Applications.Add(applicationTest); | ||
_context.SaveChangesForTest(); | ||
|
||
var testApplication = _context.Applications.Where(v => v.ApplicationName == appName).FirstOrDefault(); | ||
|
||
string displayName = "ResourceClaimDisplayNameTest"; | ||
|
||
var testResourceClaim = new ResourceClaim() | ||
{ | ||
DisplayName = displayName, | ||
ResourceName = displayName, | ||
ClaimName = "http://ed-fi.org/ods/identity/claims/domains/" + displayName, | ||
Application = testApplication | ||
}; | ||
|
||
//Arrange | ||
_context.ResourceClaims.Add(testResourceClaim); | ||
_context.SaveChangesForTest(); | ||
|
||
//Act | ||
var resourceClaimSetFromDb = _context.ResourceClaims.Where(v => v.DisplayName == displayName).Single(); | ||
|
||
//Assert | ||
resourceClaimSetFromDb.ShouldNotBeNull(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.