public ESDATDataDisplayViewModel GetSampleCollectionActionInESDAT(int Id, int?version = null)
        {
            var mappingHelper = new ESDATViewModelMappingHelper();
            var versionHelper = new DataVersioningHelper(_wqDefaultValueProvider);

            var matchedAction = _wqDataRepository.GetActionById(Id);

            var esdatModel = Mapper.Map <ESDATDataDisplayViewModel>(matchedAction);

            //no version function is applied to chemistry data yet
            esdatModel.ChemistryData = ESDATViewModelMappingHelper.MapActionToChemistryFileData(matchedAction, versionHelper);

            if (version.HasValue)
            {
                esdatModel.CurrentSampleDataVersion = version.Value;
                if (version.Value == 0)
                {
                    esdatModel.SampleFileData = ESDATViewModelMappingHelper.MapActionToSampleFileData(matchedAction);
                }
                else if (version.Value >= 1)
                {
                    while (version >= 1)
                    {
                        var nextVersion = versionHelper.GetNextVersionActionData(matchedAction);
                        if (nextVersion == null)
                        {
                            throw new ArgumentException();
                        }
                        matchedAction = nextVersion;
                        version--;
                    }
                }
                else
                {
                    throw new ArgumentException();
                }


                esdatModel.SampleFileData = ESDATViewModelMappingHelper.MapActionToSampleFileData(matchedAction);
            }
            else
            {
                //show the latest version data by default
                var numberOfSubversions = versionHelper.GetSubVersionCountOfAction(matchedAction);
                matchedAction = versionHelper.GetLatestVersionActionData(matchedAction);

                esdatModel.CurrentSampleDataVersion = numberOfSubversions;
                esdatModel.SampleFileData           = ESDATViewModelMappingHelper.MapActionToSampleFileData(matchedAction);
            }

            return(esdatModel);
        }
예제 #2
0
        public void GetNextVersionDataTest()
        {
            var mockDefaultValueProvider = new Mock <IWQDefaultValueProvider>();

            mockDefaultValueProvider.Setup(x => x.ActionRelationshipTypeSubVersion).Returns("is new version of");

            var versionHelper = new DataVersioningHelper(mockDefaultValueProvider.Object);

            CreateTestAction(mockDefaultValueProvider.Object);

            var foundNextVersionData = versionHelper.GetNextVersionActionData(rootActionData);

            Assert.NotNull(foundNextVersionData);
            Assert.AreEqual(foundNextVersionData, childActionData);
            Assert.AreEqual(2, foundNextVersionData.ActionID);
        }