using System.Collections.Generic; using Centron.BusinessLogic.Administration.Rights; using Centron.BusinessLogic.WebServices.CheckListArea; using Centron.Data.Entities.Administration; using Centron.Data.Entities.Administration.Logins; using Centron.Data.Entities.ChecklistArea; using Centron.Data.Entities.EmployeeArea; using Centron.Data.WebServices.Administration.Employees; using Centron.Interfaces.ChecklistArea; using CentronSoftware.Centron.WebServices.Entities.CentronChecklist; using Xunit; namespace Centron.Tests.EndToEnd.Tests.Checklists; public class ChecklistItemEditAccessTest { [Fact] public void IsChecklistItemEditAllowed_ShouldReturnFalse_ForNullUser() { // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(null, null, null); // Assert Assert.False(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnTrue_ForAdminUser() { // Arrange var appUser = new AppUser{ Groups = new List()}; appUser.Groups.Add(new AppGroup{ Name = UserRightsConst.ADMIN_ACCOUNT }); var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO(); // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, null, loggedInUser); // Assert Assert.True(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnFalse_ForNonAdminUserWithDifferentEditor() { // Arrange var appUser = new AppUser{ Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = new EmployeePreviewDTO { I3D = 2 } }; var checklistItemEntity = new CentronChecklistItem { Editor = new Employee { I3D = 2 } }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.False(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnTrue_ForNonAdminUserWithSameEditor() { // Arrange var appUser = new AppUser{ Employee = new EmployeeCompact { I3D = 2 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = new EmployeePreviewDTO { I3D = 2 } }; var checklistItemEntity = new CentronChecklistItem { Editor = new Employee { I3D = 2 } }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.True(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnTrue_ForNullChecklistItemEntity() { // Arrange var appUser = new AppUser { Groups = new List() }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO(); // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, null, loggedInUser); // Assert Assert.True(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnTrue_ForAdHocItemCreatedByLoggedInUser() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { AdHocCreatedBy = new EmployeePreviewDTO { I3D = 1 } }; var checklistItemEntity = new CentronChecklistItem { AdHocCreatedBy = new Employee { I3D = 1 } }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.True(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnFalse_ForAdHocItemNotCreatedByLoggedInUser() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { AdHocCreatedBy = new EmployeePreviewDTO { I3D = 2 } }; var checklistItemEntity = new CentronChecklistItem { AdHocCreatedBy = new Employee { I3D = 2 } }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.False(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnFalse_ForTemplateItemWithDifferentEditor() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = new EmployeePreviewDTO { I3D = 2 } }; var checklistItemEntity = new CentronChecklistItem { Editor = new Employee { I3D = 2 } }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.False(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnTrue_ForTemplateItemWithSameEditorStateChange() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = new EmployeePreviewDTO { I3D = 1 }, State = CentronChecklistItemState.Finished }; var checklistItemEntity = new CentronChecklistItem { Editor = new Employee { I3D = 1 }, State = CentronChecklistItemState.Open }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.True(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnFalse_ForTemplateItemWithSameEditorCaptionChange() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = new EmployeePreviewDTO { I3D = 1 }, Caption = "Test" }; var checklistItemEntity = new CentronChecklistItem { Editor = new Employee { I3D = 1 }, Caption = "Changed" }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.False(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnFalse_ForTemplateItemWithSameEditorDescriptionChange() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = new EmployeePreviewDTO { I3D = 1 }, Description = "Test" }; var checklistItemEntity = new CentronChecklistItem { Editor = new Employee { I3D = 1 }, Description = "Changed" }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.False(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnFalse_ForTemplateItemWithSameEditorDurationChange() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = new EmployeePreviewDTO { I3D = 1 }, DurationTime = 10 }; var checklistItemEntity = new CentronChecklistItem { Editor = new Employee { I3D = 1 }, DurationTime = 0 }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.False(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnTrue_ForTemplateItemWithNullEditorStateChange() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = null, State = CentronChecklistItemState.Finished }; var checklistItemEntity = new CentronChecklistItem { Editor = null, State = CentronChecklistItemState.Open }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.True(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnFalse_ForTemplateItemWithNullEditorCaptionChange() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = null, Caption = "Test" }; var checklistItemEntity = new CentronChecklistItem { Editor = null, Caption = "Changed" }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.False(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnFalse_ForTemplateItemWithNullEditorDescriptionChange() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = null, Description = "Test" }; var checklistItemEntity = new CentronChecklistItem { Editor = null, Description = "Changed" }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.False(result.Item1); } [Fact] public void IsChecklistItemEditAllowed_ShouldReturnFalse_ForTemplateItemWithNullEditorDurationChange() { // Arrange var appUser = new AppUser { Employee = new EmployeeCompact { I3D = 1 } }; var loggedInUser = new LoggedInUser(appUser); var checklistItemDTO = new CentronChecklistItemDTO { Editor = null, DurationTime = 10 }; var checklistItemEntity = new CentronChecklistItem { Editor = null, DurationTime = 0 }; // Act var result = CentronChecklistWebserviceBL.IsChecklistItemEditAllowed(checklistItemDTO, checklistItemEntity, loggedInUser); // Assert Assert.False(result.Item1); } }