Пример #1
0
        public async void Create()
        {
            Mock <ILogger <DepartmentRepository> > loggerMoc = DepartmentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DepartmentRepositoryMoc.GetContext();
            var repository = new DepartmentRepository(loggerMoc.Object, context);

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

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

            record.Should().NotBeNull();
        }
Пример #2
0
        public async void Get()
        {
            Mock <ILogger <DepartmentRepository> > loggerMoc = DepartmentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DepartmentRepositoryMoc.GetContext();
            var repository = new DepartmentRepository(loggerMoc.Object, context);

            Department entity = new Department();

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

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

            record.Should().NotBeNull();
        }
Пример #3
0
        public async void Delete()
        {
            Mock <ILogger <DepartmentRepository> > loggerMoc = DepartmentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DepartmentRepositoryMoc.GetContext();
            var        repository        = new DepartmentRepository(loggerMoc.Object, context);
            Department entity            = new Department();

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

            await repository.Delete(entity.DepartmentID);

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

            modifiedRecord.Should().BeNull();
        }
Пример #4
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <DepartmentRepository> > loggerMoc = DepartmentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DepartmentRepositoryMoc.GetContext();
            var        repository        = new DepartmentRepository(loggerMoc.Object, context);
            Department entity            = new Department();

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

            await repository.Update(new Department());

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

            modifiedRecord.Should().NotBeNull();
        }