Ejemplo n.º 1
0
        /// <summary>
        /// Invoked by UpdateCommand() if validation and business rules execute successfully
        /// </summary>
        protected override async Task <T> UpdateAsync(T entity, ExecutionContext <T> context)
        {
            // only perform this if we're not latency prone - keep it close to the server, no need to do this more than once
            if (!IsLatencyProne)
            {
                var current = context.CurrentEntity;
                if (current == null)
                {
                    current = await GetByIDAsync(entity.ID, context);
                }

                if (current == null)
                {
                    throw new DomainObjectNotFoundException(BuildNotFoundError(entity.ID));
                }
                if (current is IVersionContainer)
                {
                    var rule = new ConcurrencyCheckRule(current as IVersionContainer, entity as IVersionContainer).Validate();
                    if (!rule.IsValid)
                    {
                        throw new ConcurrencyException(rule.ErrorMessage);
                    }
                }
                entity.RevertNonEditableValues(current);
                entity.RevertForeignKeysFromZeroToNull();
            }

            return(await _dataProxy.UpdateAsync(entity));
        }
Ejemplo n.º 2
0
        public void ConcurrencyCheckRule_Returns_False()
        {
            var obj1 = new ConcurrencyMock {
                Version = "1"
            };
            var obj2 = new ConcurrencyMock {
                Version = "2"
            };
            var rule = new ConcurrencyCheckRule(obj1, obj2);

            rule.Validate().IsValid.ShouldBe(false);
        }
Ejemplo n.º 3
0
        public void ConcurrencyCheckRule_Sets_ErrorMessage_On_Invalid()
        {
            var obj1 = new ConcurrencyMock {
                Version = "1"
            };
            var obj2 = new ConcurrencyMock {
                Version = "2"
            };
            var rule = new ConcurrencyCheckRule(obj1, obj2);

            rule.Validate().ErrorMessage.ShouldNotBeEmpty();
        }
Ejemplo n.º 4
0
        public void ConcurrencyCheckRuleReturnsTrue()
        {
            var obj1 = new ConcurrencyMock()
            {
                Version = "1"
            };
            var obj2 = new ConcurrencyMock()
            {
                Version = "1"
            };
            var rule = new ConcurrencyCheckRule(obj1, obj2);

            rule.Validate().IsValid.ShouldBe(true);
        }