public async Task CanSaveAndGetCustomField()
        {
            var db  = GetSut();
            var sut = new CustomFieldRepository(db);

            sut.Add(new CustomField {
                AuthorId = 1, Name = "social|facebook|1", Content = "http://your.facebook.page.com"
            });
            await db.SaveChangesAsync();

            var result = sut.Single(f => f.Name.Contains("social|facebook"));

            Assert.NotNull(result);

            sut.Remove(result);
            await db.SaveChangesAsync();

            result = sut.Single(f => f.Name.Contains("social|facebook"));
            Assert.Null(result);
        }
示例#2
0
        public void Create(CustomFieldModel viewModel, EducationSecurityPrincipal user)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            CustomField item = CreateFieldEntity();

            viewModel.CopyTo(item);
            item.Categories = CustomFieldCategoryRepository.Items.Where(c => viewModel.SelectedCategories.Contains(c.Id)).ToList();
            if (item.Categories.Count != viewModel.SelectedCategories.Count())
            {
                throw new EntityNotFoundException("At least one selected category could not be found.");
            }
            item.CreatingUserId = user.Identity.UserEntity.Id;
            CustomFieldRepository.Add(item);
            RepositoryContainer.Save();
        }