using Centron.BusinessLogic; using Centron.BusinessLogic.Administration; using Centron.BusinessLogic.Administration.Settings; using Centron.BusinessLogic.DocuBoard; using Centron.BusinessLogic.EmployeeArea; using Centron.Data.Entities.Administration.Logins; using Centron.Data.Entities.DocuBoard; using Centron.Tests.EndToEnd.Infrastructure; using CentronSoftware.Centron.WebServices.Entities.Administration.Updates; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.UpdateAvailableNotification { public class UpdateAvailableNotificationTest : EndToEndTest { public UpdateAvailableNotificationTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { this.PreparePackagesTable(); // Now there is only the c-entron.NET package in the database // It has 2 versions: // 2.0.2004.4 // 2.0.2005.22 const int CurrentAppUserI3D = 11; const int CurrentEmployeeI3D = 22; const int OtherAppUserI3D = 14; // Test ShowToAllEmployees this.UpdateSettings(UpdateAvailableNotificationKind.ShowToAllEmployees, null); this.TestAvailableUpdates("ShowToAllEmployeesCurrentVersion1_0_0_0", "1.0.0.0", CurrentAppUserI3D); // Test NoNotification this.UpdateSettings(UpdateAvailableNotificationKind.NoNotification, null); this.TestAvailableUpdates("NoNotification", "1.0.0.0", CurrentAppUserI3D); // Test ShowToSelectedEmployees this.UpdateSettings(UpdateAvailableNotificationKind.ShowToSelectedEmployees, new List { CurrentEmployeeI3D }); this.TestAvailableUpdates("CurrentVersionIsSuperOldUpdateExpected", "1.0.0.0", CurrentAppUserI3D); this.TestAvailableUpdates("CurrentVersionIsOld2002UpdateExpected", "2.0.2002.0", CurrentAppUserI3D); this.TestAvailableUpdates("CurrentVersionIsOld2004UpdateExpected", "2.0.2004.0", CurrentAppUserI3D); this.TestAvailableUpdates("CurrentVersionIsOld2005UpdateExpected", "2.0.2005.0", CurrentAppUserI3D); this.TestAvailableUpdates("CurrentVersionIsNew2006NoUpdateExpected", "2.0.2006.0", CurrentAppUserI3D); this.TestAvailableUpdates("OtherUserNoUpdateExpected", "1.0.0.0", OtherAppUserI3D); this.TestAvailableUpdates("OtherApplicationNoUpdateExpected", "2.0.2006.0", CurrentAppUserI3D, UpdateAvailableApplication.CentronDelphi); // Test ShowToAdministrators this.UpdateSettings(UpdateAvailableNotificationKind.ShowToAdministrators, null); this.TestAvailableUpdates("Admin_CurrentVersionIsOld2005UpdateExpected", "2.0.2005.0", CurrentAppUserI3D); this.TestAvailableUpdates("Admin_CurrentVersionIsNew2006NoUpdateExpected", "2.0.2006.0", CurrentAppUserI3D); } private void PreparePackagesTable() { UpdateAvailableNotificationBL.UseAlphaPackages = false; UpdateAvailableNotificationBL.CustomGetPackageVersions = (packageName) => { if (packageName is "c-entron.NET") return new List { Version.Parse("2.0.2004.4"), Version.Parse("2.0.2005.22") }; return new List(); }; } private void TestAvailableUpdates(string name, string currentVersion, int employeeI3D, UpdateAvailableApplication kind = UpdateAvailableApplication.CentronNET) { using (var session = new BLSession()) { var user = session.GetBL().GetAppUser(f => f.I3D == employeeI3D); var updates = session.GetBL().GetAvailableUpdates(kind, currentVersion, new LoggedInUser(user)); this.Verifier.Verify(name, updates); } } private void UpdateSettings(UpdateAvailableNotificationKind kind, List employeeI3Ds) { using (var session = new BLSession()) { session.GetBL().UpdateUpdateAvailableNotificationSettings(new UpdateAvailableNotificationSettingsDTO { EmployeeI3Ds = employeeI3Ds, NotificationKind = kind }); } } } }