using Capnp.Rpc; using FabAccessAPI; using FabAccessAPI.Schema; using NUnit.Framework; using System; using System.Collections.Generic; using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using static FabAccessAPI.Schema.Machine; namespace FabAccessAPI_Test { [TestFixture, Parallelizable(ParallelScope.Children)] [Order(1)] public class MachineSystem_Test { [TestCase("Admin1", true)] [TestCase("Admin2", true)] [TestCase("ManagerA1", true)] [TestCase("ManagerA2", true)] [TestCase("ManagerB1", true)] [TestCase("ManagerB2", true)] [TestCase("ManagerC1", true)] [TestCase("ManagerC2", true)] [TestCase("ManagerABC1", true)] [TestCase("ManagerABC2", true)] [TestCase("MakerA1", true)] [TestCase("MakerA2", true)] [TestCase("MakerB1", true)] [TestCase("MakerB2", true)] [TestCase("MakerC1", true)] [TestCase("MakerC2", true)] [TestCase("MakerABC1", true)] [TestCase("MakerABC2", true)] [TestCase("GuestA1", true)] [TestCase("GuestA2", true)] [TestCase("GuestB1", true)] [TestCase("GuestB2", true)] [TestCase("GuestC1", true)] [TestCase("GuestC2", true)] [TestCase("GuestABC1", true)] [TestCase("GuestABC2", true)] [TestCase("MakerQRA", true)] [TestCase("MakerQRB", true)] [TestCase("MakerQRC", true)] [Order(2)] public async Task AccessMachineSystem_Info(string username, bool expectAllow) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Assert.AreEqual(expectAllow, !((MachineSystem.InfoInterface_Proxy)api.Session.MachineSystem.Info).IsNull); } [TestCase("Admin1", 15)] [TestCase("ManagerA1", 5)] [TestCase("ManagerB1", 5)] [TestCase("ManagerC1", 5)] [TestCase("ManagerABC1", 15)] [TestCase("MakerA1", 5)] [TestCase("MakerB1", 5)] [TestCase("MakerC1", 5)] [TestCase("MakerABC1", 15)] [TestCase("GuestA1", 5)] [TestCase("GuestB1", 5)] [TestCase("GuestC1", 5)] [TestCase("GuestABC1", 15)] [TestCase("MakerQRA", 0)] [TestCase("MakerQRB", 0)] [TestCase("MakerQRC", 0)] [Order(3)] public async Task ListMachines(string username, int expectedMachineCount) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); IReadOnlyList machine_list = await api.Session.MachineSystem.Info.GetMachineList().ConfigureAwait(false); int result = machine_list.Count; await api.Disconnect(); Assert.AreEqual(expectedMachineCount, result); } [TestCase("Admin1", "MachineA1", true)] [TestCase("Admin1", "MachineB1", true)] [TestCase("Admin1", "MachineC1", true)] [TestCase("ManagerA1", "MachineA1", true)] [TestCase("ManagerA1", "MachineB1", false)] [TestCase("ManagerA1", "MachineC1", false)] [TestCase("ManagerB1", "MachineA1", false)] [TestCase("ManagerB1", "MachineB1", true)] [TestCase("ManagerB1", "MachineC1", false)] [TestCase("ManagerC1", "MachineA1", false)] [TestCase("ManagerC1", "MachineB1", false)] [TestCase("ManagerC1", "MachineC1", true)] [TestCase("ManagerABC1", "MachineA1", true)] [TestCase("ManagerABC1", "MachineB1", true)] [TestCase("ManagerABC1", "MachineC1", true)] [TestCase("MakerA1", "MachineA1", true)] [TestCase("MakerB1", "MachineB1", true)] [TestCase("MakerC1", "MachineC1", true)] [TestCase("GuestA1", "MachineA1", true)] [TestCase("GuestB1", "MachineB1", true)] [TestCase("GuestC1", "MachineC1", true)] [TestCase("MakerQRA", "MachineA1", true)] [TestCase("MakerQRB", "MachineB1", true)] [TestCase("MakerQRC", "MachineC1", true)] [Order(4)] public async Task GetMachineByName(string username, string machineName, bool expectedAllow) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Optional optional = await api.Session.MachineSystem.Info.GetMachine(machineName).ConfigureAwait(false); bool result = optional.Just != null; await api.Disconnect(); Assert.AreEqual(expectedAllow, result); } [TestCase("Admin1", "MachineX")] [TestCase("Admin1", "urn:fabaccess:resource:MachineA1")] [Order(5)] public async Task GetMachineByName_WrongName(string username, string machineName) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Optional optional = await api.Session.MachineSystem.Info.GetMachine(machineName).ConfigureAwait(false); await api.Disconnect(); Assert.IsNull(optional.Just); } [TestCase("Admin1", "urn:fabaccess:resource:MachineA1", true)] [TestCase("Admin1", "urn:fabaccess:resource:MachineB1", true)] [TestCase("Admin1", "urn:fabaccess:resource:MachineC1", true)] [TestCase("ManagerA1", "urn:fabaccess:resource:MachineA1", true)] [TestCase("ManagerA1", "urn:fabaccess:resource:MachineB1", false)] [TestCase("ManagerA1", "urn:fabaccess:resource:MachineC1", false)] [TestCase("ManagerB1", "urn:fabaccess:resource:MachineA1", false)] [TestCase("ManagerB1", "urn:fabaccess:resource:MachineB1", true)] [TestCase("ManagerB1", "urn:fabaccess:resource:MachineC1", false)] [TestCase("ManagerC1", "urn:fabaccess:resource:MachineA1", false)] [TestCase("ManagerC1", "urn:fabaccess:resource:MachineB1", false)] [TestCase("ManagerC1", "urn:fabaccess:resource:MachineC1", true)] [TestCase("ManagerABC1", "urn:fabaccess:resource:MachineA1", true)] [TestCase("ManagerABC1", "urn:fabaccess:resource:MachineB1", true)] [TestCase("ManagerABC1", "urn:fabaccess:resource:MachineC1", true)] [TestCase("MakerA1", "urn:fabaccess:resource:MachineA1", true)] [TestCase("MakerB1", "urn:fabaccess:resource:MachineB1", true)] [TestCase("MakerC1", "urn:fabaccess:resource:MachineC1", true)] [TestCase("GuestA1", "urn:fabaccess:resource:MachineA1", true)] [TestCase("GuestB1", "urn:fabaccess:resource:MachineB1", true)] [TestCase("GuestC1", "urn:fabaccess:resource:MachineC1", true)] [TestCase("MakerQRA", "urn:fabaccess:resource:MachineA1", true)] [TestCase("MakerQRB", "urn:fabaccess:resource:MachineB1", true)] [TestCase("MakerQRC", "urn:fabaccess:resource:MachineC1", true)] [Order(6)] public async Task GetMachineByURN(string username, string urn, bool expectedAllow) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Optional optional = await api.Session.MachineSystem.Info.GetMachineURN(urn).ConfigureAwait(false); bool result = optional.Just != null; await api.Disconnect(); Assert.AreEqual(expectedAllow, result); } [TestCase("Admin1", "urn:fabaccess:resource:MachineX")] [TestCase("Admin1", "MachineA1")] [TestCase("Admin1", "something")] [Order(7)] public async Task GetMachineByURN_WrongURN(string username, string urn) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Optional optional = await api.Session.MachineSystem.Info.GetMachineURN(urn).ConfigureAwait(false); await api.Disconnect(); Assert.IsNull(optional.Just); } } [TestFixture, Parallelizable(ParallelScope.Children)] [Order(2)] public class Machine_Test_Stateless { [TestCase("Admin1", "MachineA1", true)] [TestCase("Admin1", "MachineB1", true)] [TestCase("Admin1", "MachineC1", true)] [TestCase("ManagerA1", "MachineA1", true)] [TestCase("ManagerB1", "MachineB1", true)] [TestCase("ManagerC1", "MachineC1", true)] [TestCase("ManagerABC1", "MachineA1", true)] [TestCase("ManagerABC1", "MachineB1", true)] [TestCase("ManagerABC1", "MachineC1", true)] [TestCase("MakerA1", "MachineA1", true)] [TestCase("MakerB1", "MachineB1", true)] [TestCase("MakerC1", "MachineC1", true)] [TestCase("GuestA1", "MachineA1", true)] [TestCase("GuestB1", "MachineB1", true)] [TestCase("GuestC1", "MachineC1", true)] [TestCase("MakerQRA", "MachineA1", true)] [TestCase("MakerQRB", "MachineB1", true)] [TestCase("MakerQRC", "MachineC1", true)] [Order(1)] public async Task InfoInterface(string username, string machineID, bool expectInterface) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; bool result = !((Machine.InfoInterface_Proxy)machine.Info).IsNull; await api.Disconnect(); Assert.AreEqual(expectInterface, result); } [TestCase("Admin1", "MachineA1", true)] [TestCase("Admin1", "MachineB1", true)] [TestCase("Admin1", "MachineC1", true)] [TestCase("ManagerA1", "MachineA1", true)] [TestCase("ManagerB1", "MachineB1", true)] [TestCase("ManagerC1", "MachineC1", true)] [TestCase("ManagerABC1", "MachineA1", true)] [TestCase("ManagerABC1", "MachineB1", true)] [TestCase("ManagerABC1", "MachineC1", true)] [TestCase("MakerA1", "MachineA1", false)] [TestCase("MakerB1", "MachineB1", false)] [TestCase("MakerC1", "MachineC1", false)] [TestCase("GuestA1", "MachineA1", false)] [TestCase("GuestB1", "MachineB1", false)] [TestCase("GuestC1", "MachineC1", false)] [TestCase("MakerQRA", "MachineA1", false)] [TestCase("MakerQRB", "MachineB1", false)] [TestCase("MakerQRC", "MachineC1", false)] [Order(2)] public async Task ManageInterface(string username, string machineID, bool expectInterface) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; bool result = !((ManageInterface_Proxy)machine.Manage).IsNull; await api.Disconnect(); Assert.AreEqual(expectInterface, result); } [TestCase("Admin1", "MachineA1", true)] [TestCase("Admin1", "MachineB1", true)] [TestCase("Admin1", "MachineC1", true)] [TestCase("ManagerA1", "MachineA1", false)] [TestCase("ManagerB1", "MachineB1", false)] [TestCase("ManagerC1", "MachineC1", false)] [TestCase("ManagerABC1", "MachineA1", false)] [TestCase("ManagerABC1", "MachineB1", false)] [TestCase("ManagerABC1", "MachineC1", false)] [TestCase("MakerA1", "MachineA1", false)] [TestCase("MakerB1", "MachineB1", false)] [TestCase("MakerC1", "MachineC1", false)] [TestCase("GuestA1", "MachineA1", false)] [TestCase("GuestB1", "MachineB1", false)] [TestCase("GuestC1", "MachineC1", false)] [TestCase("MakerQRA", "MachineA1", false)] [TestCase("MakerQRB", "MachineB1", false)] [TestCase("MakerQRC", "MachineC1", false)] [Order(3), Ignore("Not Implemented")] public async Task AdminInterface(string username, string machineID, bool expectInterface) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; bool result = !((AdminInterface_Proxy)machine.Admin).IsNull; await api.Disconnect(); Assert.AreEqual(expectInterface, result); } [TestCase("Admin1", "MachineA1", "Description of MachineA1", @"https://fab-access.readthedocs.io", "CategoryA")] [TestCase("Admin1", "MachineB2", "Description of MachineB2", @"https://fab-access.readthedocs.io", "CategoryB")] [TestCase("Admin1", "MachineC3", "Description of MachineC3", @"https://fab-access.readthedocs.io", "CategoryC")] [Order(4)] public async Task ReadMachineData(string username, string machineID, string description, string wiki, string category) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await api.Disconnect(); Assert.Multiple(() => { Assert.AreEqual(machineID, machine.Id); Assert.AreEqual(description, machine.Description); Assert.AreEqual(wiki, machine.Wiki); Assert.AreEqual(category, machine.Category); }); } } [TestFixture] [Order(3)] public class Machine_Test { #region SetUp [SetUp] public async Task SetUp() { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData("Admin1"); await api.Connect(connectionData); IReadOnlyList machine_list = await api.Session.MachineSystem.Info.GetMachineList().ConfigureAwait(false); List tasks = new List(); foreach(Machine m in machine_list) { tasks.Add(m.Manage.ForceFree()); } await Task.WhenAll(tasks); } #endregion [TestCase("Admin1", "MachineA1")] [TestCase("ManagerA1", "MachineA1")] [TestCase("MakerA1", "MachineA1")] [Order(1)] public async Task UseGiveBack(string username, string machineID) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; // Check State before run Test if (machine.State != MachineState.free) { await api.Disconnect(); Assert.Inconclusive("State is not 'free'"); } await machine.Use.Use().ConfigureAwait(false); machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine.Inuse.GiveBack().ConfigureAwait(false); machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await api.Disconnect(); Assert.AreEqual(MachineState.free, machine.State); } [TestCase("ManagerA1", "MakerA1", "MachineA1")] [TestCase("MakerA1", "Admin1", "MachineA1")] [TestCase("ManagerA1", "GuestA1", "MachineA1")] [Order(2), Ignore("Not Implemented")] public async Task TransferMachine(string username1, string username2, string machineID) { API api1 = new API(); ConnectionData connectionData1 = TestEnv.CreateConnetionData(username1); await api1.Connect(connectionData1); API api2 = new API(); ConnectionData connectionData2 = TestEnv.CreateConnetionData(username2); await api2.Connect(connectionData2); Machine machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; // Check State before run Test if (machine1.State != MachineState.free) { await api1.Disconnect(); await api2.Disconnect(); Assert.Inconclusive("State is not 'free'"); } await machine1.Use.Use().ConfigureAwait(false); machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine1.Inuse.Releasefortakeover().ConfigureAwait(false); Machine machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine2.Takeover.Accept().ConfigureAwait(false); machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine2.Inuse.GiveBack().ConfigureAwait(false); machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await api1.Disconnect(); await api2.Disconnect(); Assert.AreEqual(MachineState.free, machine1.State); } [TestCase("ManagerA1", "MakerA1", "MachineA1")] [TestCase("MakerA1", "Admin1", "MachineA1")] [TestCase("ManagerA1", "GuestA1", "MachineA1")] [Order(3), Ignore("Not Implemented")] public async Task TransferMachine_Reject(string username1, string username2, string machineID) { API api1 = new API(); ConnectionData connectionData1 = TestEnv.CreateConnetionData(username1); await api1.Connect(connectionData1); API api2 = new API(); ConnectionData connectionData2 = TestEnv.CreateConnetionData(username2); await api2.Connect(connectionData2); Machine machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; // Check State before run Test if (machine1.State != MachineState.free) { await api1.Disconnect(); await api2.Disconnect(); Assert.Inconclusive("State is not 'free'"); } await machine1.Use.Use().ConfigureAwait(false); machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine1.Inuse.Releasefortakeover().ConfigureAwait(false); Machine machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine2.Takeover.Reject().ConfigureAwait(false); machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine1.Inuse.GiveBack().ConfigureAwait(false); machine2 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await api1.Disconnect(); await api2.Disconnect(); Assert.AreEqual(MachineState.free, machine2.State); } [TestCase("ManagerA1", "ManagerA1", "MachineA1")] [TestCase("ManagerA1", "Admin1", "MachineA1")] [TestCase("MakerA1", "Admin1", "MachineA1")] [Order(4), Ignore("Not Implemented")] public async Task CheckMachine(string username1, string username2, string machineID) { API api1 = new API(); ConnectionData connectionData1 = TestEnv.CreateConnetionData(username1); await api1.Connect(connectionData1); API api2 = new API(); ConnectionData connectionData2 = TestEnv.CreateConnetionData(username2); await api2.Connect(connectionData2); Machine machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; // Check State before run Test if (machine1.State != MachineState.free) { await api1.Disconnect(); await api2.Disconnect(); Assert.Inconclusive("State is not 'free'"); } await machine1.Use.Use().ConfigureAwait(false); machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine1.Inuse.GiveBack().ConfigureAwait(false); Machine machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine2.Check.Check().ConfigureAwait(false); machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await api1.Disconnect(); await api2.Disconnect(); Assert.AreEqual(MachineState.free, machine1.State); } [TestCase("ManagerA1", "ManagerA1", "MachineA1")] [TestCase("ManagerA1", "Admin1", "MachineA1")] [TestCase("MakerA1", "Admin1", "MachineA1")] [Order(5), Ignore("Not Implemented")] public async Task CheckMachine_Reject(string username1, string username2, string machineID) { API api1 = new API(); ConnectionData connectionData1 = TestEnv.CreateConnetionData(username1); await api1.Connect(connectionData1); API api2 = new API(); ConnectionData connectionData2 = TestEnv.CreateConnetionData(username2); await api2.Connect(connectionData2); Machine machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; // Check State before run Test if (machine1.State != MachineState.free) { await api1.Disconnect(); await api2.Disconnect(); Assert.Inconclusive("State is not 'free'"); } await machine1.Use.Use().ConfigureAwait(false); machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine1.Inuse.GiveBack().ConfigureAwait(false); Machine machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine2.Check.Reject().ConfigureAwait(false); machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine1.Inuse.GiveBack().ConfigureAwait(false); machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine2.Check.Check().ConfigureAwait(false); machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await api1.Disconnect(); await api2.Disconnect(); Assert.AreEqual(MachineState.free, machine1.State); } [TestCase("MakerA1", "GuestA1", "ManagerA1", "MachineA1")] [Order(4), Ignore("Not Implemented")] public async Task CheckMachine_NoPermission(string username1, string username2, string username3, string machineID) { API api1 = new API(); ConnectionData connectionData1 = TestEnv.CreateConnetionData(username1); await api1.Connect(connectionData1); API api2 = new API(); ConnectionData connectionData2 = TestEnv.CreateConnetionData(username2); await api2.Connect(connectionData2); API api3 = new API(); ConnectionData connectionData3 = TestEnv.CreateConnetionData(username3); await api3.Connect(connectionData3); Machine machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; // Check State before run Test if (machine1.State != MachineState.free) { await api1.Disconnect(); await api2.Disconnect(); await api3.Disconnect(); Assert.Inconclusive("State is not 'free'"); } await machine1.Use.Use().ConfigureAwait(false); machine1 = (await api1.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine1.Inuse.GiveBack().ConfigureAwait(false); Machine machine2 = (await api2.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; bool result = ((CheckInterface_Proxy)machine2.Check).IsNull; Machine machine3 = (await api3.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; await machine3.Check.Check().ConfigureAwait(false); await api1.Disconnect(); await api2.Disconnect(); await api3.Disconnect(); Assert.IsTrue(result); } [TestCase("ManagerA1", "MachineA1")] [Order(5)] public async Task CurrentUser(string username, string machineID) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); Machine machine = (await api.Session.MachineSystem.Info.GetMachine(machineID).ConfigureAwait(false)).Just; // Check State before run Test if (machine.State != MachineState.free) { await api.Disconnect(); Assert.Inconclusive("State is not 'free'"); } MachineInfoExtended machineInfoExtended = await machine.Manage.GetMachineInfoExtended().ConfigureAwait(false); await api.Disconnect(); Assert.IsNull(machineInfoExtended.CurrentUser.Just); } } [TestFixture, Parallelizable(ParallelScope.Children)] [Order(4)] public class PermissionSystem_Test { [TestCase("Admin1", true)] [TestCase("ManagerA1", true)] [TestCase("MakerA1", true)] [TestCase("GuestA1", true)] [Order(1)] public async Task AccessPermissionSystem(string username, bool expectInterface) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); bool result = api.Session.PermissionSystem != null; await api.Disconnect(); Assert.AreEqual(expectInterface, result); } //[TestCase("Admin1", true)] //[TestCase("ManagerA1", true)] //[TestCase("MakerA1", true)] //[TestCase("GuestA1", true)] //[Order(2)] //public async Task InfoInterface(string username, bool expectInterface) //{ // Connection connection = await API_TestEnv_Test.Connect(username); // Session session = connection.Session; // MachineSystem.IInfoInterface infoInterface = await session.PermissionSystem.Info().ConfigureAwait(false); // bool result = !((Machine.InfoInterface_Proxy)machine.Info).IsNull; // API_TestEnv_Test.Disconnect(connection); // Assert.AreEqual(expectInterface, result); //} [TestCase("Admin1", 13)] [TestCase("ManagerA1", 13)] [TestCase("MakerA1", 13)] [TestCase("GuestA1", 13)] [Order(3), Ignore("Not Implemented")] public async Task ListRoles(string username, int expectRolesCount) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); IReadOnlyList roles_list = await api.Session.PermissionSystem.Info.GetRoleList().ConfigureAwait(false); await api.Disconnect(); Assert.AreEqual(expectRolesCount, roles_list.Count); } } [TestFixture, Parallelizable(ParallelScope.Children)] [Order(5)] public class UserSystem_Test { //[TestCase("Admin1", true)] //[TestCase("ManagerA1", true)] //[TestCase("MakerA1", true)] //[TestCase("GuestA1", true)] //[Order(2)] //public async Task InfoInterface(string username, bool expectInterface) //{ // Connection connection = await API_TestEnv_Test.Connect(username); // Session session = connection.Session; // UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false); // bool result = !((UserSystem.InfoInterface_Proxy)infoInterface.Info).IsNull; // API_TestEnv_Test.Disconnect(connection); // Assert.AreEqual(expectInterface, result); //} //[TestCase("Admin1", true)] //[TestCase("ManagerA1", false)] //[TestCase("MakerA1", false)] //[TestCase("GuestA1", false)] //[Order(3)] //public async Task ManageInterface(string username, bool expectInterface) //{ // Connection connection = await API_TestEnv_Test.Connect(username); // Session session = connection.Session; // UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false); // bool result = !((UserSystem.InfoInterface_Proxy)infoInterface.Info).IsNull; // API_TestEnv_Test.Disconnect(connection); // Assert.AreEqual(expectInterface, result); //} [TestCase("Admin1")] [TestCase("ManagerA1")] [TestCase("MakerA1")] [TestCase("GuestA1")] [Order(4)] public async Task GetUserSelf(string username) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false); await api.Disconnect(); Assert.IsNotNull(user); } } [TestFixture, Parallelizable(ParallelScope.Children)] [Order(6)] public class User_Test_Stateless { [TestCase("Admin1", true)] [TestCase("ManagerA1", true)] [TestCase("MakerA1", true)] [TestCase("GuestA1", true)] [Order(1)] public async Task InfoInterface(string username, bool expectInterface) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false); bool result = !((User.InfoInterface_Proxy)user.Info).IsNull; await api.Disconnect(); Assert.AreEqual(expectInterface, result); } [TestCase("Admin1", true)] [TestCase("ManagerA1", true)] [TestCase("MakerA1", true)] [TestCase("GuestA1", true)] [Order(2), Ignore("Not Implemented")] public async Task ManageInterface(string username, bool expectInterface) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false); bool result = !((User.ManageInterface_Proxy)user.Manage).IsNull; await api.Disconnect(); Assert.AreEqual(expectInterface, result); } [TestCase("Admin1", true)] [TestCase("ManagerA1", false)] [TestCase("MakerA1", false)] [TestCase("GuestA1", false)] [Order(3), Ignore("Not Implemented")] public async Task AdminInterface(string username, bool expectInterface) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false); bool result = !((User.AdminInterface_Proxy)user.Admin).IsNull; await api.Disconnect(); Assert.AreEqual(expectInterface, result); } [TestCase("Admin1")] [TestCase("ManagerA1")] [TestCase("MakerA1")] [TestCase("GuestA1")] [Order(4)] public async Task ReadUserData(string username) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false); await api.Disconnect(); Assert.Multiple(() => { Assert.AreEqual(username, user.Username); }); } [TestCase("Admin1", "somerole")] [TestCase("ManagerA1")] [TestCase("MakerA1")] [TestCase("GuestA1")] [Order(5), Ignore("Not Implemented")] public async Task ListUserRoles(string username, params string[] expect_roles) { API api = new API(); ConnectionData connectionData = TestEnv.CreateConnetionData(username); await api.Connect(connectionData); User user = await api.Session.UserSystem.Info.GetUserSelf().ConfigureAwait(false); List roles_user = new List(await user.Info.ListRoles().ConfigureAwait(false)); List expect_roles_list = new List(expect_roles); await api.Disconnect(); if (roles_user.Count != expect_roles_list.Count) { Assert.Fail("Roles Count is different"); } foreach (Role role_user in roles_user) { if (!expect_roles_list.Exists(x => x == role_user.Name)) { Assert.Fail("Roles are different"); } } } } [TestFixture] [Order(7)] public class User_Test { } }