public void CaseTemplateUploadedData_Delete_DoesSetWorkflowStateToRemoved() { //Arrange short shortMin = Int16.MinValue; short shortMax = Int16.MaxValue; Random rnd = new Random(); bool randomBool = rnd.Next(0, 2) > 0; CaseTemplate caseTemplate = new CaseTemplate(); caseTemplate.Approvable = randomBool; caseTemplate.Body = Guid.NewGuid().ToString(); caseTemplate.Title = Guid.NewGuid().ToString(); caseTemplate.AlwaysShow = randomBool; caseTemplate.EndAt = DateTime.Now; caseTemplate.PdfTitle = Guid.NewGuid().ToString(); caseTemplate.StartAt = DateTime.Now; caseTemplate.DescriptionFolderId = rnd.Next(1, 200); caseTemplate.RetractIfApproved = randomBool; caseTemplate.Create(DbContext); UploadedData uploadedData = new UploadedData(); uploadedData.Checksum = Guid.NewGuid().ToString(); uploadedData.Extension = Guid.NewGuid().ToString(); uploadedData.Local = (short)rnd.Next(shortMin, shortMax); uploadedData.CurrentFile = Guid.NewGuid().ToString(); uploadedData.ExpirationDate = DateTime.Now; uploadedData.FileLocation = Guid.NewGuid().ToString(); uploadedData.FileName = Guid.NewGuid().ToString(); uploadedData.UploaderType = Guid.NewGuid().ToString(); uploadedData.OriginalFileName = Guid.NewGuid().ToString(); uploadedData.Create(DbContext); CaseTemplateUploadedData caseTemplateUploadedData = new CaseTemplateUploadedData(); caseTemplateUploadedData.Approvable = randomBool; caseTemplateUploadedData.Title = Guid.NewGuid().ToString(); caseTemplateUploadedData.CaseTemplateId = caseTemplate.Id; caseTemplateUploadedData.RetractIfApproved = randomBool; caseTemplateUploadedData.UploadedDataId = uploadedData.Id; caseTemplateUploadedData.Create(DbContext); //Act DateTime?oldUpdatedAt = caseTemplateUploadedData.UpdatedAt; caseTemplateUploadedData.Delete(DbContext); List <CaseTemplateUploadedData> dbCaseTemplateUploadedDatas = DbContext.CaseTemplateUploadedDatas.AsNoTracking().ToList(); List <CaseTemplateUploadedDataVersion> dbCaseTemplateUploadedDataVersions = DbContext.CaseTemplateUploadedDataVersions.AsNoTracking().ToList(); //Assert Assert.NotNull(dbCaseTemplateUploadedDatas); Assert.NotNull(dbCaseTemplateUploadedDataVersions); Assert.AreEqual(1, dbCaseTemplateUploadedDatas.Count); Assert.AreEqual(2, dbCaseTemplateUploadedDataVersions.Count); Assert.AreEqual(caseTemplateUploadedData.Id, dbCaseTemplateUploadedDatas[0].Id); Assert.AreEqual(caseTemplateUploadedData.Version, dbCaseTemplateUploadedDatas[0].Version); Assert.AreEqual(caseTemplateUploadedData.CreatedAt.ToString(), dbCaseTemplateUploadedDatas[0].CreatedAt.ToString()); Assert.AreEqual(caseTemplateUploadedData.UpdatedAt.ToString(), dbCaseTemplateUploadedDatas[0].UpdatedAt.ToString()); Assert.AreEqual(caseTemplateUploadedData.CreatedByUserId, dbCaseTemplateUploadedDatas[0].CreatedByUserId); Assert.AreEqual(caseTemplateUploadedData.UpdatedByUserId, dbCaseTemplateUploadedDatas[0].UpdatedByUserId); Assert.AreEqual(Constants.WorkflowStates.Removed, dbCaseTemplateUploadedDatas[0].WorkflowState); Assert.AreEqual(caseTemplateUploadedData.Approvable, dbCaseTemplateUploadedDatas[0].Approvable); Assert.AreEqual(caseTemplateUploadedData.Title, dbCaseTemplateUploadedDatas[0].Title); Assert.AreEqual(caseTemplate.Id, dbCaseTemplateUploadedDatas[0].CaseTemplateId); Assert.AreEqual(uploadedData.Id, dbCaseTemplateUploadedDatas[0].UploadedDataId); Assert.AreEqual(caseTemplateUploadedData.RetractIfApproved, dbCaseTemplateUploadedDatas[0].RetractIfApproved); //Old Version Assert.AreEqual(caseTemplateUploadedData.Id, dbCaseTemplateUploadedDataVersions[0].Id); Assert.AreEqual(1, dbCaseTemplateUploadedDataVersions[0].Version); Assert.AreEqual(caseTemplateUploadedData.CreatedAt.ToString(), dbCaseTemplateUploadedDataVersions[0].CreatedAt.ToString()); Assert.AreEqual(oldUpdatedAt.ToString(), dbCaseTemplateUploadedDataVersions[0].UpdatedAt.ToString()); Assert.AreEqual(caseTemplateUploadedData.CreatedByUserId, dbCaseTemplateUploadedDataVersions[0].CreatedByUserId); Assert.AreEqual(caseTemplateUploadedData.UpdatedByUserId, dbCaseTemplateUploadedDataVersions[0].UpdatedByUserId); Assert.AreEqual(Constants.WorkflowStates.Created, dbCaseTemplateUploadedDataVersions[0].WorkflowState); Assert.AreEqual(caseTemplateUploadedData.Approvable, dbCaseTemplateUploadedDataVersions[0].Approvable); Assert.AreEqual(caseTemplateUploadedData.Title, dbCaseTemplateUploadedDataVersions[0].Title); Assert.AreEqual(caseTemplate.Id, dbCaseTemplateUploadedDataVersions[0].CaseTemplateId); Assert.AreEqual(uploadedData.Id, dbCaseTemplateUploadedDataVersions[0].UploadedDataId); Assert.AreEqual(caseTemplateUploadedData.RetractIfApproved, dbCaseTemplateUploadedDataVersions[0].RetractIfApproved); //New Version Assert.AreEqual(caseTemplateUploadedData.Id, dbCaseTemplateUploadedDataVersions[1].CaseTemplateUploadedDataId); Assert.AreEqual(2, dbCaseTemplateUploadedDataVersions[1].Version); Assert.AreEqual(caseTemplateUploadedData.CreatedAt.ToString(), dbCaseTemplateUploadedDataVersions[1].CreatedAt.ToString()); Assert.AreEqual(caseTemplateUploadedData.UpdatedAt.ToString(), dbCaseTemplateUploadedDataVersions[1].UpdatedAt.ToString()); Assert.AreEqual(caseTemplateUploadedData.CreatedByUserId, dbCaseTemplateUploadedDataVersions[1].CreatedByUserId); Assert.AreEqual(caseTemplateUploadedData.UpdatedByUserId, dbCaseTemplateUploadedDataVersions[1].UpdatedByUserId); Assert.AreEqual(Constants.WorkflowStates.Removed, dbCaseTemplateUploadedDataVersions[1].WorkflowState); Assert.AreEqual(caseTemplateUploadedData.Approvable, dbCaseTemplateUploadedDataVersions[1].Approvable); Assert.AreEqual(caseTemplateUploadedData.Title, dbCaseTemplateUploadedDataVersions[1].Title); Assert.AreEqual(caseTemplate.Id, dbCaseTemplateUploadedDataVersions[1].CaseTemplateId); Assert.AreEqual(uploadedData.Id, dbCaseTemplateUploadedDataVersions[1].UploadedDataId); Assert.AreEqual(caseTemplateUploadedData.RetractIfApproved, dbCaseTemplateUploadedDataVersions[1].RetractIfApproved); }
public void CaseTemplates_Update_DoesUpdate() { //Arrange Random rnd = new Random(); bool randomBool = rnd.Next(0, 2) > 0; CaseTemplate caseTemplate = new CaseTemplate(); caseTemplate.Approvable = randomBool; caseTemplate.Body = Guid.NewGuid().ToString(); caseTemplate.Title = Guid.NewGuid().ToString(); caseTemplate.AlwaysShow = randomBool; caseTemplate.EndAt = DateTime.Now; caseTemplate.PdfTitle = Guid.NewGuid().ToString(); caseTemplate.StartAt = DateTime.Now; caseTemplate.DescriptionFolderId = rnd.Next(1, 200); caseTemplate.RetractIfApproved = randomBool; caseTemplate.Create(DbContext); //Act DateTime?oldUpdatedAt = caseTemplate.UpdatedAt; bool oldApprovable = caseTemplate.Approvable; string oldBody = caseTemplate.Body; string oldTitle = caseTemplate.Title; bool oldAlwaysShow = caseTemplate.AlwaysShow; DateTime oldEndAt = caseTemplate.EndAt; string oldPdfTitle = caseTemplate.PdfTitle; DateTime oldStartAt = caseTemplate.StartAt; int oldDescriptionFolderId = caseTemplate.DescriptionFolderId; bool oldRetractIfApproved = caseTemplate.RetractIfApproved; caseTemplate.Approvable = randomBool; caseTemplate.Body = Guid.NewGuid().ToString(); caseTemplate.Title = Guid.NewGuid().ToString(); caseTemplate.AlwaysShow = randomBool; caseTemplate.EndAt = DateTime.Now; caseTemplate.PdfTitle = Guid.NewGuid().ToString(); caseTemplate.StartAt = DateTime.Now; caseTemplate.DescriptionFolderId = rnd.Next(1, 200); caseTemplate.RetractIfApproved = randomBool; caseTemplate.Update(DbContext); List <CaseTemplate> dbCaseTemplates = DbContext.CaseTemplates.AsNoTracking().ToList(); List <CaseTemplateVersion> dbCaseTemplateVersions = DbContext.CaseTemplateVersions.AsNoTracking().ToList(); //Assert Assert.NotNull(dbCaseTemplates); Assert.NotNull(dbCaseTemplateVersions); Assert.AreEqual(1, dbCaseTemplates.Count); Assert.AreEqual(2, dbCaseTemplateVersions.Count); Assert.AreEqual(caseTemplate.Id, dbCaseTemplates[0].Id); Assert.AreEqual(caseTemplate.Version, dbCaseTemplates[0].Version); Assert.AreEqual(caseTemplate.CreatedAt.ToString(), dbCaseTemplates[0].CreatedAt.ToString()); Assert.AreEqual(caseTemplate.UpdatedAt.ToString(), dbCaseTemplates[0].UpdatedAt.ToString()); Assert.AreEqual(caseTemplate.CreatedByUserId, dbCaseTemplates[0].CreatedByUserId); Assert.AreEqual(caseTemplate.UpdatedByUserId, dbCaseTemplates[0].UpdatedByUserId); Assert.AreEqual(Constants.WorkflowStates.Created, dbCaseTemplates[0].WorkflowState); Assert.AreEqual(caseTemplate.Approvable, dbCaseTemplates[0].Approvable); Assert.AreEqual(caseTemplate.Body, dbCaseTemplates[0].Body); Assert.AreEqual(caseTemplate.Title, dbCaseTemplates[0].Title); Assert.AreEqual(caseTemplate.AlwaysShow, dbCaseTemplates[0].AlwaysShow); Assert.AreEqual(caseTemplate.EndAt.ToString(), dbCaseTemplates[0].EndAt.ToString()); Assert.AreEqual(caseTemplate.PdfTitle, dbCaseTemplates[0].PdfTitle); Assert.AreEqual(caseTemplate.StartAt.ToString(), dbCaseTemplates[0].StartAt.ToString()); Assert.AreEqual(caseTemplate.DescriptionFolderId, dbCaseTemplates[0].DescriptionFolderId); Assert.AreEqual(caseTemplate.RetractIfApproved, dbCaseTemplates[0].RetractIfApproved); //Old Version Assert.AreEqual(caseTemplate.Id, dbCaseTemplateVersions[0].CaseTemplateId); Assert.AreEqual(1, dbCaseTemplateVersions[0].Version); Assert.AreEqual(caseTemplate.CreatedAt.ToString(), dbCaseTemplateVersions[0].CreatedAt.ToString()); Assert.AreEqual(oldUpdatedAt.ToString(), dbCaseTemplateVersions[0].UpdatedAt.ToString()); Assert.AreEqual(caseTemplate.CreatedByUserId, dbCaseTemplateVersions[0].CreatedByUserId); Assert.AreEqual(caseTemplate.UpdatedByUserId, dbCaseTemplateVersions[0].UpdatedByUserId); Assert.AreEqual(Constants.WorkflowStates.Created, dbCaseTemplateVersions[0].WorkflowState); Assert.AreEqual(oldApprovable, dbCaseTemplateVersions[0].Approvable); Assert.AreEqual(oldBody, dbCaseTemplateVersions[0].Body); Assert.AreEqual(oldTitle, dbCaseTemplateVersions[0].Title); Assert.AreEqual(oldAlwaysShow, dbCaseTemplateVersions[0].AlwaysShow); Assert.AreEqual(oldEndAt.ToString(), dbCaseTemplateVersions[0].EndAt.ToString()); Assert.AreEqual(oldPdfTitle, dbCaseTemplateVersions[0].PdfTitle); Assert.AreEqual(oldStartAt.ToString(), dbCaseTemplateVersions[0].StartAt.ToString()); Assert.AreEqual(oldDescriptionFolderId, dbCaseTemplateVersions[0].DescriptionFolderId); Assert.AreEqual(oldRetractIfApproved, dbCaseTemplateVersions[0].RetractIfApproved); //New Version Assert.AreEqual(caseTemplate.Id, dbCaseTemplateVersions[1].CaseTemplateId); Assert.AreEqual(2, dbCaseTemplateVersions[1].Version); Assert.AreEqual(caseTemplate.CreatedAt.ToString(), dbCaseTemplateVersions[1].CreatedAt.ToString()); Assert.AreEqual(caseTemplate.UpdatedAt.ToString(), dbCaseTemplateVersions[1].UpdatedAt.ToString()); Assert.AreEqual(caseTemplate.CreatedByUserId, dbCaseTemplateVersions[1].CreatedByUserId); Assert.AreEqual(caseTemplate.UpdatedByUserId, dbCaseTemplateVersions[1].UpdatedByUserId); Assert.AreEqual(Constants.WorkflowStates.Created, dbCaseTemplateVersions[1].WorkflowState); Assert.AreEqual(caseTemplate.Approvable, dbCaseTemplateVersions[1].Approvable); Assert.AreEqual(caseTemplate.Body, dbCaseTemplateVersions[1].Body); Assert.AreEqual(caseTemplate.Title, dbCaseTemplateVersions[1].Title); Assert.AreEqual(caseTemplate.AlwaysShow, dbCaseTemplateVersions[1].AlwaysShow); Assert.AreEqual(caseTemplate.EndAt.ToString(), dbCaseTemplateVersions[1].EndAt.ToString()); Assert.AreEqual(caseTemplate.PdfTitle, dbCaseTemplateVersions[1].PdfTitle); Assert.AreEqual(caseTemplate.StartAt.ToString(), dbCaseTemplateVersions[1].StartAt.ToString()); Assert.AreEqual(caseTemplate.DescriptionFolderId, dbCaseTemplateVersions[1].DescriptionFolderId); Assert.AreEqual(caseTemplate.RetractIfApproved, dbCaseTemplateVersions[1].RetractIfApproved); }
public void Cases_Update_DoesUpdate() { #region Arrange Random rnd = new Random(); bool randomBool = rnd.Next(0, 2) > 0; CaseTemplate caseTemplate = new CaseTemplate(); caseTemplate.Approvable = randomBool; caseTemplate.Body = Guid.NewGuid().ToString(); caseTemplate.Title = Guid.NewGuid().ToString(); caseTemplate.AlwaysShow = randomBool; caseTemplate.EndAt = DateTime.Now; caseTemplate.PdfTitle = Guid.NewGuid().ToString(); caseTemplate.StartAt = DateTime.Now; caseTemplate.DescriptionFolderId = rnd.Next(0, 255); caseTemplate.RetractIfApproved = randomBool; caseTemplate.Create(DbContext); Case @case = new Case(); @case.Status = rnd.Next(0, 255); @case.Type = Guid.NewGuid().ToString(); @case.DoneAt = DateTime.Now; @case.eFormId = rnd.Next(0, 255); @case.SiteId = rnd.Next(0, 255); @case.UnitId = rnd.Next(0, 255); @case.WorkerId = rnd.Next(0, 255); @case.CaseTemplateId = caseTemplate.Id; @case.FetchedByTablet = randomBool; @case.FetchedByTabletAt = DateTime.Now; @case.ReceiptRetrievedFromUser = randomBool; @case.ReceiptRetrievedFromUserAt = DateTime.Now; @case.Create(DbContext); #endregion //Act DateTime?oldUpdatedAt = @case.UpdatedAt; DateTime?oldDoneAt = @case.DoneAt; int? oldStatus = @case.Status; string oldType = @case.Type; int? oldeFormId = @case.eFormId; int? oldSiteId = @case.SiteId; int? oldUnitId = @case.UnitId; int? oldWorkerId = @case.WorkerId; bool oldFetchedByTablet = @case.FetchedByTablet; bool oldReceiptRetrievedFromUser = @case.ReceiptRetrievedFromUser; DateTime?oldFetchedByTabletAt = @case.FetchedByTabletAt; DateTime?oldReceiptRetrievedFromUserAt = @case.ReceiptRetrievedFromUserAt; @case.Status = rnd.Next(0, 255); @case.Type = Guid.NewGuid().ToString(); @case.DoneAt = DateTime.Now; @case.eFormId = rnd.Next(0, 255); @case.SiteId = rnd.Next(0, 255); @case.UnitId = rnd.Next(0, 255); @case.WorkerId = rnd.Next(0, 255); @case.FetchedByTablet = randomBool; @case.FetchedByTabletAt = DateTime.Now.AddDays(1); @case.ReceiptRetrievedFromUser = randomBool; @case.ReceiptRetrievedFromUserAt = DateTime.Now.AddDays(1); @case.Update(DbContext); List <Case> dbCases = DbContext.Cases.AsNoTracking().ToList(); List <CaseVersion> dbCaseVersions = DbContext.CaseVersions.AsNoTracking().ToList(); //Assert Assert.NotNull(dbCases); Assert.NotNull(dbCaseVersions); Assert.AreEqual(1, dbCases.Count); Assert.AreEqual(2, dbCaseVersions.Count); Assert.AreEqual(@case.Status, dbCases[0].Status); Assert.AreEqual(@case.Type, dbCases[0].Type); Assert.AreEqual(@case.DoneAt.ToString(), dbCases[0].DoneAt.ToString()); Assert.AreEqual(@case.eFormId, dbCases[0].eFormId); Assert.AreEqual(@case.SiteId, dbCases[0].SiteId); Assert.AreEqual(@case.UnitId, dbCases[0].UnitId); Assert.AreEqual(@case.WorkerId, dbCases[0].WorkerId); Assert.AreEqual(caseTemplate.Id, dbCases[0].CaseTemplateId); Assert.AreEqual(@case.FetchedByTablet, dbCases[0].FetchedByTablet); Assert.AreEqual(@case.FetchedByTabletAt.ToString(), dbCases[0].FetchedByTabletAt.ToString()); Assert.AreEqual(@case.ReceiptRetrievedFromUser, dbCases[0].ReceiptRetrievedFromUser); Assert.AreEqual(@case.ReceiptRetrievedFromUserAt.ToString(), dbCases[0].ReceiptRetrievedFromUserAt.ToString()); Assert.AreEqual(Constants.WorkflowStates.Created, dbCases[0].WorkflowState); //Old version Assert.AreEqual(oldStatus, dbCaseVersions[0].Status); Assert.AreEqual(oldType, dbCaseVersions[0].Type); Assert.AreEqual(oldUpdatedAt.ToString(), dbCaseVersions[0].UpdatedAt.ToString()); Assert.AreEqual(@case.DoneAt.ToString(), dbCaseVersions[0].DoneAt.ToString()); Assert.AreEqual(oldeFormId, dbCaseVersions[0].eFormId); Assert.AreEqual(oldSiteId, dbCaseVersions[0].SiteId); Assert.AreEqual(oldUnitId, dbCaseVersions[0].UnitId); Assert.AreEqual(oldWorkerId, dbCaseVersions[0].WorkerId); Assert.AreEqual(caseTemplate.Id, dbCaseVersions[0].CaseTemplateId); Assert.AreEqual(oldFetchedByTablet, dbCaseVersions[0].FetchedByTablet); Assert.AreEqual(oldFetchedByTabletAt.ToString(), dbCaseVersions[0].FetchedByTabletAt.ToString()); Assert.AreEqual(oldReceiptRetrievedFromUser, dbCaseVersions[0].ReceiptRetrievedFromUser); Assert.AreEqual(oldReceiptRetrievedFromUserAt.ToString(), dbCaseVersions[0].ReceiptRetrievedFromUserAt.ToString()); Assert.AreEqual(Constants.WorkflowStates.Created, dbCaseVersions[0].WorkflowState); //New Version Assert.AreEqual(@case.Status, dbCaseVersions[1].Status); Assert.AreEqual(@case.Type, dbCaseVersions[1].Type); Assert.AreEqual(@case.UpdatedAt.ToString(), dbCaseVersions[1].UpdatedAt.ToString()); Assert.AreEqual(@case.DoneAt.ToString(), dbCaseVersions[1].DoneAt.ToString()); Assert.AreEqual(@case.eFormId, dbCaseVersions[1].eFormId); Assert.AreEqual(@case.SiteId, dbCaseVersions[1].SiteId); Assert.AreEqual(@case.UnitId, dbCaseVersions[1].UnitId); Assert.AreEqual(@case.WorkerId, dbCaseVersions[1].WorkerId); Assert.AreEqual(caseTemplate.Id, dbCaseVersions[1].CaseTemplateId); Assert.AreEqual(@case.FetchedByTablet, dbCaseVersions[1].FetchedByTablet); Assert.AreEqual(@case.FetchedByTabletAt.ToString(), dbCaseVersions[1].FetchedByTabletAt.ToString()); Assert.AreEqual(@case.ReceiptRetrievedFromUser, dbCaseVersions[1].ReceiptRetrievedFromUser); Assert.AreEqual(@case.ReceiptRetrievedFromUserAt.ToString(), dbCaseVersions[1].ReceiptRetrievedFromUserAt.ToString()); Assert.AreEqual(Constants.WorkflowStates.Created, dbCaseVersions[1].WorkflowState); }
public async Task <OperationResult> CreateCaseTemplate(int id) { try { Core _core = new Core(); _core.StartSqlOnly( "host= localhost;Database=759_SDK;user = root;port=3306;Convert Zero Datetime = true;SslMode=none;"); Dictionary <int, string> laRoutes = new Dictionary <int, string>() { { 24, "Århus H - Aalborg" }, { 25, "Aalborg - Lindholm" } }; string checkSum; DateTime dt = DateTime.Now; var dayofWeek = dt.AddDays(1).ToString("dddd", new System.Globalization.CultureInfo("da-DK")); var dayOfWeek2 = dt.AddDays(2).ToString("dddd", new System.Globalization.CultureInfo("da-DK")); var date = dt.AddDays(1).ToString("dd"); var date2 = dt.AddDays(2).ToString("dd"); var monthOfYear = dt.ToString("MMMM", new System.Globalization.CultureInfo("da-DK")); var year = dt.ToString("yyyy"); string dateFormatted = dt.ToString("-yyyy-MM-dd-yyyy-MM-dd"); string laNumber; string laTitle; foreach (KeyValuePair <int, string> entry in laRoutes) { laNumber = entry.Key.ToString(); laTitle = "La-" + laNumber + dateFormatted; CaseTemplate existingCaseTemplate = await _dbContext.CaseTemplates.SingleOrDefaultAsync(x => x.Title == entry.Value && x.StartAt.ToString("dd-MM-yyyy") == dt.AddDays(1).ToString("dd-MM-yyyy") && x.EndAt.ToString("dd-MM-yyyy") == dt.AddDays(2).ToString("dd-MM-yyyy")); if (existingCaseTemplate == null) { string fileCheckSum = GetLa(laNumber, _core); checkSum = fileCheckSum; MainElement mainElement = _core.TemplateRead(9); mainElement.Repeated = 1; mainElement.Label = $"Banedanmark LA: {entry.Value}"; mainElement.ElementList[0].Label = mainElement.Label; mainElement.ElementList[0].Description = new CDataValue() { InderValue = $"Fra: {dayofWeek} den {date}. {monthOfYear} {year}<br>Til: {dayOfWeek2} den {date2}. {monthOfYear} {year}" }; DataElement dataElement = (DataElement)mainElement.ElementList[0]; dataElement.DataItemList[0].Label = entry.Value; ShowPdf showPdf = (ShowPdf)dataElement.DataItemList[1]; showPdf.Value = fileCheckSum; CaseTemplate newCaseTemplate = new CaseTemplate(); newCaseTemplate.Title = entry.Value; newCaseTemplate.StartAt = dt.AddDays(1); newCaseTemplate.EndAt = dt.AddDays(2); newCaseTemplate.PdfTitle = fileCheckSum; newCaseTemplate.Create(_dbContext); List <SiteName_Dto> sites = _core.Advanced_SiteItemReadAll(false); foreach (var site in sites) { int?sdkCaseId = _core.CaseCreate(mainElement, "", site.SiteUId); CaseTemplateSite caseTemplateSite = new CaseTemplateSite() { CaseTemplateId = newCaseTemplate.Id, SdkSiteId = site.SiteUId, SdkCaseId = (int)sdkCaseId }; caseTemplateSite.Create(_dbContext); } } UploadedData existingUploadedData = await _dbContext.UploadedDatas.SingleOrDefaultAsync(x => x.FileName == laTitle); if (existingUploadedData == null) { UploadedData uploadedData = new UploadedData() { FileName = laTitle, ExpirationDate = existingCaseTemplate.EndAt }; uploadedData.Create(_dbContext); } } return(new OperationResult(true, "Created successfully")); } catch (Exception e) { Trace.TraceError(e.Message); return(new OperationDataResult <CaseTemplatesModel>(false, _baneDanmarkLaLocalizationService.GetString("Failure creating LA") + $" {e.Message}")); } }
public void Cases_Create_DoesCreate() { #region Arrange Random rnd = new Random(); bool randomBool = rnd.Next(0, 2) > 0; CaseTemplate caseTemplate = new CaseTemplate(); caseTemplate.Approvable = randomBool; caseTemplate.Body = Guid.NewGuid().ToString(); caseTemplate.Title = Guid.NewGuid().ToString(); caseTemplate.AlwaysShow = randomBool; caseTemplate.EndAt = DateTime.Now; caseTemplate.PdfTitle = Guid.NewGuid().ToString(); caseTemplate.StartAt = DateTime.Now; caseTemplate.DescriptionFolderId = rnd.Next(0, 255); caseTemplate.RetractIfApproved = randomBool; caseTemplate.Create(DbContext); Case @case = new Case(); @case.Status = rnd.Next(0, 255); @case.Type = Guid.NewGuid().ToString(); @case.DoneAt = DateTime.Now; @case.eFormId = rnd.Next(0, 255); @case.SiteId = rnd.Next(0, 255); @case.UnitId = rnd.Next(0, 255); @case.WorkerId = rnd.Next(0, 255); @case.CaseTemplateId = caseTemplate.Id; @case.FetchedByTablet = randomBool; @case.FetchedByTabletAt = DateTime.Now; @case.ReceiptRetrievedFromUser = randomBool; @case.ReceiptRetrievedFromUserAt = DateTime.Now; #endregion //Act @case.Create(DbContext); List <Case> dbCases = DbContext.Cases.AsNoTracking().ToList(); List <CaseVersion> dbCaseVersions = DbContext.CaseVersions.AsNoTracking().ToList(); //Assert Assert.NotNull(dbCases); Assert.NotNull(dbCaseVersions); Assert.AreEqual(1, dbCases.Count); Assert.AreEqual(1, dbCaseVersions.Count); Assert.AreEqual(@case.Status, dbCases[0].Status); Assert.AreEqual(@case.Type, dbCases[0].Type); Assert.AreEqual(@case.DoneAt.ToString(), dbCases[0].DoneAt.ToString()); Assert.AreEqual(@case.eFormId, dbCases[0].eFormId); Assert.AreEqual(@case.SiteId, dbCases[0].SiteId); Assert.AreEqual(@case.UnitId, dbCases[0].UnitId); Assert.AreEqual(@case.WorkerId, dbCases[0].WorkerId); Assert.AreEqual(@case.CaseTemplateId, dbCases[0].CaseTemplateId); Assert.AreEqual(@case.FetchedByTablet, dbCases[0].FetchedByTablet); Assert.AreEqual(@case.FetchedByTabletAt.ToString(), dbCases[0].FetchedByTabletAt.ToString()); Assert.AreEqual(@case.ReceiptRetrievedFromUser, dbCases[0].ReceiptRetrievedFromUser); Assert.AreEqual(@case.ReceiptRetrievedFromUserAt.ToString(), dbCases[0].ReceiptRetrievedFromUserAt.ToString()); }