Пример #1
0
        public async Task TestRead()
        {
            MiniLinkContext             context  = GetContext();
            IBaseRepository <LinkEntry> linkRepo = new BaseRepository <LinkEntry>(context);

            async Task ResetRepo()
            {
                context.Dispose();
                context  = GetContext();
                linkRepo = new BaseRepository <LinkEntry>(context);
                return;
            }

            var entry  = new LinkEntry("https://www.google.com/", "", DateTime.UtcNow);
            var entry2 = new LinkEntry("https://www.facebook.com/", "", DateTime.UtcNow);

            await linkRepo.InsertAsync(entry);

            await linkRepo.InsertAsync(entry2);

            var save = await linkRepo.SaveChangesAsync();

            await ResetRepo();

            var readEntry = await linkRepo.GetByIdAsync(entry.Id);

            Assert.Equal(entry.Id, readEntry.Id);
            Assert.Equal(entry.URL, readEntry.URL);

            var readAll = await linkRepo.GetAllAsync();

            Assert.Equal(2, readAll.Count);

            context.Dispose();
        }
Пример #2
0
        public async Task TestDelete()
        {
            MiniLinkContext             context  = GetContext();
            IBaseRepository <LinkEntry> linkRepo = new BaseRepository <LinkEntry>(context);

            async Task ResetRepo()
            {
                context.Dispose();
                context  = GetContext();
                linkRepo = new BaseRepository <LinkEntry>(context);
                return;
            }

            var entry = new LinkEntry("https://www.google.com/", "", DateTime.UtcNow);

            await linkRepo.InsertAsync(entry);

            await linkRepo.SaveChangesAsync();

            await ResetRepo();

            var entryToDelete = await linkRepo.GetByIdAsync(entry.Id);

            await linkRepo.DeleteAsync(entryToDelete);

            await linkRepo.SaveChangesAsync();

            await ResetRepo();

            var deletedEntry = await linkRepo.GetByIdAsync(entry.Id);

            Assert.True(deletedEntry == default(LinkEntry));

            context.Dispose();
        }
        public async Task TestInsertAndGetByBase64Id()
        {
            MiniLinkContext                  context = GetContext();
            IBaseRepository <LinkEntry>      linkRepo;
            IBaseRepository <LinkEntryVisit> linkVisitRepo;

            MemoryCacheOptions options;
            IMemoryCache       cache;

            async Task <ILinkEntryService> SetupAsync()
            {
                context = GetContext();

                linkRepo      = new BaseRepository <LinkEntry>(context);
                linkVisitRepo = new BaseRepository <LinkEntryVisit>(context);

                var          options = new MemoryCacheOptions();
                IMemoryCache cache   = new MemoryCache(options);

                return(new LinkEntryService(linkRepo, linkVisitRepo, cache));
            }

            ILinkEntryService linkEntryService = await SetupAsync();

            var url = "https://www.google.com/";
            var add = await linkEntryService.AddLinkEntry(url, "");

            Assert.True(add.Success);

            // reset context to ensue ef doesnt keep the results
            context.Dispose();

            linkEntryService = await SetupAsync();

            var fetch = await linkEntryService.GetLinkEntryByBase64Id(add.Entry.Base64Id, true);

            Assert.Equal(fetch.URL, url);

            context.Dispose();
        }
Пример #4
0
        public async Task TestUpdate()
        {
            MiniLinkContext             context  = GetContext();
            IBaseRepository <LinkEntry> linkRepo = new BaseRepository <LinkEntry>(context);

            async Task ResetRepo()
            {
                context.Dispose();
                context  = GetContext();
                linkRepo = new BaseRepository <LinkEntry>(context);
                return;
            }

            var entry = new LinkEntry("https://www.google.com/", "", DateTime.UtcNow);

            await linkRepo.InsertAsync(entry);

            var save = await linkRepo.SaveChangesAsync();

            await ResetRepo();

            var readEntry = await linkRepo.GetByIdAsync(entry.Id);

            readEntry.Visits = 5;

            await linkRepo.UpdateAsync(readEntry);

            await linkRepo.SaveChangesAsync();

            await ResetRepo();

            var updatedEntry = await linkRepo.GetByIdAsync(entry.Id);

            Assert.Equal(readEntry.Visits, updatedEntry.Visits);
            Assert.True(entry.Visits != updatedEntry.Visits);

            context.Dispose();
        }
Пример #5
0
        public async Task TestInsert()
        {
            MiniLinkContext             context  = GetContext();
            IBaseRepository <LinkEntry> linkRepo = new BaseRepository <LinkEntry>(context);


            var entry  = new LinkEntry("https://www.google.com/", "", DateTime.UtcNow);
            var entry2 = new LinkEntry("https://www.facebook.com/", "", DateTime.UtcNow);

            await linkRepo.InsertAsync(entry);

            await linkRepo.InsertAsync(entry2);

            var save = await linkRepo.SaveChangesAsync();

            Assert.Equal(2, save);

            context.Dispose();
        }