Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.
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 @@ -5,8 +5,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EdFi.Admin.DataAccess.Models;
using EdFi.Ods.AdminApi.Common.Settings;
Expand All @@ -23,17 +21,19 @@ internal class AddApiClientCommandTests : PlatformUsersContextTestBase
private int applicationId { get; set; }

[SetUp]
public virtual async Task SetUp()
public new virtual async Task SetUp()
{
AppSettings appSettings = new AppSettings();
appSettings.PreventDuplicateApplications = false;
AppSettings appSettings = new()
{
PreventDuplicateApplications = false
};
_options = Options.Create(appSettings);
await Task.Yield();

var vendor = new Vendor
{
VendorId = 0,
VendorNamespacePrefixes = new List<VendorNamespacePrefix> { new VendorNamespacePrefix { NamespacePrefix = "http://tests.com" } },
VendorNamespacePrefixes = [new() { NamespacePrefix = "http://tests.com" }],
VendorName = "Integration Tests"
};

Expand Down Expand Up @@ -62,7 +62,7 @@ public void ShouldFailForInvalidApplication()
Name = "Test ApiClient",
ApplicationId = 0,
IsApproved = true,
OdsInstanceIds = new List<int> { 1, 2 }
OdsInstanceIds = [1, 2]
};

Assert.Throws<InvalidOperationException>(() => command.Execute(newApiClient, _options));
Expand All @@ -75,7 +75,7 @@ public void ShouldCreateApiClientWithOdsInstances()
var vendor = new Vendor
{
VendorId = 0,
VendorNamespacePrefixes = new List<VendorNamespacePrefix> { new VendorNamespacePrefix { NamespacePrefix = "http://tests.com" } },
VendorNamespacePrefixes = [new() { NamespacePrefix = "http://tests.com" }],
VendorName = "Integration Tests"
};

Expand All @@ -98,7 +98,7 @@ public void ShouldCreateApiClientWithOdsInstances()
Name = "Test ApiClient",
ApplicationId = application.ApplicationId,
IsApproved = true,
OdsInstanceIds = new List<int> { 1, 2 }
OdsInstanceIds = [1, 2]
};

command.Execute(newApiClient, _options);
Expand All @@ -111,7 +111,7 @@ public void ShouldCreateApiClientWithOutOdsInstances()
var vendor = new Vendor
{
VendorId = 0,
VendorNamespacePrefixes = new List<VendorNamespacePrefix> { new VendorNamespacePrefix { NamespacePrefix = "http://tests.com" } },
VendorNamespacePrefixes = [new() { NamespacePrefix = "http://tests.com" }],
VendorName = "Integration Tests"
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
using EdFi.Ods.AdminApi.Common.Infrastructure;
using EdFi.Ods.AdminApi.Common.Settings;
using EdFi.Ods.AdminApi.Infrastructure.Database.Commands;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using NUnit.Framework;
using Shouldly;
using Profile = EdFi.Admin.DataAccess.Models.Profile;
using VendorUser = EdFi.Admin.DataAccess.Models.User;

namespace EdFi.Ods.AdminApi.DBTests.Database.CommandTests;
Expand All @@ -33,10 +31,12 @@ internal class EditApiClientCommandTests : PlatformUsersContextTestBase
private IOptions<AppSettings> _options { get; set; }

[SetUp]
public virtual async Task SetUp()
public new virtual async Task SetUp()
{
AppSettings appSettings = new AppSettings();
appSettings.PreventDuplicateApplications = false;
AppSettings appSettings = new()
{
PreventDuplicateApplications = false
};
_options = Options.Create(appSettings);
await Task.Yield();
}
Expand All @@ -52,7 +52,7 @@ private void SetupTestEntities()

_vendor = new Vendor
{
VendorNamespacePrefixes = new List<VendorNamespacePrefix> { new VendorNamespacePrefix { NamespacePrefix = "http://tests.com" } },
VendorNamespacePrefixes = [new() { NamespacePrefix = "http://tests.com" }],
VendorName = "Integration Tests"
};

Expand Down Expand Up @@ -190,7 +190,7 @@ public void ShouldAddOdsInstancesIfNew()
ApplicationId = _application.ApplicationId,
Name = _apiClient.Name,
IsApproved = true,
OdsInstanceIds = new List<int> { _odsInstance.OdsInstanceId, _newOdsInstance.OdsInstanceId }
OdsInstanceIds = [_odsInstance.OdsInstanceId, _newOdsInstance.OdsInstanceId]
};

Transaction(usersContext =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ public class UsersContextFactory : IUsersContextFactory
public UsersContextFactory(IAdminDatabaseConnectionStringProvider connectionStringsProvider, DatabaseEngine databaseEngine)
{
_connectionStringsProvider = Preconditions.ThrowIfNull(connectionStringsProvider, nameof(connectionStringsProvider));
_databaseEngine = Preconditions.ThrowIfNull(databaseEngine, nameof(databaseEngine));
_databaseEngine = Preconditions.ThrowIfNull(databaseEngine, nameof(databaseEngine));
}

public Type GetUsersContextType()
{
if (_usersContextTypeByDatabaseEngine.TryGetValue(_databaseEngine, out Type contextType))
if (_usersContextTypeByDatabaseEngine.TryGetValue(_databaseEngine, out Type? contextType) && contextType != null)
{
return contextType;
}
Expand All @@ -44,23 +45,23 @@ public IUsersContext CreateContext()
if (_databaseEngine == DatabaseEngine.SqlServer)
{
return Activator.CreateInstance(
GetUsersContextType(),
new DbContextOptionsBuilder<SqlServerUsersContext>()
.UseLazyLoadingProxies()
.UseSqlServer(_connectionStringsProvider.GetConnectionString())
.Options) as
IUsersContext;
GetUsersContextType(),
new DbContextOptionsBuilder<SqlServerUsersContext>()
.UseLazyLoadingProxies()
.UseSqlServer(_connectionStringsProvider.GetConnectionString())
.Options) as
IUsersContext ?? throw new InvalidOperationException("Failed to create SqlServerUsersContext instance.");
}

if (_databaseEngine == DatabaseEngine.Postgres)
{
return Activator.CreateInstance(
GetUsersContextType(),
new DbContextOptionsBuilder<PostgresUsersContext>()
.UseLazyLoadingProxies()
.UseNpgsql(_connectionStringsProvider.GetConnectionString())
.Options) as
IUsersContext;
GetUsersContextType(),
new DbContextOptionsBuilder<PostgresUsersContext>()
.UseLazyLoadingProxies()
.UseNpgsql(_connectionStringsProvider.GetConnectionString())
.Options) as
IUsersContext ?? throw new InvalidOperationException("Failed to create PostgresUsersContext instance.");
}

throw new InvalidOperationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// 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.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

Expand All @@ -14,35 +12,30 @@ public class User
{
public User()
{
ApiClients = new Collection<ApiClient>();
ApiClients = [];
}

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }

public string Email { get; set; }
public required string Email { get; set; }

public string FullName { get; set; }
public required string FullName { get; set; }

public virtual Vendor Vendor { get; set; }
public required Vendor Vendor { get; set; }

public virtual ICollection<ApiClient> ApiClients { get; set; }

/// <summary>
/// Create a new sandbox client
/// </summary>
/// <param name="name">The visible name of the sandbox</param>
/// <param name="sandboxType">Empty, Minimal, Populated</param>
/// <param name="key">optional parameter, value is created randomly if it is null or empty. Both Key and Secret are required if providing either.</param>
/// <param name="secret">optional parameter, value is created randomly if it is null or empty. Both Key and Secret are required if providing either.</param>
/// <returns>ApiClient information about the created sandbox</returns>
public ApiClient AddSandboxClient(string name, SandboxType sandboxType, string key, string secret)
{
var client = new ApiClient(true)
{
Name = name, IsApproved = true, UseSandbox = true, SandboxType = sandboxType
};
{
Name = name,
IsApproved = true,
UseSandbox = true,
SandboxType = sandboxType
};

if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(secret))
{
Expand All @@ -54,13 +47,13 @@ public ApiClient AddSandboxClient(string name, SandboxType sandboxType, string k
return client;
}

public static User Create(string userEmail, string userName, Vendor vendor = null)
public static User Create(string userEmail, string userName, Vendor vendor)
{
return new User
{
Email = userEmail,
FullName = userName,
Vendor = vendor
Vendor = vendor
};
}
}
Expand All @@ -69,40 +62,40 @@ public class RegisterExternalLoginModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
public string UserName { get; set; } = string.Empty;

public string ExternalLoginData { get; set; }
public string ExternalLoginData { get; set; } = string.Empty;
}

public class LocalPasswordModel
{
[Required]
[DataType(DataType.Password)]
[Display(Name = "Current password")]
public string OldPassword { get; set; }
public string OldPassword { get; set; } = string.Empty;

[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "New password")]
public string NewPassword { get; set; }
public string NewPassword { get; set; } = string.Empty;

[DataType(DataType.Password)]
[Display(Name = "Confirm new password")]
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
public string ConfirmPassword { get; set; } = string.Empty;
}

public class LoginModel
{
[Required]
[Display(Name = "Email Address")]
public string EmailAddress { get; set; }
public required string EmailAddress { get; set; }

[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
public required string Password { get; set; }

[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
Expand All @@ -112,26 +105,26 @@ public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
public required string UserName { get; set; }

[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
public required string Password { get; set; }

[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
public required string ConfirmPassword { get; set; }
}

public class ExternalLogin
{
public string Provider { get; set; }
public string Provider { get; set; } = string.Empty;

public string ProviderDisplayName { get; set; }
public string ProviderDisplayName { get; set; } = string.Empty;

public string ProviderUserId { get; set; }
public string ProviderUserId { get; set; } = string.Empty;
}
}
Loading
Loading