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

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

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

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

            KeyAllocation entity = new KeyAllocation();

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

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

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

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

            await repository.Delete(entity.CollectionName);

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

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

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

            await repository.Update(new KeyAllocation());

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

            modifiedRecord.Should().NotBeNull();
        }