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

            await sut.SaveSocial(new SocialField {
                AuthorId = 0,
                Title    = "Facebook",
                Icon     = "fa-facebook",
                Name     = "social|facebook|1",
                Rank     = 1,
                Content  = "http://your.facebook.page.com"
            });

            var socials = await sut.GetSocial();

            Assert.NotNull(socials);

            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);
        }
Exemplo n.º 2
0
        public void Delete(int id)
        {
            var customFieldToDelete = CustomFieldRepository.Items.SingleOrDefault(c => c.Id == id);

            if (customFieldToDelete == null)
            {
                throw new EntityNotFoundException("Specified custom field does not exist");
            }
            if (CustomFieldValueRepository.Items.Any(v => v.CustomFieldId == id))
            {
                throw new ValidationException(new ValidationResult("Custom field has associated values and cannot be deleted"), null, id);
            }
            CustomFieldRepository.Remove(customFieldToDelete);
            RepositoryContainer.Save();
        }
        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);
        }