Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }