public async Task <IActionResult> UploadUploadedDataPdf(UploadedDataPDFUploadModel pdfUploadModel) { try { var core = _core.GetCore(); var saveFolder = Path.Combine(await core.Result.GetSdkSetting(Settings.fileLocationPdf), Path.Combine("pdfFiles")); Directory.CreateDirectory(saveFolder); string fileName = $"ItemCase_{pdfUploadModel.ItemCaseId}_{DateTime.Now.Ticks}.pdf"; if (pdfUploadModel.File.Length > 0) { using (var stream = new FileStream(Path.Combine(saveFolder, fileName), FileMode.Create)) { await pdfUploadModel.File.CopyToAsync(stream); } } if (core.Result.GetSdkSetting(Settings.swiftEnabled).ToString().ToLower() == "true") { await core.Result.PutFileToStorageSystem(Path.Combine(saveFolder, fileName), fileName); } UploadedData uploadedData = new UploadedData(); uploadedData.FileLocation = saveFolder; uploadedData.FileName = fileName; uploadedData.ItemCaseId = pdfUploadModel.ItemCaseId; await uploadedData.Create(_dbContext); return(new OkResult()); } catch (Exception e) { Trace.TraceError(e.Message); _core.LogException(e.Message); return(new BadRequestResult()); } }
public void UploadedData_Update_DoesUpdate() { //Arrange Random rnd = new Random(); short minValue = Int16.MinValue; short maxValue = Int16.MaxValue; UploadedData uploadedData = new UploadedData(); uploadedData.Checksum = Guid.NewGuid().ToString(); uploadedData.Extension = Guid.NewGuid().ToString(); uploadedData.CurrentFile = Guid.NewGuid().ToString(); uploadedData.FileLocation = Guid.NewGuid().ToString(); uploadedData.FileName = Guid.NewGuid().ToString(); uploadedData.UploaderType = Guid.NewGuid().ToString(); uploadedData.Local = (short)rnd.Next(minValue, maxValue); uploadedData.ExpirationDate = DateTime.Now; uploadedData.OriginalFileName = Guid.NewGuid().ToString(); uploadedData.Create(DbContext); //Act DateTime?oldUpdatedAt = uploadedData.UpdatedAt; string oldChecksum = uploadedData.Checksum; string oldExtension = uploadedData.Extension; string oldCurrentFIle = uploadedData.CurrentFile; string oldFileLocation = uploadedData.FileLocation; string oldFileName = uploadedData.FileName; string oldUploaderType = uploadedData.UploaderType; int? oldLocal = uploadedData.Local; DateTime?oldExpirationDate = uploadedData.ExpirationDate; string oldOriginalFileName = uploadedData.OriginalFileName; uploadedData.Checksum = Guid.NewGuid().ToString(); uploadedData.Extension = Guid.NewGuid().ToString(); uploadedData.CurrentFile = Guid.NewGuid().ToString(); uploadedData.FileLocation = Guid.NewGuid().ToString(); uploadedData.FileName = Guid.NewGuid().ToString(); uploadedData.UploaderType = Guid.NewGuid().ToString(); uploadedData.Local = (short)rnd.Next(minValue, maxValue); uploadedData.ExpirationDate = DateTime.Now; uploadedData.OriginalFileName = Guid.NewGuid().ToString(); uploadedData.Update(DbContext); List <UploadedData> dbUploadedDatas = DbContext.UploadedDatas.AsNoTracking().ToList(); List <UploadedDataVersion> dbUploadedDataVersions = DbContext.UploadedDataVersions.AsNoTracking().ToList(); //Assert Assert.NotNull(dbUploadedDatas); Assert.NotNull(dbUploadedDataVersions); Assert.AreEqual(1, dbUploadedDatas.Count); Assert.AreEqual(2, dbUploadedDataVersions.Count); Assert.AreEqual(uploadedData.Id, dbUploadedDatas[0].Id); Assert.AreEqual(uploadedData.Version, dbUploadedDatas[0].Version); Assert.AreEqual(uploadedData.CreatedAt.ToString(), dbUploadedDatas[0].CreatedAt.ToString()); Assert.AreEqual(uploadedData.UpdatedAt.ToString(), dbUploadedDatas[0].UpdatedAt.ToString()); Assert.AreEqual(uploadedData.CreatedByUserId, dbUploadedDatas[0].CreatedByUserId); Assert.AreEqual(uploadedData.UpdatedByUserId, dbUploadedDatas[0].UpdatedByUserId); Assert.AreEqual(Constants.WorkflowStates.Created, dbUploadedDatas[0].WorkflowState); Assert.AreEqual(uploadedData.Checksum, dbUploadedDatas[0].Checksum); Assert.AreEqual(uploadedData.Extension, dbUploadedDatas[0].Extension); Assert.AreEqual(uploadedData.Local, dbUploadedDatas[0].Local); Assert.AreEqual(uploadedData.CurrentFile, dbUploadedDatas[0].CurrentFile); Assert.AreEqual(uploadedData.ExpirationDate.ToString(), dbUploadedDatas[0].ExpirationDate.ToString()); Assert.AreEqual(uploadedData.FileLocation, dbUploadedDatas[0].FileLocation); Assert.AreEqual(uploadedData.FileName, dbUploadedDatas[0].FileName); Assert.AreEqual(uploadedData.UploaderType, dbUploadedDatas[0].UploaderType); Assert.AreEqual(uploadedData.OriginalFileName, dbUploadedDatas[0].OriginalFileName); //Old Version Assert.AreEqual(uploadedData.Id, dbUploadedDataVersions[0].UploadedDataId); Assert.AreEqual(1, dbUploadedDataVersions[0].Version); Assert.AreEqual(uploadedData.CreatedAt.ToString(), dbUploadedDataVersions[0].CreatedAt.ToString()); Assert.AreEqual(oldUpdatedAt.ToString(), dbUploadedDataVersions[0].UpdatedAt.ToString()); Assert.AreEqual(uploadedData.CreatedByUserId, dbUploadedDataVersions[0].CreatedByUserId); Assert.AreEqual(uploadedData.UpdatedByUserId, dbUploadedDataVersions[0].UpdatedByUserId); Assert.AreEqual(Constants.WorkflowStates.Created, dbUploadedDataVersions[0].WorkflowState); Assert.AreEqual(oldChecksum, dbUploadedDataVersions[0].Checksum); Assert.AreEqual(oldExtension, dbUploadedDataVersions[0].Extension); Assert.AreEqual(oldLocal, dbUploadedDataVersions[0].Local); Assert.AreEqual(oldCurrentFIle, dbUploadedDataVersions[0].CurrentFile); Assert.AreEqual(oldExpirationDate.ToString(), dbUploadedDataVersions[0].ExpirationDate.ToString()); Assert.AreEqual(oldFileLocation, dbUploadedDataVersions[0].FileLocation); Assert.AreEqual(oldFileName, dbUploadedDataVersions[0].FileName); Assert.AreEqual(oldUploaderType, dbUploadedDataVersions[0].UploaderType); Assert.AreEqual(oldOriginalFileName, dbUploadedDataVersions[0].OriginalFileName); //New Version Assert.AreEqual(uploadedData.Id, dbUploadedDataVersions[1].UploadedDataId); Assert.AreEqual(2, dbUploadedDataVersions[1].Version); Assert.AreEqual(uploadedData.CreatedAt.ToString(), dbUploadedDataVersions[1].CreatedAt.ToString()); Assert.AreEqual(uploadedData.UpdatedAt.ToString(), dbUploadedDataVersions[1].UpdatedAt.ToString()); Assert.AreEqual(uploadedData.CreatedByUserId, dbUploadedDataVersions[1].CreatedByUserId); Assert.AreEqual(uploadedData.UpdatedByUserId, dbUploadedDataVersions[1].UpdatedByUserId); Assert.AreEqual(Constants.WorkflowStates.Created, dbUploadedDataVersions[1].WorkflowState); Assert.AreEqual(uploadedData.Checksum, dbUploadedDataVersions[1].Checksum); Assert.AreEqual(uploadedData.Extension, dbUploadedDataVersions[1].Extension); Assert.AreEqual(uploadedData.Local, dbUploadedDataVersions[1].Local); Assert.AreEqual(uploadedData.CurrentFile, dbUploadedDataVersions[1].CurrentFile); Assert.AreEqual(uploadedData.ExpirationDate.ToString(), dbUploadedDataVersions[1].ExpirationDate.ToString()); Assert.AreEqual(uploadedData.FileLocation, dbUploadedDataVersions[1].FileLocation); Assert.AreEqual(uploadedData.FileName, dbUploadedDataVersions[1].FileName); Assert.AreEqual(uploadedData.UploaderType, dbUploadedDataVersions[1].UploaderType); Assert.AreEqual(uploadedData.OriginalFileName, dbUploadedDataVersions[1].OriginalFileName); }
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 async Task UploadedData_Update_DoesUpdate() { //Arrange ItemList itemList = new ItemList { Name = Guid.NewGuid().ToString() }; await itemList.Create(DbContext); Item item = new Item { Name = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString(), Enabled = true, ItemListId = itemList.Id, }; await item.Create(DbContext); ItemCase itemCase = new ItemCase { MicrotingSdkSiteId = 24, MicrotingSdkCaseId = 34, MicrotingSdkeFormId = 234, Status = 66, ItemId = item.Id, }; await itemCase.Create(DbContext); UploadedData uploadedData = new UploadedData { ItemCaseId = itemCase.Id, Checksum = Guid.NewGuid().ToString(), Extension = Guid.NewGuid().ToString(), CurrentFile = Guid.NewGuid().ToString(), UploaderType = Guid.NewGuid().ToString(), FileLocation = Guid.NewGuid().ToString(), FileName = Guid.NewGuid().ToString() }; await uploadedData.Create(DbContext); string newCheckSum = Guid.NewGuid().ToString(); string newExtension = Guid.NewGuid().ToString(); string newCurrentFile = Guid.NewGuid().ToString(); string newUploaderType = Guid.NewGuid().ToString(); string newFileLocation = Guid.NewGuid().ToString(); string newFileName = Guid.NewGuid().ToString(); uploadedData.Checksum = newCheckSum; uploadedData.Extension = newExtension; uploadedData.CurrentFile = newCurrentFile; uploadedData.UploaderType = newUploaderType; uploadedData.FileLocation = newFileLocation; uploadedData.FileName = newFileName; //Act await uploadedData.Update(DbContext); UploadedData dbUploadedData = DbContext.UploadedDatas.AsNoTracking().First(); List <UploadedData> uploadedDataList = DbContext.UploadedDatas.AsNoTracking().ToList(); List <UploadedDataVersion> uploadedDataVersionList = DbContext.UploadedDataVersions.AsNoTracking().ToList(); //Assert Assert.NotNull(dbUploadedData); Assert.AreEqual(1, uploadedDataList.Count); Assert.AreEqual(2, uploadedDataVersionList.Count); Assert.AreEqual(newCheckSum, dbUploadedData.Checksum); Assert.AreEqual(newExtension, dbUploadedData.Extension); Assert.AreEqual(newCurrentFile, dbUploadedData.CurrentFile); Assert.AreEqual(newUploaderType, dbUploadedData.UploaderType); Assert.AreEqual(newFileLocation, dbUploadedData.FileLocation); Assert.AreEqual(newFileName, dbUploadedData.FileName); Assert.AreEqual(uploadedData.ItemCaseId, dbUploadedData.ItemCaseId); }