public async void All()
        {
            Mock <ILogger <StudentRepository> > loggerMoc = StudentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = StudentRepositoryMoc.GetContext();
            var repository = new StudentRepository(loggerMoc.Object, context);
            var records    = await repository.All();

            records.Should().NotBeEmpty();
            records.Count.Should().Be(1);
        }
        public async void AllWithSearch()
        {
            Mock <ILogger <StudentRepository> > loggerMoc = StudentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = StudentRepositoryMoc.GetContext();
            var repository = new StudentRepository(loggerMoc.Object, context);

            var records = await repository.All(1, 0, DateTime.Parse("1/1/1987 12:00:00 AM").ToString());

            records.Should().NotBeEmpty();
            records.Count.Should().Be(1);
        }
Example #3
0
        public async void Create()
        {
            Mock <ILogger <StudentRepository> > loggerMoc = StudentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = StudentRepositoryMoc.GetContext();
            var repository = new StudentRepository(loggerMoc.Object, context);

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

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

            record.Should().NotBeNull();
        }
        public void DeleteNotFound()
        {
            Mock <ILogger <StudentRepository> > loggerMoc = StudentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = StudentRepositoryMoc.GetContext();
            var repository = new StudentRepository(loggerMoc.Object, context);

            Func <Task> delete = async() =>
            {
                await repository.Delete(default(int));
            };

            delete.Should().NotThrow();
        }
Example #5
0
        public async void Get()
        {
            Mock <ILogger <StudentRepository> > loggerMoc = StudentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = StudentRepositoryMoc.GetContext();
            var repository = new StudentRepository(loggerMoc.Object, context);

            Student entity = new Student();

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

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

            record.Should().NotBeNull();
        }
        public async void Create()
        {
            Mock <ILogger <StudentRepository> > loggerMoc = StudentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = StudentRepositoryMoc.GetContext();
            var repository = new StudentRepository(loggerMoc.Object, context);

            var entity = new Student();

            entity.SetProperties(default(int), DateTime.Parse("1/1/1988 12:00:00 AM"), "B", true, 1, "B", true, "B", "B", true, 1);
            await repository.Create(entity);

            var records = await context.Set <Student>().ToListAsync();

            records.Count.Should().Be(2);
        }
Example #7
0
        public async void Delete()
        {
            Mock <ILogger <StudentRepository> > loggerMoc = StudentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = StudentRepositoryMoc.GetContext();
            var     repository           = new StudentRepository(loggerMoc.Object, context);
            Student entity = new Student();

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

            await repository.Delete(entity.Id);

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

            modifiedRecord.Should().BeNull();
        }
Example #8
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <StudentRepository> > loggerMoc = StudentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = StudentRepositoryMoc.GetContext();
            var     repository           = new StudentRepository(loggerMoc.Object, context);
            Student entity = new Student();

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

            await repository.Update(new Student());

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

            modifiedRecord.Should().NotBeNull();
        }
        public async void Get()
        {
            Mock <ILogger <StudentRepository> > loggerMoc = StudentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = StudentRepositoryMoc.GetContext();
            var repository = new StudentRepository(loggerMoc.Object, context);

            Student entity = new Student();

            entity.SetProperties(default(int), DateTime.Parse("1/1/1988 12:00:00 AM"), "B", true, 1, "B", true, "B", "B", true, 1);
            context.Set <Student>().Add(entity);
            await context.SaveChangesAsync();

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

            record.Should().NotBeNull();
        }
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <StudentRepository> > loggerMoc = StudentRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = StudentRepositoryMoc.GetContext();
            var     repository           = new StudentRepository(loggerMoc.Object, context);
            Student entity = new Student();

            entity.SetProperties(default(int), DateTime.Parse("1/1/1988 12:00:00 AM"), "B", true, 1, "B", true, "B", "B", true, 1);
            context.Set <Student>().Add(entity);
            await context.SaveChangesAsync();

            context.Entry(entity).State = EntityState.Detached;

            await repository.Update(entity);

            var records = await context.Set <Student>().ToListAsync();

            records.Count.Should().Be(2);
        }