public void EditDatasetVersion_DeleteADataTupleAfterUpdate_ReturnUpdatedVersion() { Dataset dataset; DatasetVersion latest; using (DatasetManager datasetManager = new DatasetManager()) { //Arrange dataset = datasetManager.GetDataset(datasetId); latest = datasetManager.GetDatasetLatestVersion(datasetId); //update the dataset dataset = dsHelper.UpdateAnyTupleForDataset(dataset, dataset.DataStructure as StructuredDataStructure, datasetManager); datasetManager.CheckInDataset(datasetId, "for testing update all datatuple", username, ViewCreationBehavior.None); } using (DatasetManager datasetManager = new DatasetManager()) { try { latest = datasetManager.GetDatasetLatestVersion(datasetId); int before = datasetManager.GetDataTuplesCount(latest.Id); var tuple = datasetManager.GetDataTuples(latest.Id).LastOrDefault(); //Act if (datasetManager.IsDatasetCheckedOutFor(datasetId, "David") || datasetManager.CheckOutDataset(datasetId, "David")) { DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(datasetId); List <AbstractTuple> deleteTuples = new List <AbstractTuple>(); deleteTuples.Add(tuple); workingCopy = datasetManager.EditDatasetVersion(workingCopy, null, null, deleteTuples.Select(d => d.Id).ToList()); datasetManager.CheckInDataset(datasetId, "delete one datatuple for testing", username, ViewCreationBehavior.None); } latest = datasetManager.GetDatasetLatestVersion(datasetId); int after = datasetManager.GetDataTuplesCount(latest.Id); //Assert Assert.That(before, Is.GreaterThan(after)); } catch (Exception ex) { throw ex; } } }
public void GetDataTuples_CallOlderVersionAfterTwoUpdates_ReturnIQueryable() { List <long> datatupleIds; try { //Arrange using (var datasetManager = new DatasetManager()) { var dataset = datasetManager.GetDataset(datasetId); var datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); Assert.IsNotNull(dataset); Assert.IsNotNull(datasetVersion); //get latest datatupleid before create a new dataset and data using (var uow = this.GetUnitOfWork()) { datatupleIds = uow.GetReadOnlyRepository <DataTuple>().Get().Where(dt => dt.DatasetVersion.Id.Equals(datasetVersion.Id)).Select(dt => dt.Id).ToList(); } dataset = dsHelper.UpdateOneTupleForDataset(dataset, (StructuredDataStructure)dataset.DataStructure, datatupleIds[0], 1000, datasetManager); datasetManager.CheckInDataset(dataset.Id, "for testing datatuples with versions", username, ViewCreationBehavior.None); dataset = dsHelper.UpdateOneTupleForDataset(dataset, (StructuredDataStructure)dataset.DataStructure, datatupleIds[1], 2000, datasetManager); datasetManager.CheckInDataset(dataset.Id, "for testing datatuples with versions", username, ViewCreationBehavior.None); } //Act using (var datasetManager = new DatasetManager()) { List <DatasetVersion> datasetversions = datasetManager.GetDatasetVersions(datasetId).OrderBy(d => d.Timestamp).ToList(); Assert.That(datasetversions.Count, Is.EqualTo(3)); foreach (var dsv in datasetversions) { int c = datasetManager.GetDataTuplesCount(dsv.Id); var result = datasetManager.GetDataTuples(dsv.Id); // get datatuples from the one before the latest int cm = result.Count(); Assert.That(c, Is.EqualTo(10)); Assert.That(c, Is.EqualTo(result.Count())); } } } catch (Exception ex) { throw ex; } }
public Dataset UpdateAnyTupleForDataset(Dataset dataset, StructuredDataStructure dataStructure) { dataset.Status.Should().Be(DatasetStatus.CheckedIn); dataset.Should().NotBeNull(); DatasetManager dm = new DatasetManager(); try { DatasetVersion dsv = dm.GetDatasetLatestVersion(dataset.Id); var datatuples = dm.GetDataTuples(dsv.Id); if (dm.IsDatasetCheckedOutFor(dataset.Id, "David") || dm.CheckOutDataset(dataset.Id, "David")) { dataset.Status.Should().Be(DatasetStatus.CheckedOut, "Dataset must be in Checkedout status."); DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(dataset.Id); List <DataTuple> editedTuples = new List <DataTuple>(); foreach (var dataTuple in datatuples) { var vv = dataTuple.VariableValues.Where(v => v.VariableId.Equals(dataStructure.Variables.Skip(4).First().Id)).FirstOrDefault(); if (vv != null) { vv.Value = DateTime.Now.ToString(); } dataTuple.Dematerialize(); dataTuple.Should().NotBeNull(); //dataTuple.XmlVariableValues.Should().NotBeNull(); dataTuple.Materialize(); editedTuples.Add((DataTuple)dataTuple); } dm.EditDatasetVersion(workingCopy, null, editedTuples, null); dataset.Status.Should().Be(DatasetStatus.CheckedOut, "Dataset must be in Checkedout status."); } return(dataset); } catch (Exception ex) { return(null); } finally { dm.Dispose(); } }
public void GetDataTuples_InvalidDatasetVersionId_ReturnEmptyIQueryable() { DatasetManager datasetManager = new DatasetManager(); try { //Act var result = datasetManager.GetDataTuples(-1); //Assert Assert.That(result.Count(), Is.EqualTo(0)); } finally { datasetManager.Dispose(); } }
public void EditDatasetVersion_DeleteADataTuple_ReturnUpdatedVersion() { DatasetManager datasetManager = new DatasetManager(); try { //Arrange DatasetVersion latest = datasetManager.GetDatasetLatestVersion(datasetId); int before = datasetManager.GetDataTuplesCount(latest.Id); var tuple = datasetManager.GetDataTuples(latest.Id).LastOrDefault(); //Act if (datasetManager.IsDatasetCheckedOutFor(datasetId, "David") || datasetManager.CheckOutDataset(datasetId, "David")) { DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(datasetId); List <DataTuple> deleteTuples = new List <DataTuple>(); deleteTuples.Add(tuple as DataTuple); workingCopy = datasetManager.EditDatasetVersion(workingCopy, null, null, deleteTuples.Select(d => d.Id).ToList()); datasetManager.CheckInDataset(datasetId, "delete one datatuple for testing", username, ViewCreationBehavior.None); } latest = datasetManager.GetDatasetLatestVersion(datasetId); int after = datasetManager.GetDataTuplesCount(latest.Id); //Assert Assert.That(before, Is.GreaterThan(after)); } catch (Exception ex) { throw ex; } finally { datasetManager.Dispose(); } }
public void GetDataTuples_WhenCalledForLatestVersionComplete_ReturnIQueryable() { //Arrange DatasetManager datasetManager = new DatasetManager(); try { //Act DatasetVersion datasetversion = datasetManager.GetDatasetLatestVersion(datasetId); var result = datasetManager.GetDataTuples(datasetversion.Id); int c = datasetManager.GetDataTuplesCount(datasetversion.Id); //Assert Assert.That(result.Count(), Is.EqualTo(numberOfTuples)); Assert.That(c, Is.EqualTo(result.Count())); } finally { datasetManager.Dispose(); } }
public List <DataTuple> GetUpdatedDatatuples(DatasetVersion datasetVersion, StructuredDataStructure dataStructure, DatasetManager datasetManager) { datasetVersion.Should().NotBeNull(); var dataset = datasetVersion.Dataset; dataset.Status.Should().Be(DatasetStatus.CheckedIn); dataset.Should().NotBeNull(); try { var datatuples = datasetManager.GetDataTuples(datasetVersion.Id); List <DataTuple> editedTuples = new List <DataTuple>(); foreach (var dataTuple in datatuples) { dataTuple.Materialize(); var vv = dataTuple.VariableValues.Where(v => v.VariableId.Equals(dataStructure.Variables.Skip(4).First().Id)).FirstOrDefault(); if (vv != null) { vv.Value = DateTime.Now.ToString(new CultureInfo("en-US")); } dataTuple.Dematerialize(); dataTuple.Should().NotBeNull(); //dataTuple.XmlVariableValues.Should().NotBeNull(); editedTuples.Add((DataTuple)dataTuple); } return(editedTuples); } catch (Exception ex) { return(null); } }
public void GetDataTuples_WhenCalledOneOlderVersion_ReturnIQueryableOfAbstractTuples() { //Arrange DatasetManager datasetManager = null; try { datasetManager = new DatasetManager(); //get latest datatupleid before create a new dataset and data using (var uow = this.GetUnitOfWork()) { var latestDataTuple = uow.GetReadOnlyRepository <DataTuple>().Get().LastOrDefault(); if (latestDataTuple != null) { latestDataTupleId = latestDataTuple.Id; } } var dataset = datasetManager.GetDataset(datasetId); dataset = dsHelper.UpdateOneTupleForDataset(dataset, (StructuredDataStructure)dataset.DataStructure, latestDataTupleId, 1, datasetManager); datasetManager.CheckInDataset(dataset.Id, "for testing datatuples with versions", username, ViewCreationBehavior.None); //Act List <DatasetVersion> datasetversions = datasetManager.GetDatasetVersions(datasetId).OrderBy(d => d.Timestamp).ToList(); var result = datasetManager.GetDataTuples(datasetversions.ElementAt(datasetversions.Count - 2).Id); // get datatuples from the one before the latest //Assert Assert.That(result.Count(), Is.EqualTo(10)); } finally { datasetManager.Dispose(); } }