mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Added tests.
This commit is contained in:
parent
0ae840f74a
commit
71ae471864
@ -43,6 +43,50 @@
|
||||
<PropertyGroup>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Costura, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll</HintPath>
|
||||
|
||||
@ -60,7 +60,7 @@ namespace Remotely.Agent.Services
|
||||
|
||||
await HubConnection.StartAsync();
|
||||
|
||||
var device = await DeviceInformation.Create(ConnectionInfo);
|
||||
var device = await DeviceInformation.Create(ConnectionInfo.DeviceID, ConnectionInfo.OrganizationID);
|
||||
|
||||
var result = await HubConnection.InvokeAsync<bool>("DeviceCameOnline", device);
|
||||
|
||||
@ -98,7 +98,7 @@ namespace Remotely.Agent.Services
|
||||
|
||||
public async Task SendHeartbeat()
|
||||
{
|
||||
var currentInfo = await DeviceInformation.Create(ConnectionInfo);
|
||||
var currentInfo = await DeviceInformation.Create(ConnectionInfo.DeviceID, ConnectionInfo.OrganizationID);
|
||||
await HubConnection.InvokeAsync("DeviceHeartbeat", currentInfo);
|
||||
}
|
||||
|
||||
|
||||
34
Remotely.sln
34
Remotely.sln
@ -47,7 +47,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Desktop.Win", "Desktop.Win\
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agent.Installer.Win", "Agent.Installer.Win\Agent.Installer.Win.csproj", "{A3D0368C-0850-4614-B5B5-41B9D5135AA9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{48D9D0E6-5781-44A9-84C0-56F56C2A1193}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{48D9D0E6-5781-44A9-84C0-56F56C2A1193}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -157,28 +157,28 @@ Global
|
||||
{6B726FC4-A907-4813-BF38-3342E02AA8D2}.Release|x86.Build.0 = Release|x86
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Debug|x64.Build.0 = Debug|x64
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Debug|x86.Build.0 = Debug|x86
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x86.Build.0 = Release|Any CPU
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x64.ActiveCfg = Release|x64
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x64.Build.0 = Release|x64
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x86.ActiveCfg = Release|x86
|
||||
{A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x86.Build.0 = Release|x86
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x64.Build.0 = Debug|x64
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x86.Build.0 = Debug|x86
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x64.Build.0 = Release|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x86.Build.0 = Release|Any CPU
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x64.ActiveCfg = Release|x64
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x64.Build.0 = Release|x64
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x86.ActiveCfg = Release|x86
|
||||
{48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@ -249,14 +249,20 @@ namespace Remotely.Server.API
|
||||
|
||||
if (!DataService.DoesUserExist(invite.InvitedUser))
|
||||
{
|
||||
var user = new RemotelyUser { UserName = invite.InvitedUser, Email = invite.InvitedUser, OrganizationID = orgID };
|
||||
var user = new RemotelyUser
|
||||
{
|
||||
UserName = invite.InvitedUser,
|
||||
Email = invite.InvitedUser,
|
||||
OrganizationID = orgID,
|
||||
IsAdministrator = invite.IsAdmin
|
||||
};
|
||||
var result = await UserManager.CreateAsync(user);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
if (!DataService.SetNewUserProperties(user.UserName, orgID, invite.IsAdmin))
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
//if (!DataService.SetNewUserProperties(user.UserName, orgID, invite.IsAdmin))
|
||||
//{
|
||||
// return BadRequest();
|
||||
//}
|
||||
|
||||
|
||||
user = await UserManager.FindByEmailAsync(invite.InvitedUser);
|
||||
|
||||
@ -57,6 +57,40 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage
|
||||
public async Task<IActionResult> OnPostSendInviteAsync()
|
||||
{
|
||||
var currentUser = await UserManager.FindByEmailAsync(User.Identity.Name);
|
||||
return await SendInvite(currentUser);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostCreateDeviceGroupAsync()
|
||||
{
|
||||
var currentUser = await UserManager.FindByEmailAsync(User.Identity.Name);
|
||||
if (!currentUser.IsAdministrator)
|
||||
{
|
||||
return RedirectToPage("Index");
|
||||
}
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var deviceGroup = new DeviceGroup()
|
||||
{
|
||||
Name = Input.DeviceGroupName
|
||||
};
|
||||
|
||||
var result = DataService.AddDeviceGroup(currentUser.OrganizationID, deviceGroup, out _, out var errorMessage);
|
||||
if (!result)
|
||||
{
|
||||
PopulateViewModel();
|
||||
ModelState.AddModelError("AddDeviceGroup", errorMessage);
|
||||
return Page();
|
||||
}
|
||||
StatusMessage = "Device group created.";
|
||||
return RedirectToPage();
|
||||
}
|
||||
PopulateViewModel();
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> SendInvite(RemotelyUser currentUser)
|
||||
{
|
||||
if (!currentUser.IsAdministrator)
|
||||
{
|
||||
return RedirectToPage("Index");
|
||||
@ -66,15 +100,22 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage
|
||||
{
|
||||
if (!DataService.DoesUserExist(Input.UserEmail))
|
||||
{
|
||||
var user = new RemotelyUser { UserName = Input.UserEmail, Email = Input.UserEmail };
|
||||
var user = new RemotelyUser
|
||||
{
|
||||
UserName = Input.UserEmail,
|
||||
Email = Input.UserEmail,
|
||||
OrganizationID = currentUser.OrganizationID,
|
||||
Organization = currentUser.Organization,
|
||||
IsAdministrator = Input.IsAdmin
|
||||
};
|
||||
var result = await UserManager.CreateAsync(user);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
if (!DataService.SetNewUserProperties(user.UserName, currentUser.OrganizationID, Input.IsAdmin))
|
||||
{
|
||||
ModelState.AddModelError("OrgID", "Failed to set organization ID.");
|
||||
return Page();
|
||||
}
|
||||
//if (!DataService.SetNewUserProperties(user.UserName, currentUser.OrganizationID, Input.IsAdmin))
|
||||
//{
|
||||
// ModelState.AddModelError("OrgID", "Failed to set organization ID.");
|
||||
// return Page();
|
||||
//}
|
||||
|
||||
user = await UserManager.FindByEmailAsync(Input.UserEmail);
|
||||
|
||||
@ -118,35 +159,6 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostCreateDeviceGroupAsync()
|
||||
{
|
||||
var currentUser = await UserManager.FindByEmailAsync(User.Identity.Name);
|
||||
if (!currentUser.IsAdministrator)
|
||||
{
|
||||
return RedirectToPage("Index");
|
||||
}
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var deviceGroup = new DeviceGroup()
|
||||
{
|
||||
Name = Input.DeviceGroupName
|
||||
};
|
||||
|
||||
var result = DataService.AddDeviceGroup(currentUser.OrganizationID, deviceGroup, out _, out var errorMessage);
|
||||
if (!result)
|
||||
{
|
||||
PopulateViewModel();
|
||||
ModelState.AddModelError("AddDeviceGroup", errorMessage);
|
||||
return Page();
|
||||
}
|
||||
StatusMessage = "Device group created.";
|
||||
return RedirectToPage();
|
||||
}
|
||||
PopulateViewModel();
|
||||
return Page();
|
||||
}
|
||||
|
||||
private void PopulateViewModel()
|
||||
{
|
||||
OrganizationName = DataService.GetOrganizationName(User.Identity.Name);
|
||||
|
||||
@ -14,7 +14,7 @@ namespace Remotely.Shared.Services
|
||||
{
|
||||
public class DeviceInformation
|
||||
{
|
||||
public static async Task<Device> Create(ConnectionInfo connectionInfo)
|
||||
public static async Task<Device> Create(string deviceID, string orgID)
|
||||
{
|
||||
OSPlatform platform = OSUtils.GetPlatform();
|
||||
|
||||
@ -24,7 +24,7 @@ namespace Remotely.Shared.Services
|
||||
|
||||
var device = new Device()
|
||||
{
|
||||
ID = connectionInfo.DeviceID,
|
||||
ID = deviceID,
|
||||
DeviceName = Environment.MachineName,
|
||||
Platform = platform.ToString(),
|
||||
ProcessorCount = Environment.ProcessorCount,
|
||||
@ -42,7 +42,7 @@ namespace Remotely.Shared.Services
|
||||
TotalSize = x.TotalSize > 0 ? Math.Round((double)(x.TotalSize / 1024 / 1024 / 1024), 2) : 0,
|
||||
VolumeLabel = x.VolumeLabel
|
||||
}).ToList(),
|
||||
OrganizationID = connectionInfo.OrganizationID,
|
||||
OrganizationID = orgID,
|
||||
CurrentUser = DeviceInformation.GetCurrentUser()
|
||||
};
|
||||
|
||||
@ -53,11 +53,11 @@ namespace Remotely.Shared.Services
|
||||
}
|
||||
|
||||
|
||||
var (usedMemory, totalMemory) = DeviceInformation.GetMemoryInGB();
|
||||
var (usedMemory, totalMemory) = GetMemoryInGB();
|
||||
device.UsedMemory = usedMemory;
|
||||
device.TotalMemory = totalMemory;
|
||||
|
||||
device.CpuUtilization = await DeviceInformation.GetCpuUtilization();
|
||||
device.CpuUtilization = await GetCpuUtilization();
|
||||
|
||||
if (File.Exists("Remotely_Agent.dll"))
|
||||
{
|
||||
|
||||
@ -3,14 +3,17 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Remotely.Server.Data;
|
||||
using Remotely.Server.Services;
|
||||
using Remotely.Shared.Models;
|
||||
using Remotely.Shared.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -19,47 +22,81 @@ namespace Remotely.Tests
|
||||
[TestClass]
|
||||
public class DataServiceTests
|
||||
{
|
||||
[ClassInitialize]
|
||||
public static void ClassInit(TestContext context)
|
||||
{
|
||||
IoCActivator.Activate();
|
||||
}
|
||||
|
||||
|
||||
private DataService DataService { get; set; }
|
||||
|
||||
private DataService GetDataService()
|
||||
[TestInitialize]
|
||||
public async Task TestInit()
|
||||
{
|
||||
//var contextOptions = new DbContextOptions<ApplicationDbContext>();
|
||||
//var appDbContext = new ApplicationDbContext(contextOptions);
|
||||
//var appConfig = new ApplicationConfig(new ConfigurationRoot());
|
||||
//var dataService = new DataService(appDbContext);
|
||||
await TestData.PopulateTestData();
|
||||
DataService = IoCActivator.ServiceProvider.GetRequiredService<DataService>();
|
||||
}
|
||||
|
||||
//return dataService;
|
||||
return null;
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
TestData.ClearData();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Test()
|
||||
[DoNotParallelize]
|
||||
public void VerifyInitialData()
|
||||
{
|
||||
var dataService = IoCActivator.ServiceProvider.GetRequiredService<DataService>();
|
||||
var userManager = IoCActivator.ServiceProvider.GetRequiredService <UserManager<RemotelyUser>>();
|
||||
Assert.IsNotNull(DataService.GetUserByName(TestData.Admin1.UserName));
|
||||
Assert.IsNotNull(DataService.GetUserByName(TestData.Admin2.UserName));
|
||||
Assert.IsNotNull(DataService.GetUserByName(TestData.User1.UserName));
|
||||
Assert.IsNotNull(DataService.GetUserByName(TestData.User2.UserName));
|
||||
Assert.AreEqual(1, DataService.GetOrganizationCount());
|
||||
|
||||
Assert.IsNull(dataService.GetUserByName(TestData.TestAdmin1.UserName));
|
||||
Assert.AreEqual(0, dataService.GetOrganizationCount());
|
||||
var devices = DataService.GetAllDevices(TestData.Admin1.OrganizationID);
|
||||
|
||||
await userManager.CreateAsync(TestData.TestAdmin1);
|
||||
Assert.AreEqual(2, devices.Count());
|
||||
Assert.IsTrue(devices.Any(x => x.ID == "Device1"));
|
||||
Assert.IsTrue(devices.Any(x => x.ID == "Device2"));
|
||||
|
||||
Assert.IsNotNull(dataService.GetUserByName(TestData.TestAdmin1.UserName));
|
||||
Assert.AreEqual(1, dataService.GetOrganizationCount());
|
||||
var orgIDs = new string[]
|
||||
{
|
||||
TestData.Group1.OrganizationID,
|
||||
TestData.Group2.OrganizationID,
|
||||
TestData.Admin1.OrganizationID,
|
||||
TestData.Admin2.OrganizationID,
|
||||
TestData.User1.OrganizationID,
|
||||
TestData.User2.OrganizationID,
|
||||
TestData.Device1.OrganizationID,
|
||||
TestData.Device2.OrganizationID
|
||||
};
|
||||
|
||||
Assert.IsTrue(orgIDs.All(x => x == TestData.Admin1.OrganizationID));
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void Test2()
|
||||
[DoNotParallelize]
|
||||
public void UpdateOrganizationName()
|
||||
{
|
||||
var test = IoCActivator.ServiceProvider;
|
||||
Assert.IsTrue(string.IsNullOrWhiteSpace(TestData.Admin1.Organization.OrganizationName));
|
||||
DataService.UpdateOrganizationName(TestData.Admin1.OrganizationID, "Test Org");
|
||||
Assert.AreEqual(TestData.Admin1.Organization.OrganizationName, "Test Org");
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
[DoNotParallelize]
|
||||
public void DeviceGroupPermissions()
|
||||
{
|
||||
Assert.IsTrue(DataService.GetDevicesForUser(TestData.Admin1.UserName).Count() == 2);
|
||||
Assert.IsTrue(DataService.GetDevicesForUser(TestData.Admin2.UserName).Count() == 2);
|
||||
Assert.IsTrue(DataService.GetDevicesForUser(TestData.User1.UserName).Count() == 2);
|
||||
Assert.IsTrue(DataService.GetDevicesForUser(TestData.User2.UserName).Count() == 2);
|
||||
|
||||
var groupID = DataService.GetDeviceGroups(TestData.Admin1.UserName).First().ID;
|
||||
|
||||
DataService.UpdateDevice(TestData.Device1.ID, "", "", groupID);
|
||||
DataService.AddUserToDeviceGroup(TestData.Admin1.OrganizationID, groupID, TestData.User1.UserName, out _);
|
||||
|
||||
Assert.IsTrue(DataService.GetDevicesForUser(TestData.Admin1.UserName).Count() == 2);
|
||||
Assert.IsTrue(DataService.GetDevicesForUser(TestData.Admin2.UserName).Count() == 2);
|
||||
Assert.IsTrue(DataService.GetDevicesForUser(TestData.User1.UserName).Count() == 2);
|
||||
Assert.IsTrue(DataService.GetDevicesForUser(TestData.User2.UserName).Count() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -11,9 +11,13 @@ using Microsoft.EntityFrameworkCore.InMemory.Internal;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Remotely.Shared.Models;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
|
||||
namespace Remotely.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class IoCActivator
|
||||
{
|
||||
public static IServiceProvider ServiceProvider { get; set; }
|
||||
@ -30,6 +34,13 @@ namespace Remotely.Tests
|
||||
builder.Build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[AssemblyInitialize]
|
||||
public static void AssemblyInit(TestContext context)
|
||||
{
|
||||
Activate();
|
||||
}
|
||||
}
|
||||
|
||||
public class Startup
|
||||
@ -44,14 +55,17 @@ namespace Remotely.Tests
|
||||
.AddDefaultUI()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
services.AddScoped<DataService>();
|
||||
services.AddScoped<ApplicationConfig>();
|
||||
services.AddTransient<DataService>();
|
||||
services.AddTransient<ApplicationConfig>();
|
||||
services.AddTransient<IEmailSender, EmailSender>();
|
||||
IoCActivator.ServiceProvider = services.BuildServiceProvider();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext context, DataService dataService)
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,16 +1,110 @@
|
||||
using Remotely.Shared.Models;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Remotely.Server.Areas.Identity.Pages.Account.Manage;
|
||||
using Remotely.Server.Data;
|
||||
using Remotely.Server.Services;
|
||||
using Remotely.Shared.Models;
|
||||
using Remotely.Shared.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Remotely.Tests
|
||||
{
|
||||
public class TestData
|
||||
{
|
||||
public static RemotelyUser TestAdmin1 { get; } = new RemotelyUser()
|
||||
public static RemotelyUser Admin1 { get; } = new RemotelyUser()
|
||||
{
|
||||
UserName = "testadmin1@test.com",
|
||||
UserName = "admin1@test.com",
|
||||
IsAdministrator = true
|
||||
};
|
||||
|
||||
public static RemotelyUser Admin2 { get; private set; } = new RemotelyUser()
|
||||
{
|
||||
UserName = "admin2@test.com",
|
||||
IsAdministrator = true
|
||||
};
|
||||
|
||||
public static RemotelyUser User1 { get; private set; } = new RemotelyUser()
|
||||
{
|
||||
UserName = "testuser1@test.com",
|
||||
IsAdministrator = false
|
||||
};
|
||||
|
||||
public static RemotelyUser User2 { get; private set; } = new RemotelyUser()
|
||||
{
|
||||
UserName = "testuser2@test.com",
|
||||
IsAdministrator = false
|
||||
};
|
||||
|
||||
public static DeviceGroup Group1 { get; private set; } = new DeviceGroup()
|
||||
{
|
||||
Name = "Group1"
|
||||
};
|
||||
|
||||
public static DeviceGroup Group2 { get; private set; } = new DeviceGroup()
|
||||
{
|
||||
Name = "Group2"
|
||||
};
|
||||
|
||||
public static Device Device1 { get; private set; } = new Device()
|
||||
{
|
||||
ID = "Device1"
|
||||
};
|
||||
|
||||
public static Device Device2 { get; private set; } = new Device()
|
||||
{
|
||||
ID = "Device2"
|
||||
};
|
||||
|
||||
public static void ClearData()
|
||||
{
|
||||
var dbContext = IoCActivator.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
dbContext.Devices.RemoveRange(dbContext.Devices.ToList());
|
||||
dbContext.DeviceGroups.RemoveRange(dbContext.DeviceGroups.ToList());
|
||||
dbContext.Users.RemoveRange(dbContext.Users.ToList());
|
||||
dbContext.SaveChanges();
|
||||
|
||||
}
|
||||
|
||||
public static async Task PopulateTestData()
|
||||
{
|
||||
var dataService = IoCActivator.ServiceProvider.GetRequiredService<DataService>();
|
||||
var userManager = IoCActivator.ServiceProvider.GetRequiredService<UserManager<RemotelyUser>>();
|
||||
var emailSender = IoCActivator.ServiceProvider.GetRequiredService<IEmailSender>();
|
||||
var organizationModel = new OrganizationModel(dataService, userManager, emailSender);
|
||||
|
||||
|
||||
await userManager.CreateAsync(Admin1);
|
||||
|
||||
organizationModel.Input.UserEmail = Admin2.UserName;
|
||||
organizationModel.Input.IsAdmin = true;
|
||||
await organizationModel.SendInvite(Admin1);
|
||||
Admin2 = await userManager.FindByNameAsync(Admin2.UserName);
|
||||
|
||||
organizationModel.Input.UserEmail = User1.UserName;
|
||||
organizationModel.Input.IsAdmin = false;
|
||||
await organizationModel.SendInvite(Admin1);
|
||||
User1 = await userManager.FindByNameAsync(User1.UserName);
|
||||
|
||||
organizationModel.Input.UserEmail = User2.UserName;
|
||||
organizationModel.Input.IsAdmin = false;
|
||||
await organizationModel.SendInvite(Admin1);
|
||||
User2 = await userManager.FindByNameAsync(User2.UserName);
|
||||
|
||||
Device1.OrganizationID = Admin1.OrganizationID;
|
||||
dataService.AddOrUpdateDevice(Device1, out _);
|
||||
Device2.OrganizationID = Admin1.OrganizationID;
|
||||
dataService.AddOrUpdateDevice(Device2, out _);
|
||||
|
||||
dataService.AddDeviceGroup(Admin1.OrganizationID, Group1, out _, out _);
|
||||
dataService.AddDeviceGroup(Admin1.OrganizationID, Group2, out _, out _);
|
||||
var deviceGroups = dataService.GetDeviceGroups(Admin1.UserName);
|
||||
Group1 = deviceGroups.First(x => x.Name == Group1.Name);
|
||||
Group2 = deviceGroups.First(x => x.Name == Group2.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
<RootNamespace>Remotely.Tests</RootNamespace>
|
||||
|
||||
<AssemblyName>Remotely_Tests</AssemblyName>
|
||||
|
||||
<Platforms>AnyCPU;x64;x86</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user