public async Task FieldType_Update_DoesUpdate() { //Arrange field_types fieldType = new field_types { Description = Guid.NewGuid().ToString(), FieldType = Guid.NewGuid().ToString() }; await fieldType.Create(dbContext).ConfigureAwait(false); //Act fieldType.Description = Guid.NewGuid().ToString(); fieldType.FieldType = Guid.NewGuid().ToString(); await fieldType.Update(dbContext).ConfigureAwait(false); List <field_types> fieldTypes = dbContext.field_types.AsNoTracking().ToList(); //Assert Assert.NotNull(fieldTypes); Assert.AreEqual(20, fieldTypes.Count()); Assert.AreEqual(fieldType.Description, fieldTypes[19].Description); Assert.AreEqual(fieldType.Id, fieldTypes[19].Id); Assert.AreEqual(fieldType.FieldType, fieldTypes[19].FieldType); }
public async Task FieldType_Delete_DoesDelete() { //Arrange field_types fieldType = new field_types { Description = Guid.NewGuid().ToString(), FieldType = Guid.NewGuid().ToString() }; await fieldType.Create(dbContext).ConfigureAwait(false); //Act List <field_types> fieldTypes = dbContext.field_types.AsNoTracking().ToList(); //Assert before delete Assert.NotNull(fieldTypes); Assert.AreEqual(20, fieldTypes.Count()); //Assert after delete await fieldType.Delete(dbContext); fieldTypes = dbContext.field_types.AsNoTracking().ToList(); Assert.AreEqual(19, fieldTypes.Count()); }
public async Task FieldValues_Delete_DoesSetWorkflowStateToRemoved() { short shortMinValue = Int16.MinValue; short shortmaxValue = Int16.MaxValue; Random rnd = new Random(); bool randomBool = rnd.Next(0, 2) > 0; sites site = new sites { Name = Guid.NewGuid().ToString(), MicrotingUid = rnd.Next(1, 255) }; await site.Create(dbContext).ConfigureAwait(false); units unit = new units { CustomerNo = rnd.Next(1, 255), MicrotingUid = rnd.Next(1, 255), OtpCode = rnd.Next(1, 255), SiteId = site.Id }; await unit.Create(dbContext).ConfigureAwait(false); check_lists checklist = new check_lists { Color = Guid.NewGuid().ToString(), Custom = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString(), Field1 = rnd.Next(1, 255), Field2 = rnd.Next(1, 255), Field4 = rnd.Next(1, 255), Field5 = rnd.Next(1, 255), Field6 = rnd.Next(1, 255), Field7 = rnd.Next(1, 255), Field8 = rnd.Next(1, 255), Field9 = rnd.Next(1, 255), Field10 = rnd.Next(1, 255), Label = Guid.NewGuid().ToString(), Repeated = rnd.Next(1, 255), ApprovalEnabled = (short)rnd.Next(shortMinValue, shortmaxValue), CaseType = Guid.NewGuid().ToString(), DisplayIndex = rnd.Next(1, 255), DownloadEntities = (short)rnd.Next(shortMinValue, shortmaxValue), FastNavigation = (short)rnd.Next(shortMinValue, shortmaxValue), FolderName = Guid.NewGuid().ToString(), ManualSync = (short)rnd.Next(shortMinValue, shortmaxValue), MultiApproval = (short)rnd.Next(shortMinValue, shortmaxValue), OriginalId = Guid.NewGuid().ToString(), ReviewEnabled = (short)rnd.Next(shortMinValue, shortmaxValue), DocxExportEnabled = randomBool, DoneButtonEnabled = (short)rnd.Next(shortMinValue, shortmaxValue), ExtraFieldsEnabled = (short)rnd.Next(shortMinValue, shortmaxValue), JasperExportEnabled = randomBool, QuickSyncEnabled = (short)rnd.Next(shortMinValue, shortmaxValue) }; await checklist.Create(dbContext).ConfigureAwait(false); entity_groups entityGroup = new entity_groups { Name = Guid.NewGuid().ToString(), Type = Guid.NewGuid().ToString(), MicrotingUid = Guid.NewGuid().ToString() }; await entityGroup.Create(dbContext).ConfigureAwait(false); field_types fieldType = new field_types { Description = Guid.NewGuid().ToString(), FieldType = Guid.NewGuid().ToString() }; await fieldType.Create(dbContext).ConfigureAwait(false); fields field = new fields { Color = Guid.NewGuid().ToString(), Custom = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString(), Dummy = (short)rnd.Next(shortMinValue, shortmaxValue), Label = Guid.NewGuid().ToString(), Mandatory = (short)rnd.Next(shortMinValue, shortmaxValue), Multi = rnd.Next(1, 255), Optional = (short)rnd.Next(shortMinValue, shortmaxValue), Selected = (short)rnd.Next(shortMinValue, shortmaxValue), BarcodeEnabled = (short)rnd.Next(shortMinValue, shortmaxValue), BarcodeType = Guid.NewGuid().ToString(), DecimalCount = rnd.Next(1, 255), DefaultValue = Guid.NewGuid().ToString(), DisplayIndex = rnd.Next(1, 255), GeolocationEnabled = (short)rnd.Next(shortMinValue, shortmaxValue), GeolocationForced = (short)rnd.Next(shortMinValue, shortmaxValue), GeolocationHidden = (short)rnd.Next(shortMinValue, shortmaxValue), IsNum = (short)rnd.Next(shortMinValue, shortmaxValue), MaxLength = rnd.Next(1, 255), MaxValue = Guid.NewGuid().ToString(), MinValue = Guid.NewGuid().ToString(), OriginalId = Guid.NewGuid().ToString(), QueryType = Guid.NewGuid().ToString(), ReadOnly = (short)rnd.Next(shortMinValue, shortmaxValue), SplitScreen = (short)rnd.Next(shortMinValue, shortmaxValue), UnitName = Guid.NewGuid().ToString(), StopOnSave = (short)rnd.Next(shortMinValue, shortmaxValue), KeyValuePairList = Guid.NewGuid().ToString(), CheckListId = checklist.Id, EntityGroupId = entityGroup.Id, FieldTypeId = fieldType.Id }; await field.Create(dbContext).ConfigureAwait(false); workers worker = new workers { Email = Guid.NewGuid().ToString(), FirstName = Guid.NewGuid().ToString(), LastName = Guid.NewGuid().ToString(), MicrotingUid = rnd.Next(1, 255) }; await worker.Create(dbContext).ConfigureAwait(false); cases theCase = new cases { Custom = Guid.NewGuid().ToString(), Status = rnd.Next(1, 255), Type = Guid.NewGuid().ToString(), CaseUid = Guid.NewGuid().ToString(), DoneAt = DateTime.Now, FieldValue1 = Guid.NewGuid().ToString(), FieldValue2 = Guid.NewGuid().ToString(), FieldValue3 = Guid.NewGuid().ToString(), FieldValue4 = Guid.NewGuid().ToString(), FieldValue5 = Guid.NewGuid().ToString(), FieldValue6 = Guid.NewGuid().ToString(), FieldValue7 = Guid.NewGuid().ToString(), FieldValue8 = Guid.NewGuid().ToString(), FieldValue9 = Guid.NewGuid().ToString(), FieldValue10 = Guid.NewGuid().ToString(), MicrotingUid = rnd.Next(shortMinValue, shortmaxValue), SiteId = site.Id, UnitId = unit.Id, WorkerId = worker.Id, CheckListId = checklist.Id, MicrotingCheckUid = rnd.Next(shortMinValue, shortmaxValue) }; await theCase.Create(dbContext).ConfigureAwait(false); uploaded_data uploadedData = new uploaded_data { Checksum = Guid.NewGuid().ToString(), Extension = Guid.NewGuid().ToString(), Local = (short)rnd.Next(shortMinValue, shortmaxValue), CurrentFile = Guid.NewGuid().ToString(), ExpirationDate = DateTime.Now, FileLocation = Guid.NewGuid().ToString(), FileName = Guid.NewGuid().ToString(), TranscriptionId = rnd.Next(1, 255), UploaderId = rnd.Next(1, 255), UploaderType = Guid.NewGuid().ToString() }; await uploadedData.Create(dbContext).ConfigureAwait(false); field_values fieldValue = new field_values { Accuracy = Guid.NewGuid().ToString(), Altitude = Guid.NewGuid().ToString(), Date = DateTime.Now, Heading = Guid.NewGuid().ToString(), Latitude = Guid.NewGuid().ToString(), Longitude = Guid.NewGuid().ToString(), Value = Guid.NewGuid().ToString(), CaseId = theCase.Id, DoneAt = DateTime.Now, FieldId = field.Id, WorkerId = worker.Id, CheckListId = checklist.Id, UploadedDataId = uploadedData.Id }; await fieldValue.Create(dbContext).ConfigureAwait(false); //Act DateTime?oldUpdatedAt = fieldValue.UpdatedAt; await fieldValue.Delete(dbContext); List <field_values> fieldValues = dbContext.field_values.AsNoTracking().ToList(); List <field_value_versions> fieldValueVersions = dbContext.field_value_versions.AsNoTracking().ToList(); Assert.NotNull(fieldValues); Assert.NotNull(fieldValueVersions); Assert.AreEqual(1, fieldValues.Count()); Assert.AreEqual(2, fieldValueVersions.Count()); Assert.AreEqual(fieldValue.CreatedAt.ToString(), fieldValues[0].CreatedAt.ToString()); Assert.AreEqual(fieldValue.Version, fieldValues[0].Version); // Assert.AreEqual(fieldValue.UpdatedAt.ToString(), fieldValues[0].UpdatedAt.ToString()); Assert.AreEqual(fieldValues[0].WorkflowState, Constants.WorkflowStates.Removed); Assert.AreEqual(fieldValue.Id, fieldValues[0].Id); Assert.AreEqual(fieldValue.Accuracy, fieldValues[0].Accuracy); Assert.AreEqual(fieldValue.Date.ToString(), fieldValues[0].Date.ToString()); Assert.AreEqual(fieldValue.Heading, fieldValues[0].Heading); Assert.AreEqual(fieldValue.Latitude, fieldValues[0].Latitude); Assert.AreEqual(fieldValue.Longitude, fieldValues[0].Longitude); Assert.AreEqual(fieldValue.Value, fieldValues[0].Value); Assert.AreEqual(fieldValue.CaseId, theCase.Id); Assert.AreEqual(fieldValue.DoneAt.ToString(), fieldValues[0].DoneAt.ToString()); Assert.AreEqual(fieldValue.FieldId, field.Id); Assert.AreEqual(fieldValue.WorkerId, worker.Id); Assert.AreEqual(fieldValue.CheckListId, checklist.Id); Assert.AreEqual(fieldValue.UploadedDataId, uploadedData.Id); //Old Version Assert.AreEqual(fieldValue.CreatedAt.ToString(), fieldValueVersions[0].CreatedAt.ToString()); Assert.AreEqual(1, fieldValueVersions[0].Version); // Assert.AreEqual(oldUpdatedAt.ToString(), fieldValueVersions[0].UpdatedAt.ToString()); Assert.AreEqual(fieldValueVersions[0].WorkflowState, Constants.WorkflowStates.Created); Assert.AreEqual(fieldValue.Id, fieldValueVersions[0].FieldId); Assert.AreEqual(fieldValue.Accuracy, fieldValueVersions[0].Accuracy); Assert.AreEqual(fieldValue.Date.ToString(), fieldValueVersions[0].Date.ToString()); Assert.AreEqual(fieldValue.Heading, fieldValueVersions[0].Heading); Assert.AreEqual(fieldValue.Latitude, fieldValueVersions[0].Latitude); Assert.AreEqual(fieldValue.Longitude, fieldValueVersions[0].Longitude); Assert.AreEqual(fieldValue.Value, fieldValueVersions[0].Value); Assert.AreEqual(theCase.Id, fieldValueVersions[0].CaseId); Assert.AreEqual(fieldValue.DoneAt.ToString(), fieldValueVersions[0].DoneAt.ToString()); Assert.AreEqual(field.Id, fieldValueVersions[0].FieldId); Assert.AreEqual(worker.Id, fieldValueVersions[0].WorkerId); Assert.AreEqual(checklist.Id, fieldValueVersions[0].CheckListId); Assert.AreEqual(uploadedData.Id, fieldValueVersions[0].UploadedDataId); //New Version Assert.AreEqual(fieldValue.CreatedAt.ToString(), fieldValueVersions[1].CreatedAt.ToString()); Assert.AreEqual(2, fieldValueVersions[1].Version); // Assert.AreEqual(fieldValue.UpdatedAt.ToString(), fieldValueVersions[1].UpdatedAt.ToString()); Assert.AreEqual(fieldValueVersions[1].WorkflowState, Constants.WorkflowStates.Removed); Assert.AreEqual(fieldValue.Id, fieldValueVersions[1].FieldId); Assert.AreEqual(fieldValue.Accuracy, fieldValueVersions[1].Accuracy); Assert.AreEqual(fieldValue.Date.ToString(), fieldValueVersions[1].Date.ToString()); Assert.AreEqual(fieldValue.Heading, fieldValueVersions[1].Heading); Assert.AreEqual(fieldValue.Latitude, fieldValueVersions[1].Latitude); Assert.AreEqual(fieldValue.Longitude, fieldValueVersions[1].Longitude); Assert.AreEqual(fieldValue.Value, fieldValueVersions[1].Value); Assert.AreEqual(theCase.Id, fieldValueVersions[1].CaseId); Assert.AreEqual(fieldValue.DoneAt.ToString(), fieldValueVersions[1].DoneAt.ToString()); Assert.AreEqual(field.Id, fieldValueVersions[1].FieldId); Assert.AreEqual(worker.Id, fieldValueVersions[1].WorkerId); Assert.AreEqual(checklist.Id, fieldValueVersions[1].CheckListId); Assert.AreEqual(uploadedData.Id, fieldValueVersions[1].UploadedDataId); }