Beispiel #1
0
        public async void CanDeleteRecordingCRUDTest()
        {
            DbContextOptions <LingDbContext> options =
                new DbContextOptionsBuilder <LingDbContext>()
                .UseInMemoryDatabase("LingUpdateDBContex")
                .Options;

            using (LingDbContext context = new LingDbContext(options))
            {
                Recording rec = new Recording();
                rec.Transcription = "English";
                rec.ID            = 1;

                context.Recordings.Add(rec);
                context.SaveChanges();
                var newRecording = await context.Recordings.FirstOrDefaultAsync(x => x.Transcription == rec.Transcription);

                context.Recordings.Remove(newRecording);
                context.SaveChanges();

                var deletedRecording = await context.Recordings.FirstOrDefaultAsync(l => l.Transcription == newRecording.Transcription);

                Assert.True(deletedRecording == null);
            }
        }
Beispiel #2
0
        public async void CanReadLangCRUDTest()
        {
            DbContextOptions <LingDbContext> options =
                new DbContextOptionsBuilder <LingDbContext>()
                .UseInMemoryDatabase("LingReadDBContex")
                .Options;

            using (LingDbContext context = new LingDbContext(options))
            {
                Language lang = new Language();
                lang.EnglishName = "English";
                lang.ISOCode     = "en-US";

                context.Languages.Add(lang);
                context.SaveChanges();

                var myLang = await context.Languages.FirstOrDefaultAsync(x => x.EnglishName == lang.EnglishName);

                Assert.Equal("en-US", myLang.ISOCode);
            }
        }
Beispiel #3
0
        public async void CanCreateLangCRUDTest()
        {
            DbContextOptions <LingDbContext> options =
                new DbContextOptionsBuilder <LingDbContext>()
                .UseInMemoryDatabase("LingCreateDBContex")
                .Options;

            using (LingDbContext context = new LingDbContext(options))
            {
                // Create
                Language lang = new Language();
                lang.EnglishName = "Dutch";
                lang.ISOCode     = "uk-EUR";

                context.Languages.Add(lang);
                context.SaveChanges();

                var createdLang = await context.Languages.FirstOrDefaultAsync(x => x.EnglishName == lang.EnglishName);

                Assert.Equal("Dutch", createdLang.EnglishName);
            }
        }
Beispiel #4
0
        public async void CanReadRecordingCRUDTest()
        {
            DbContextOptions <LingDbContext> options =
                new DbContextOptionsBuilder <LingDbContext>()
                .UseInMemoryDatabase("RecordingReadDBContex")
                .Options;

            using (LingDbContext context = new LingDbContext(options))
            {
                // Read
                Recording rec = new Recording();
                rec.Transcription = "English";
                rec.ID            = 1;

                context.Recordings.Add(rec);
                context.SaveChanges();

                var myRec = await context.Recordings.FirstOrDefaultAsync(x => x.Transcription == rec.Transcription);

                Assert.Equal(1, myRec.ID);
            }
        }
Beispiel #5
0
        public async void CanDeleteLangCRUDTest()
        {
            DbContextOptions <LingDbContext> options =
                new DbContextOptionsBuilder <LingDbContext>()
                .UseInMemoryDatabase("LingUpdateDBContex")
                .Options;

            using (LingDbContext context = new LingDbContext(options))
            {
                Language lang = new Language();
                lang.EnglishName = "English";
                lang.ISOCode     = "en-US";
                context.Languages.Add(lang);
                context.SaveChanges();
                var newLang = await context.Languages.FirstOrDefaultAsync(x => x.EnglishName == lang.EnglishName);

                context.Languages.Remove(newLang);
                context.SaveChanges();
                var deletedLang = await context.Languages.FirstOrDefaultAsync(l => l.EnglishName == newLang.EnglishName);

                Assert.True(deletedLang == null);
            }
        }
Beispiel #6
0
        public async void CanUpdateRecordingCRUDTest()
        {
            DbContextOptions <LingDbContext> options =
                new DbContextOptionsBuilder <LingDbContext>()
                .UseInMemoryDatabase("RecordingUpdateDBContex")
                .Options;

            using (LingDbContext context = new LingDbContext(options))
            {
                Recording rec = new Recording();
                rec.Transcription = "English";
                rec.ID            = 1;

                context.Recordings.Add(rec);
                context.SaveChanges();
                rec.Transcription = "Spanish";
                context.Recordings.Update(rec);
                context.SaveChanges();

                var newRecording = await context.Recordings.FirstOrDefaultAsync(l => l.Transcription == rec.Transcription);

                Assert.Equal("Spanish", newRecording.Transcription);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RecordingService"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="googleCredential">The google credential.</param>
 public RecordingService(LingDbContext context, GoogleCredential googleCredential)
 {
     _context          = context;
     _googleCredential = googleCredential;
 }
Beispiel #8
0
 public LanguageService(LingDbContext context)
 {
     _context = context;
 }