Exemplo n.º 1
0
        public void VerifyThatAnUnkownLanguageCodeCanBeLoaded()
        {
            var languageCode = "F6F40215-560D-4104-93E1-6452769FDACC";
            var content      = "content in an unknown language";

            var definition = new Definition()
            {
                LanguageCode = languageCode, Content = content
            };

            var requirement = new Requirement();
            var clone       = requirement.Clone(false);

            clone.Definition.Add(definition);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDirectory);
            var transaction        = new ThingTransaction(transactionContext, null);

            transaction.CreateOrUpdate(clone);

            var vm = new DefinitionDialogViewModel(definition, transaction, this.session.Object, true, ThingDialogKind.Create, null, clone, null);

            Assert.AreEqual(vm.SelectedLanguageCode.Name, languageCode);
            Assert.AreEqual(vm.Content, content);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs the drop operation for a <see cref="Requirement"/> payload
        /// </summary>
        /// <param name="requirement">
        /// The <see cref="Requirement"/> that was dropped into this <see cref="RequirementsGroup"/>
        /// </param>
        private async Task OnRequirementDrop(Requirement requirement)
        {
            var context                  = TransactionContextResolver.ResolveContext(this.Thing);
            var transaction              = new ThingTransaction(context);
            var requirementClone         = requirement.Clone(false);
            var requirementSpecification = this.Thing.GetContainerOfType <RequirementsSpecification>();

            requirementClone.Group = this.Thing;
            transaction.CreateOrUpdate(requirementClone);
            if (requirement.Container != requirementSpecification)
            {
                var requirementSpecificationClone = requirementSpecification.Clone(false);
                requirementSpecificationClone.Requirement.Add(requirementClone);
                transaction.CreateOrUpdate(requirementSpecificationClone);
            }

            await this.DalWrite(transaction);
        }
Exemplo n.º 3
0
        public void VerifyThatDialogViewModelCanLoadIfLanguageCodeIsNull()
        {
            var definition = new Definition()
            {
                LanguageCode = null, Content = null
            };

            var requirement = new Requirement();
            var clone       = requirement.Clone(false);

            clone.Definition.Add(definition);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDirectory);
            var transaction        = new ThingTransaction(transactionContext, null);

            transaction.CreateOrUpdate(clone);

            Assert.DoesNotThrow(() => new DefinitionDialogViewModel(definition, transaction, this.session.Object, true, ThingDialogKind.Create, null, clone, null));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Performs the drop operation for a <see cref="Requirement"/> payload
        /// </summary>
        /// <param name="requirement">
        /// The <see cref="Requirement"/> that was dropped into this <see cref="RequirementsSpecification"/>
        /// </param>
        private async Task OnRequirementDrop(Requirement requirement)
        {
            var context     = TransactionContextResolver.ResolveContext(this.Thing);
            var transaction = new ThingTransaction(context);

            var requirementClone = requirement.Clone(false);

            requirementClone.Group = null;
            transaction.CreateOrUpdate(requirementClone);

            if (requirement.Container != this.Thing)
            {
                // Add the requirement to the RequirementSpecification represented by this RowViewModel
                var requirementSpecificationClone = this.Thing.Clone(false);
                requirementSpecificationClone.Requirement.Add(requirement);
                transaction.CreateOrUpdate(requirementSpecificationClone);
            }

            await this.DalWrite(transaction);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates and returns a <see cref="ThingTransaction"/> that contains required operations to insert <paramref name="reqToInsert"/> before <paramref name="requirement"/>
        /// </summary>
        /// <param name="reqToInsert">The <see cref="Requirement"/> to insert</param>
        /// <param name="requirement">The <see cref="Requirement"/> that comes right after <paramref name="reqToInsert"/></param>
        /// <param name="insertKind">The <see cref="InsertKind"/></param>
        /// <returns>The <see cref="ThingTransaction"/></returns>
        public ThingTransaction Insert(Requirement reqToInsert, Requirement requirement, InsertKind insertKind)
        {
            var transaction   = new ThingTransaction(TransactionContextResolver.ResolveContext(reqToInsert));
            var specification = (RequirementsSpecification)requirement.Container;

            var allReqInContext = specification.Requirement.Where(x => x.Group == requirement.Group && x.Iid != reqToInsert.Iid).ToList();

            allReqInContext.Add(reqToInsert);

            // contains all new or clone of SimpleParameterValue
            var paramValuesClone = new Dictionary <Guid, SimpleParameterValue>();
            var unorderedReq     = new List <Requirement>();

            // put all ParameterValueSet in transaction as update if existing, as created otherwise
            foreach (var req in allReqInContext)
            {
                // Create SimpleParameterValue if missing
                SimpleParameterValue orderValue;
                if (!this.TryQueryOrderParameterOrCreate(req, out orderValue))
                {
                    var cloneReq = req.Clone(false);
                    cloneReq.ParameterValue.Add(orderValue);
                    transaction.CreateOrUpdate(cloneReq);
                    transaction.CreateOrUpdate(orderValue);
                    paramValuesClone.Add(req.Iid, orderValue);

                    // keep tab on unordered req to put order on their shortname
                    unorderedReq.Add(req);
                }
                else
                {
                    var cloneValue = orderValue.Clone(false);
                    if (req.Iid == reqToInsert.Iid)
                    {
                        // reset current value to max
                        cloneValue.Value = new ValueArray <string>(new [] { int.MaxValue.ToString() });
                    }

                    transaction.CreateOrUpdate(cloneValue);
                    paramValuesClone.Add(req.Iid, cloneValue);
                }
            }

            var reqToInsertClone = (Requirement)transaction.UpdatedThing.SingleOrDefault(x => x.Key.Iid == reqToInsert.Iid).Value;

            if (reqToInsertClone == null)
            {
                reqToInsertClone = reqToInsert.Clone(false);
                transaction.CreateOrUpdate(reqToInsertClone);
            }

            reqToInsertClone.Group = requirement.Group;
            if (reqToInsert.Container != requirement.Container)
            {
                var specClone = (RequirementsSpecification)requirement.Container.Clone(false);

                specClone.Requirement.Add(reqToInsertClone);
                transaction.CreateOrUpdate(specClone);
            }

            // keys
            unorderedReq = unorderedReq.OrderBy(x => x.ShortName).ToList();
            var unorderedReqId = unorderedReq.Select(x => x.Iid).ToList();

            var orderedParamClone = paramValuesClone.Where(x => !unorderedReqId.Contains(x.Key)).OrderBy(x => this.getOrderKey(x.Value)).ToList();

            orderedParamClone.AddRange(paramValuesClone.Where(x => unorderedReqId.Contains(x.Key)).OrderBy(x => unorderedReqId.IndexOf(x.Key)));

            paramValuesClone = orderedParamClone.ToDictionary(x => x.Key, x => x.Value);
            var reqOrderedUuid = paramValuesClone.Where(x => x.Key != reqToInsert.Iid).OrderBy(x => this.getOrderKey(x.Value)).Select(x => x.Key).ToList();

            var indexOfRefInsertReq = reqOrderedUuid.IndexOf(requirement.Iid);
            var endReqIdInterval    = insertKind == InsertKind.InsertBefore
                ? indexOfRefInsertReq > 0 ? (Guid?)reqOrderedUuid[indexOfRefInsertReq - 1] : null
                : indexOfRefInsertReq < reqOrderedUuid.Count - 1
                    ? (Guid?)reqOrderedUuid[indexOfRefInsertReq + 1]
                    : null;

            var upperPair = insertKind == InsertKind.InsertBefore ? paramValuesClone.First(x => x.Key == requirement.Iid) : endReqIdInterval.HasValue ? paramValuesClone.First(x => x.Key == endReqIdInterval) : default(KeyValuePair <Guid, SimpleParameterValue>);
            var lowerPair = insertKind == InsertKind.InsertBefore ? endReqIdInterval.HasValue ? paramValuesClone.First(x => x.Key == endReqIdInterval) : default(KeyValuePair <Guid, SimpleParameterValue>) : paramValuesClone.First(x => x.Key == requirement.Iid);

            var upperKey = upperPair.Value != null?this.getOrderKey(upperPair.Value) : int.MaxValue;

            var lowerKey = lowerPair.Value != null?this.getOrderKey(lowerPair.Value) : int.MinValue;

            // either just update key of the dropped requirement or recompute all keys
            var insertKey = this.ComputeOrderKey(lowerKey, upperKey, paramValuesClone.Values.Select(this.getOrderKey).ToList(), false);

            if (insertKey.HasValue)
            {
                paramValuesClone[reqToInsert.Iid].Value = new ValueArray <string>(new [] { insertKey.ToString() });
            }
            else
            {
                if (unorderedReq.Any(x => !this.session.PermissionService.CanWrite(ClassKind.SimpleParameterValue, x)))
                {
                    // if no permission to update everything, just update value with min or max depending on the kind of insert
                    insertKey = this.ComputeOrderKey(lowerKey, upperKey, paramValuesClone.Values.Select(this.getOrderKey).ToList(), true);
                    paramValuesClone[reqToInsert.Iid].Value = new ValueArray <string>(new[] { insertKey.ToString() });
                }
                else
                {
                    var lower = 0;
                    // recompute all keys in ascending order
                    foreach (var simpleParameterValue in paramValuesClone)
                    {
                        if (simpleParameterValue.Key == reqToInsert.Iid)
                        {
                            continue;
                        }

                        var key = this.ComputeOrderKey(lower, Int32.MaxValue, new List <int>(), true);
                        if (simpleParameterValue.Key == requirement.Iid && insertKind == InsertKind.InsertBefore)
                        {
                            var reqValueToInsert = paramValuesClone.First(x => x.Key == reqToInsert.Iid);
                            reqValueToInsert.Value.Value = new ValueArray <string>(new[] { key.ToString() });
                            lower = key.Value;
                            key   = this.ComputeOrderKey(lower, Int32.MaxValue, new List <int>(), true);
                            simpleParameterValue.Value.Value = new ValueArray <string>(new[] { key.ToString() });
                            lower = key.Value;
                        }
                        else if (simpleParameterValue.Key == requirement.Iid && insertKind == InsertKind.InsertAfter)
                        {
                            simpleParameterValue.Value.Value = new ValueArray <string>(new[] { key.ToString() });
                            lower = key.Value;

                            key = this.ComputeOrderKey(lower, Int32.MaxValue, new List <int>(), true);
                            var reqValueToInsert = paramValuesClone.First(x => x.Key == reqToInsert.Iid);
                            reqValueToInsert.Value.Value = new ValueArray <string>(new[] { key.ToString() });
                            lower = key.Value;
                        }
                        else
                        {
                            simpleParameterValue.Value.Value = new ValueArray <string>(new[] { key.ToString() });
                            lower = key.Value;
                        }
                    }
                }
            }

            return(transaction);
        }