Пример #1
0
        public async Task TestFirstOrDefault2WhenInDbAsync()
        {
            await using var context = new EspeonDbContext(this._options);
            var prefix = await context.GuildPrefixes.FirstOrDefault2Async(prefixes => prefixes.GuildId == GuildId);

            Assert.NotNull(prefix);
        }
Пример #2
0
        public async Task TestFindAndIncludeAsync()
        {
            await using var context = new EspeonDbContext(this._options);
            var tags = await context.IncludeAndFindAsync <GuildTags, GuildTag, ulong>(
                GuildId,
                tags => tags.Values);

            Assert.NotNull(tags);
            Assert.NotNull(tags.Values);
        }
Пример #3
0
        public async Task TestRemoveAsync()
        {
            await using var context = new EspeonDbContext(this._options);
            var prefixes = await context.GuildPrefixes.FindAsync(GuildId);

            await context.RemoveAsync(prefixes);

            prefixes = await context.GuildPrefixes.FindAsync(GuildId);

            Assert.Null(prefixes);
        }
Пример #4
0
        public async Task TestPersistAsync()
        {
            const ulong guildId = 1;

            await using var context = new EspeonDbContext(this._options);
            await context.PersistAsync(new GuildPrefixes(guildId));

            var found = await context.GuildPrefixes.FindAsync(guildId);

            Assert.NotNull(found);
        }
Пример #5
0
        public async Task TestGetOrCreate2IdWhenInDbAsync()
        {
            await using var context = new EspeonDbContext(this._options);
            var local = await context.GetOrCreateAsync <UserLocalisation, ulong>(
                GuildId,
                UserId,
                (guildId, userId) => throw new InvalidOperationException("Entity should be in db"));

            Assert.AreEqual(GuildId, local.GuildId);
            Assert.AreEqual(UserId, local.UserId);
            Assert.AreEqual(Language.Owo, local.Value);
        }
Пример #6
0
        public async Task TestGetOrCreate2IdWhenNotInDbAsync()
        {
            const ulong guildId = 1;
            const ulong userId  = 1;

            await using var context = new EspeonDbContext(this._options);
            var local = await context.GetOrCreateAsync(
                guildId,
                userId,
                (guildId, userId) => new UserLocalisation(guildId, userId));

            Assert.AreEqual(guildId, local.GuildId);
            Assert.AreEqual(userId, local.UserId);
            Assert.AreEqual(Language.Default, local.Value);
        }
Пример #7
0
        public async Task TestUpdateAsync()
        {
            await using var context = new EspeonDbContext(this._options);
            var tags = await context.IncludeAndFindAsync <GuildTags, GuildTag, ulong>(
                GuildId,
                tags => tags.Values);

            tags.Values.Add(new GuildTag(GuildId, "espeon", "tag", UserId));
            await context.UpdateAsync(tags);

            var tags2 = await context.IncludeAndFindAsync <GuildTags, GuildTag, ulong>(
                GuildId,
                tags => tags.Values);

            CollectionAssert.AreEquivalent(tags.Values, tags2.Values);
        }
Пример #8
0
        public async Task TestGetOrCreate1IdWhenNotInDbAsync()
        {
            const ulong guildId = 1;

            await using var context = new EspeonDbContext(this._options);
            var prefixes = await context.GetOrCreateAsync(
                guildId,
                guildId => new GuildPrefixes(guildId));

            Assert.AreEqual(guildId, prefixes.GuildId);
            CollectionAssert.AreEquivalent(
                new IPrefix[] {
                MentionPrefix.Instance,
                new StringPrefix("es/")
            },
                prefixes.Values);
        }
Пример #9
0
        public async Task BeforeEachAsync()
        {
            this._options = new DbContextOptionsBuilder()
                            .UseInMemoryDatabase("espeon")
                            .Options;

            await using var context = new EspeonDbContext(this._options);

            await context.UserLocalisations.AddAsync(new UserLocalisation(GuildId, UserId) {
                Value = Language.Owo
            });

            await context.GuildPrefixes.AddAsync(new GuildPrefixes(GuildId));

            await context.GuildTags.AddAsync(new GuildTags(GuildId));

            await context.SaveChangesAsync();
        }
Пример #10
0
        public async Task TestGetOrCreate1IdWhenInDbAsync()
        {
            await using var context = new EspeonDbContext(this._options);
            var prefixes = await context.GetOrCreateAsync <GuildPrefixes, ulong>(
                GuildId,
                guildId => throw new InvalidOperationException("Entity should be in db"));

            //this should really test against a different set to the default
            //but there's a bug with inmemory database that means even though
            //we save a modified one, we will get the default one when we construct
            //a new context
            Assert.AreEqual(GuildId, prefixes.GuildId);
            CollectionAssert.AreEquivalent(
                new IPrefix[] {
                MentionPrefix.Instance,
                new StringPrefix("es/")
            },
                prefixes.Values);
        }
Пример #11
0
 public async Task AfterEachAsync()
 {
     await using var context = new EspeonDbContext(this._options);
     await context.Database.EnsureDeletedAsync();
 }