Beispiel #1
0
        public void VerifyCatalogGroupDelete_Throws_InvalidOperationException_When_There_Are_Dependencies()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>().UseInMemoryDatabase("delete_cataloggroup_invalidoperationexception").Options;

            using (var context = new AppDbContext(options))
            {
                var repository = new CatalogMetadataRepository(context);

                CatalogMetadata metadata = repository.CreateCatalogMetadata(new CatalogMetadata()
                {
                    ProductCode  = "testProductCode",
                    Description  = "testProductDescription",
                    Title        = "testTitle",
                    CatalogGroup = new CatalogGroup()
                    {
                        GroupName        = "testGroupName",
                        GroupDescription = "testGroupDescription",
                        CatalogCategory  = new CatalogCategory()
                        {
                            CategoryId   = 1,
                            CategoryName = "testCategoryName",
                        },
                    },
                });

                Assert.True(metadata.CatalogGroupId > 0);

                Assert.Throws <InvalidOperationException>(() => repository.DeleteCatalogGroup(metadata.CatalogGroupId));
            }
        }
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     CatalogMetadata.OnModelCreating(modelBuilder);
     CatalogGroup.OnModelCreating(modelBuilder);
     CatalogCategory.OnModelCreating(modelBuilder);
     CatalogDiscount.OnModelCreating(modelBuilder);
     base.OnModelCreating(modelBuilder);
 }
Beispiel #3
0
        public CatalogMetadata UpdateCatalogMetadata(CatalogMetadata updatedEntity)
        {
            var existingObj = this.context.CatalogMetadatadbset.Where(p => p.Id == updatedEntity.Id).FirstOrDefault();

            if (existingObj == null)
            {
                throw new RowNotInTableException("row not found with the given entity id ");
            }

            this.context.Entry(existingObj).CurrentValues.SetValues(updatedEntity);
            this.context.SaveChanges();
            return(updatedEntity);
        }
Beispiel #4
0
 public CatalogMetadata CreateCatalogMetadata(CatalogMetadata entity)
 {
     this.context.CatalogMetadatadbset.Add(entity);
     this.context.SaveChanges();
     return(entity);
 }