public async Task CreateAsync_GuildRoleDoesNotExist_InsertsGuildRole(GuildRoleCreationData data)
        {
            (var modixContext, var uut) = BuildTestContext();

            await uut.CreateAsync(data);

            modixContext.GuildRoles.ShouldContain(x => x.RoleId == data.RoleId);
            var role = modixContext.GuildRoles.First(x => x.RoleId == data.RoleId);

            role.GuildId.ShouldBe(data.GuildId);
            role.Name.ShouldBe(data.Name);
            role.Position.ShouldBe(data.Position);

            modixContext.GuildRoles
            .Where(x => x.RoleId != role.RoleId)
            .Select(x => x.RoleId)
            .ShouldBe(GuildRoles.Entities
                      .Select(x => x.RoleId));

            modixContext.GuildRoles
            .Where(x => x.RoleId != role.RoleId)
            .EachShould(x => x.ShouldNotHaveChanged());

            await modixContext.ShouldHaveReceived(1)
            .SaveChangesAsync();
        }
Example #2
0
        /// <inheritdoc />
        public async Task CreateAsync(GuildRoleCreationData data)
        {
            if (data == null)
                throw new ArgumentNullException(nameof(data));

            var entity = data.ToEntity();

            await ModixContext.GuildRoles.AddAsync(entity);
            await ModixContext.SaveChangesAsync();
        }
        public async Task CreateAsync_GuildRoleExists_DoesNotUpdateGuildRolesAndThrowsException(GuildRoleCreationData data)
        {
            (var modixContext, var uut) = BuildTestContext();

            await Should.ThrowAsync <InvalidOperationException>(uut.CreateAsync(data));

            modixContext.GuildRoles
            .Select(x => x.RoleId)
            .ShouldBe(GuildRoles.Entities
                      .Select(x => x.RoleId));

            modixContext.GuildRoles
            .EachShould(x => x.ShouldNotHaveChanged());

            await modixContext.ShouldNotHaveReceived()
            .SaveChangesAsync();
        }