using Centron.BusinessLogic; using Centron.BusinessLogic.MyDay; using Centron.Data.Entities.Administration.Logins; using Centron.Interfaces.MyDay; using Centron.Tests.EndToEnd.Infrastructure; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Xunit; using Xunit.Abstractions; using Centron.Interfaces.BL; using CentronSoftware.Centron.WebServices.Entities.MyDay; using Centron.BusinessLogic.Administration.Employees; using Centron.BusinessLogic.WebServices.Employee; using Centron.BusinessLogic.EmployeeArea; using Centron.Data.Entities.EmployeeArea; using Microsoft.Graph.Models.Security; namespace Centron.Tests.EndToEnd.Tests.MyDay { public class MyDayNotificationsTest : EndToEndTest { public MyDayNotificationsTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } private DateTime GetDateTime() { var date = DateTime.Today.AddDays(-1); while (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday) { date = date.AddDays(-1); } return date; } public override void Execute() { this.PrepareDatabase(this.GetLoggedInUser()); this.CheckFinalizeMyDayNotifications(this.GetLoggedInUser(), 1); // Expected: Beside vacation and sicckness has also work item "Meeting" and no finalized day -> Notification this.UpdateDatabase(this.GetLoggedInUser(34)); this.CheckFinalizeMyDayNotifications(this.GetLoggedInUser(34), 0); // Expected: Only items for vacation and sickness -> No Notification // Addes test case for Ticket 157349 // Before: MyDayFinalizedDay was only recognized if it was saved between 0:00:00 and 23:59:59 on the last working day. // Now: MyDayFinalizedDay is recognized when it is saved between 0:00:00 a.m. on the last working day and immediately before the notification check. this.LateFinalizeMyDayBooking(this.GetLoggedInUser()); this.CheckFinalizeMyDayNotifications(this.GetLoggedInUser(), 0); // Expcted: Finalized day just in time for the work item "Meeting" -> No Notification } private void PrepareDatabase(LoggedInUser loggedInUser) { using (var session = new BLSession()) { var settings = session.GetBL().GetSettings().ThrowIfError(); settings.SendDayNotFinalizedNotifications = true; session.GetBL().UpdateSettings(settings).ThrowIfError(); session.GetBL().SaveOrUpdateWorkItem(new MyDayWorkItemDTO { StartTime = this.GetDateTime().AddHours(8), EndTime = this.GetDateTime().AddHours(17), BreakTime = TimeSpan.FromHours(1), EmployeeI3D = loggedInUser.User.Employee.I3D, Caption = "Sickness", Type = MyDayWorkItemType.Sickness, ShowInTimeLine = true }).ThrowIfError(); session.GetBL().SaveOrUpdateWorkItem(new MyDayWorkItemDTO { StartTime = this.GetDateTime().AddHours(8), EndTime = this.GetDateTime().AddHours(17), BreakTime = TimeSpan.FromHours(1), EmployeeI3D = loggedInUser.User.Employee.I3D, Caption = "Vacation", Type = MyDayWorkItemType.Vacation, ShowInTimeLine = true }).ThrowIfError(); session.GetBL().SaveOrUpdateWorkItem(new MyDayWorkItemDTO { StartTime = this.GetDateTime().AddHours(8), EndTime = this.GetDateTime().AddHours(17), BreakTime = TimeSpan.FromHours(1), EmployeeI3D = loggedInUser.User.Employee.I3D, Caption = "Meeting", Type = MyDayWorkItemType.Meeting, ShowInTimeLine = true }).ThrowIfError(); var result = session.GetBL().GetEmployeeDepartments2(loggedInUser.User).ThrowIfError(); var employeeDepartment = result.FirstOrDefault(); employeeDepartment.MyDayBegin = this.GetDateTime().AddHours(8); employeeDepartment.IsMyDayActive = true; session.GetBL().UpdateEmployeeDepartments(loggedInUser.User, result).ThrowIfError(); } } private void UpdateDatabase(LoggedInUser loggedInUser) { using (var session = new BLSession()) { var settings = session.GetBL().GetSettings().ThrowIfError(); settings.SendDayNotFinalizedNotifications = true; session.GetBL().UpdateSettings(settings).ThrowIfError(); session.GetBL().SaveOrUpdateWorkItem(new MyDayWorkItemDTO { StartTime = this.GetDateTime().AddHours(8), EndTime = this.GetDateTime().AddHours(17), BreakTime = TimeSpan.FromHours(1), EmployeeI3D = loggedInUser.User.Employee.I3D, Caption = "Sickness", Type = MyDayWorkItemType.Sickness, ShowInTimeLine = true }).ThrowIfError(); session.GetBL().SaveOrUpdateWorkItem(new MyDayWorkItemDTO { StartTime = this.GetDateTime().AddHours(8), EndTime = this.GetDateTime().AddHours(17), BreakTime = TimeSpan.FromHours(1), EmployeeI3D = loggedInUser.User.Employee.I3D, Caption = "Vacation", Type = MyDayWorkItemType.Vacation, ShowInTimeLine = true }).ThrowIfError(); var result = session.GetBL().GetEmployeeDepartments2(loggedInUser.User).ThrowIfError(); var employeeDepartment = result.FirstOrDefault(); employeeDepartment.MyDayBegin = this.GetDateTime().AddHours(8); employeeDepartment.IsMyDayActive = true; session.GetBL().UpdateEmployeeDepartments(loggedInUser.User, result).ThrowIfError(); } } private void CheckFinalizeMyDayNotifications(LoggedInUser loggedInUser, int expectedNotificationCount) { using (var session = new BLSession()) { var notifications = session.GetBL().GetCurrentNotificationsToSend(); Assert.True(notifications.Where(f => f.EmployeeI3D == loggedInUser.User.Employee.I3D).Count() == expectedNotificationCount); } } private void LateFinalizeMyDayBooking(LoggedInUser loggedInUser) { using (var session = new BLSession()) { session.GetBL().SaveOrUpdateFinalizedDay(new MyDayFinalizedDayDTO { EmployeeI3D = loggedInUser.User.Employee.I3D, Date = DateTime.Now.AddMinutes(-1), Comment = "Sorry forgot to do that yesterday!" }).ThrowIfError(); } } } }