Example #1
0
        public async Task Update(ItemsPlanningPnDbContext dbContext)
        {
            UploadedData uploadedData = await dbContext.UploadedDatas.FirstOrDefaultAsync(x => x.Id == Id);

            if (uploadedData == null)
            {
                throw new NullReferenceException($"Could not find uploadedData with id: {Id}");
            }

            uploadedData.ItemCaseId    = ItemCaseId;
            uploadedData.Checksum      = Checksum;
            uploadedData.Extension     = Extension;
            uploadedData.CurrentFile   = CurrentFile;
            uploadedData.UploaderType  = UploaderType;
            uploadedData.FileLocation  = FileLocation;
            uploadedData.FileName      = FileName;
            uploadedData.WorkflowState = WorkflowState;

            if (dbContext.ChangeTracker.HasChanges())
            {
                uploadedData.UpdatedAt = DateTime.UtcNow;
                uploadedData.Version  += 1;

                await dbContext.UploadedDataVersions.AddAsync(MapVersion(uploadedData));

                await dbContext.SaveChangesAsync();
            }
        }
Example #2
0
        public async Task Delete(ItemsPlanningPnDbContext dbContext)
        {
            UploadedData uploadedData = await dbContext.UploadedDatas.FirstOrDefaultAsync(x => x.Id == Id);

            if (uploadedData == null)
            {
                throw new NullReferenceException($"Could not find uploadedData with id: {Id}");
            }

            uploadedData.WorkflowState = Constants.WorkflowStates.Removed;

            if (dbContext.ChangeTracker.HasChanges())
            {
                uploadedData.UpdatedAt = DateTime.UtcNow;
                uploadedData.Version  += 1;

                await dbContext.UploadedDataVersions.AddAsync(MapVersion(uploadedData));

                await dbContext.SaveChangesAsync();
            }
        }
Example #3
0
        private UploadedDataVersion MapVersion(UploadedData uploadedData)
        {
            UploadedDataVersion uploadedDataVersion = new UploadedDataVersion()
            {
                ItemCaseId      = uploadedData.ItemCaseId,
                Checksum        = uploadedData.Checksum,
                Extension       = uploadedData.Extension,
                CurrentFile     = uploadedData.CurrentFile,
                UploaderType    = uploadedData.UploaderType,
                FileLocation    = uploadedData.FileLocation,
                FileName        = uploadedData.FileName,
                UploadedDataId  = uploadedData.Id,
                Version         = uploadedData.Version,
                CreatedAt       = uploadedData.CreatedAt,
                CreatedByUserId = uploadedData.CreatedByUserId,
                UpdatedAt       = uploadedData.UpdatedAt,
                UpdatedByUserId = uploadedData.UpdatedByUserId,
                WorkflowState   = uploadedData.WorkflowState
            };

            return(uploadedDataVersion);
        }
Example #4
0
        public async Task UploadedData_Update_DoesUpdate()
        {
            // Arrange
            var planning = new Planning();

            await planning.Create(DbContext);

            var commonTranslationModels = new List <PlanningNameTranslation>()
            {
                new PlanningNameTranslation()
                {
                    Name     = Guid.NewGuid().ToString(),
                    Language = new Language()
                    {
                        LanguageCode = "da", Name = "Danish"
                    },
                    Planning = planning
                }
            };

            foreach (var translationModel in commonTranslationModels)
            {
                await translationModel.Create(DbContext);
            }

            var planningCase = new PlanningCase
            {
                MicrotingSdkSiteId  = 24,
                MicrotingSdkCaseId  = 34,
                MicrotingSdkeFormId = 234,
                Status     = 66,
                PlanningId = planning.Id,
            };

            await planningCase.Create(DbContext);

            var uploadedData = new UploadedData
            {
                PlanningCaseId = planningCase.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);

            var newCheckSum     = Guid.NewGuid().ToString();
            var newExtension    = Guid.NewGuid().ToString();
            var newCurrentFile  = Guid.NewGuid().ToString();
            var newUploaderType = Guid.NewGuid().ToString();
            var newFileLocation = Guid.NewGuid().ToString();
            var 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);

            var dbUploadedData          = DbContext.UploadedDatas.AsNoTracking().First();
            var uploadedDataList        = DbContext.UploadedDatas.AsNoTracking().ToList();
            var 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.PlanningCaseId, dbUploadedData.PlanningCaseId);
        }