using System.Reflection; using Centron.BusinessLogic.Administration.Licensing; using Centron.Data.Entities.Administration.Logins; using Centron.Interfaces.Administration.Logins; using Centron.Interfaces.BL; using Microsoft.Graph; using Microsoft.Graph.Models; using Microsoft.Kiota.Abstractions; using Microsoft.Kiota.Abstractions.Serialization; using NSubstitute; namespace Centron.Tests.BL.SetupUtils; public static class MockSetupUtils { public static ILicenseManager PrepareLicenseManagerMock(params Result[] licenseGuids) { var mockedLicenseServer = Substitute.For(); foreach (var license in licenseGuids) { mockedLicenseServer.CheckLicense( Arg.Any(), Arg.Any(), Arg.Any()).Returns(license); mockedLicenseServer.HasLicense( Arg.Is(license.Data)).Returns(license is { Status: ResultStatus.Success }); } return mockedLicenseServer; } public static GraphServiceClient PrepareGraphMock(List users) { return PrepareGraphMock(users); } public static GraphServiceClient PrepareGraphMock(object value) where T : IParsable, new() { var requestAdapter = Substitute.For(); var mock = new T(); var valueProperty = typeof(T).GetProperty("Value"); if (valueProperty == null) throw new Exception("Value property not found"); if (!valueProperty.PropertyType.IsInstanceOfType(value)) throw new InvalidOperationException($"Value property type mismatch: expected {valueProperty.PropertyType}, got {value.GetType()}"); valueProperty.SetValue(mock, value); requestAdapter.SendAsync( Arg.Any(), Arg.Any>(), Arg.Any>>(), Arg.Any()) .ReturnsForAnyArgs(mock); return new GraphServiceClient(requestAdapter); } }