コード例 #1
0
        public async void Create()
        {
            Mock <ILogger <ProductCategoryRepository> > loggerMoc = ProductCategoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ProductCategoryRepositoryMoc.GetContext();
            var repository = new ProductCategoryRepository(loggerMoc.Object, context);

            var entity = new ProductCategory();
            await repository.Create(entity);

            var record = await context.Set <ProductCategory>().FirstOrDefaultAsync();

            record.Should().NotBeNull();
        }
コード例 #2
0
        public async void Get()
        {
            Mock <ILogger <ProductCategoryRepository> > loggerMoc = ProductCategoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ProductCategoryRepositoryMoc.GetContext();
            var repository = new ProductCategoryRepository(loggerMoc.Object, context);

            ProductCategory entity = new ProductCategory();

            context.Set <ProductCategory>().Add(entity);
            await context.SaveChangesAsync();

            var record = await repository.Get(entity.ProductCategoryID);

            record.Should().NotBeNull();
        }
コード例 #3
0
        public async void Delete()
        {
            Mock <ILogger <ProductCategoryRepository> > loggerMoc = ProductCategoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ProductCategoryRepositoryMoc.GetContext();
            var             repository   = new ProductCategoryRepository(loggerMoc.Object, context);
            ProductCategory entity       = new ProductCategory();

            context.Set <ProductCategory>().Add(entity);
            await context.SaveChangesAsync();

            await repository.Delete(entity.ProductCategoryID);

            ProductCategory modifiedRecord = await context.Set <ProductCategory>().FirstOrDefaultAsync();

            modifiedRecord.Should().BeNull();
        }
コード例 #4
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <ProductCategoryRepository> > loggerMoc = ProductCategoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ProductCategoryRepositoryMoc.GetContext();
            var             repository   = new ProductCategoryRepository(loggerMoc.Object, context);
            ProductCategory entity       = new ProductCategory();

            context.Set <ProductCategory>().Add(entity);
            await context.SaveChangesAsync();

            await repository.Update(new ProductCategory());

            var modifiedRecord = context.Set <ProductCategory>().FirstOrDefaultAsync();

            modifiedRecord.Should().NotBeNull();
        }