using System; using System.Collections.Generic; using System.Linq; using Xunit.Abstractions; using Centron.Tests.EndToEnd.Infrastructure; using Centron.BusinessLogic; using Centron.BusinessLogic.MyDay; using Centron.Data.WebServices.Sales.Support; using Centron.BusinessLogic.WebServices.Sales.Support; using Centron.Data.Entities.Administration.Logins; using Centron.BusinessLogic.EmployeeArea; using Centron.BusinessLogic.WebServices.Administration.MasterData; using Centron.Interfaces.MyDay; using Centron.Data.Entities.Tapi; using Centron.BusinessLogic.Tapi; using Centron.BusinessLogic.WebServices.MyCentron; using CentronSoftware.Centron.WebServices.Entities.MyDay; using Centron.Data.Entities.MyCentron; using Centron.Interfaces; using Centron.Interfaces.BL; using Centron.Core.Extensions; namespace Centron.Tests.EndToEnd.Tests.MyDay { public class MyDayTests : EndToEndTest { private LoggedInUser GetUser(BLSession session) => new LoggedInUser(session.GetBL().GetAppUser(f => f.I3D == 11)); private LoggedInUser GetUser() { using (var session = new BLSession()) return new LoggedInUser(session.GetBL().GetAppUser(f => f.I3D == 11)); } private readonly int _referenceCustomerI3D = 10000; private DateTime _baseDate => new DateTime(2020, 1, 1); public MyDayTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { this.Verifier.Settings.IgnoreProperty(f => f.CreatedVersion); } public override void Execute() { return; // this.PrepareDatabase(); // // this.GetSettings(); // this.UpdateSettings(); // // this.GetNewWorkItems(); // this.SaveTimeLine(); // this.GetWorkItems(); // this.GetWorkItemByI3D(); } private void PrepareDatabase() { using (var session = new BLSession()) { var user = this.GetUser(session); var employee = session.GetBL().GetEmployeePreviews(new List { user.User.Employee.I3D }).ThrowIfError().First(); var helpdeskI3D = 10491; session.GetBL().SaveHelpdeskTimer(new HelpdeskTimerDTO { Start = this._baseDate.AddHours(8), Stop = this._baseDate.AddHours(9), Employee = employee, InternalNote = "Internal note 1", ExternalNote = "External note 1", HelpdeskI3D = helpdeskI3D }, user); session.GetBL().SaveHelpdeskTimer(new HelpdeskTimerDTO { Start = this._baseDate.AddHours(13), Stop = this._baseDate.AddHours(15), Employee = employee, InternalNote = "Internal note 2", ExternalNote = "External note 2", HelpdeskI3D = helpdeskI3D, Calculable = true }, user); session.GetBL().SaveOrUpdateCall(new PhoneCall { StartTime = this._baseDate.AddHours(9), EndTime = this._baseDate.AddHours(10.5), CallerNumber = "1234", CallerName = "CallerName", WasConnected = true, OwnerI3D = 72, OwnerKind = CentronObjectKindNumeric.ContactPerson }, user.User); session.GetBL().AddComplete(user.User, LatestUsedCentronObjectKind.Customer, CentronObjectKindNumeric.Account, this._referenceCustomerI3D, "Worked on customer " + this._referenceCustomerI3D, this._baseDate.AddHours(14), this._baseDate.AddHours(16)); } } private void GetSettings() { var settings = this.GetSettingsInternal(); this.Verifier.Verify("Settings", settings); } private void UpdateSettings() { using (var session = new BLSession()) { var settings = this.GetSettingsInternal(); settings.EditPeriod = 20; settings.WorkTimeStart = TimeSpan.FromHours(15); settings.WorkTimeEnd = TimeSpan.FromHours(18); settings.BreakDuration = TimeSpan.FromHours(1.5); settings.SpecialTimeSettings = new List { new MyDaySpecialTimeSettingDTO { BreakDuration = TimeSpan.FromHours(1), WorkTimeStart = TimeSpan.FromHours(7), WorkTimeEnd = TimeSpan.FromHours(20), Employees = new List { new MyDaySpecialTimeSettingAssignmentDTO { EmployeeI3D = this.GetUser(session).User.Employee.I3D } } } }; settings.SendDayNotFinalizedNotifications = true; settings.DayNotFinalizedNotificationSendTime = TimeSpan.FromHours(20); session.GetBL().UpdateSettings(settings).ThrowIfError(); var updatedSettings = this.GetSettingsInternal(); this.Verifier.Verify("UpdatedSettings", updatedSettings); } } private MyDaySettingsDTO GetSettingsInternal() { using (var session = new BLSession()) { return session.GetBL().GetSettings().ThrowIfError(); } } private void GetNewWorkItems() { var newWorkItems = this.GetNewWorkItemsInternal(); this.Verifier.Verify("NewWorkItems", newWorkItems); } private void SaveTimeLine() { var workItems = this.GetNewWorkItemsInternal(); workItems.Add(new MyDayWorkItemDTO { BreakTime = TimeSpan.FromHours(1), StartTime = this._baseDate.AddHours(20), EndTime = this._baseDate.AddHours(22), Caption = "I am a caption", EmployeeI3D = this.GetUser().User.Employee.I3D, Type = MyDayWorkItemType.Other, ShowInTimeLine = true }); foreach (var currentWorkItem in workItems) { using (var session = new BLSession()) { session.GetBL().SaveOrUpdateWorkItem(currentWorkItem).ThrowIfError(); } } } private void GetWorkItems() { using (var session = new BLSession()) { var workItems = session.GetBL().GetWorkItems(new MyDayWorkItemsFilter { EmployeeI3Ds = new List { this.GetUser(session).User.Employee.I3D }, StarTime = this._baseDate.StartOfDay(), EndTime = this._baseDate.EndOfDay(), IncludeItemsNotShownInTimeLine = true }, this.GetUser(session)).ThrowIfError(); this.Verifier.Verify("WorkItems", workItems.OrderBy(o => o.I3D)); } } private IList GetNewWorkItemsInternal() { using (var session = new BLSession()) { return session .GetBL() .GetNewWorkItems(new MyDayWorkItemsFilter { EmployeeI3Ds = new List { this.GetUser(session).User.Employee.I3D }, StarTime = this._baseDate.StartOfDay(), EndTime = this._baseDate.EndOfDay() }, this.GetUser(session)).ThrowIfError(); } } private void GetWorkItemByI3D() { using (var session = new BLSession()) { var workItem = session.GetBL().GetWorkItemByI3D(5).ThrowIfError(); this.Verifier.Verify("WorkItemByI3D", workItem); } } } }