Exemplo n.º 1
0
        public async void Create()
        {
            Mock <ILogger <ProductRepository> > loggerMoc = ProductRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ProductRepositoryMoc.GetContext();
            var repository = new ProductRepository(loggerMoc.Object, context);

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

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

            record.Should().NotBeNull();
        }
Exemplo n.º 2
0
        public async void Get()
        {
            Mock <ILogger <ProductRepository> > loggerMoc = ProductRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ProductRepositoryMoc.GetContext();
            var repository = new ProductRepository(loggerMoc.Object, context);

            Product entity = new Product();

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

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

            record.Should().NotBeNull();
        }
Exemplo n.º 3
0
        public async void Delete()
        {
            Mock <ILogger <ProductRepository> > loggerMoc = ProductRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ProductRepositoryMoc.GetContext();
            var     repository           = new ProductRepository(loggerMoc.Object, context);
            Product entity = new Product();

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

            await repository.Delete(entity.ProductID);

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

            modifiedRecord.Should().BeNull();
        }
Exemplo n.º 4
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <ProductRepository> > loggerMoc = ProductRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ProductRepositoryMoc.GetContext();
            var     repository           = new ProductRepository(loggerMoc.Object, context);
            Product entity = new Product();

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

            await repository.Update(new Product());

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

            modifiedRecord.Should().NotBeNull();
        }