Пример #1
0
        public async Task<int> UpdateAsync(ValidatableEntity entity) {
            try {
                _dataService.Entry(entity).State = EntityState.Modified;
                entity.Updated = DateTime.Now;

                return await _dataService.SaveChangesAsync();
            } catch (DbEntityValidationException e) {
                debugLogEntityValidationError(e);
                throw;
            } catch (Exception ex) {
                throw ex;
            }
        }
Пример #2
0
        public void BuildEntityValidator_does_not_return_null_for_an_IValidatableObject()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new ValidatableEntity();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildEntityValidatorBase(ctx.Entry(entity).InternalEntry);

                Assert.NotNull(validator);
                Assert.False(validator.PropertyValidators.Any());
                Assert.True(validator.TypeLevelValidators.Any());
            }
        }
Пример #3
0
        public void BuildComplexTypeValidator_does_not_return_null_for_an_IValidatableObject()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new ValidatableEntity();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var complexType = (ComplexType)ctx.Entry(entity).InternalEntry.EdmEntityType.Properties
                                  .Where(p => p.Name == "ComplexProperty").Single().TypeUsage.EdmType;
                var validator = builder.Object.BuildComplexTypeValidatorBase(typeof(ValidatableComplexType), complexType);

                Assert.NotNull(validator);
                Assert.False(validator.PropertyValidators.Any());
                Assert.True(validator.TypeLevelValidators.Any());
            }
        }
Пример #4
0
        public async Task<int> CreateAsync(ValidatableEntity entity) {
            try {
                var link = entity as Link;
                if (link != null) {
                    _dataService.Links.Attach(link);
                }
                _dataService.Entry(entity).State = EntityState.Added;
                entity.Created = entity.Updated = DateTime.Now;


                return await _dataService.SaveChangesAsync();
            } catch (DbEntityValidationException e) {
                debugLogEntityValidationError(e);
                throw;
            } catch (Exception ex) {
                throw ex;
            }
        }
        public void BuildComplexTypeValidator_does_not_return_null_for_an_IValidatableObject()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new ValidatableEntity();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var complexType = (ComplexType)ctx.Entry(entity).InternalEntry.EdmEntityType.Properties
                                                   .Where(p => p.Name == "ComplexProperty").Single().TypeUsage.EdmType;
                var validator = builder.Object.BuildComplexTypeValidatorBase(typeof(ValidatableComplexType), complexType);

                Assert.NotNull(validator);
                Assert.False(validator.PropertyValidators.Any());
                Assert.True(validator.TypeLevelValidators.Any());
            }
        }
        public void BuildEntityValidator_does_not_return_null_for_an_IValidatableObject()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new ValidatableEntity();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildEntityValidatorBase(ctx.Entry(entity).InternalEntry);

                Assert.NotNull(validator);
                Assert.False(validator.PropertyValidators.Any());
                Assert.True(validator.TypeLevelValidators.Any());
            }
        }
Пример #7
0
        public async Task<int> DeleteAsync(ValidatableEntity entity) {
            _dataService.Entry(entity).State = EntityState.Deleted;

            try {
                return await _dataService.SaveChangesAsync();
            } catch (Exception ex) {
                Debug.WriteLine("LinkRepositoryAsync Exception while deleting entity!");
                Debug.WriteLine("Exception: " + ex.GetType().Name);
                Debug.WriteLine("Message: " + ex.Message);
                throw;
            }
        }