/// <inheritdoc />
        public async Task <long> CreateAsync(DesignatedChannelMappingCreationData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            var entity = data.ToEntity();

            await ModixContext.Set <DesignatedChannelMappingEntity>().AddAsync(entity);

            await ModixContext.SaveChangesAsync();

            entity.CreateAction.DesignatedChannelMappingId = entity.Id;
            await ModixContext.SaveChangesAsync();

            return(entity.Id);
        }
Beispiel #2
0
        public async Task CreateAsync_DataIsNotNull_InsertsDesignatedChannelMapping(DesignatedChannelMappingCreationData data)
        {
            (var modixContext, var uut) = BuildTestContext();

            var id = await uut.CreateAsync(data);

            modixContext.DesignatedChannelMappings.ShouldContain(x => x.Id == id);
            var designatedChannelMapping = modixContext.DesignatedChannelMappings.First(x => x.Id == id);

            designatedChannelMapping.GuildId.ShouldBe(data.GuildId);
            designatedChannelMapping.Type.ShouldBe(data.Type);
            designatedChannelMapping.ChannelId.ShouldBe(data.ChannelId);
            designatedChannelMapping.CreateActionId.ShouldNotBeNull();
            designatedChannelMapping.DeleteActionId.ShouldBeNull();

            modixContext.DesignatedChannelMappings.Where(x => x.Id != designatedChannelMapping.Id).Select(x => x.Id).ShouldBe(DesignatedChannelMappings.Entities.Select(x => x.Id));
            modixContext.DesignatedChannelMappings.Where(x => x.Id != designatedChannelMapping.Id).EachShould(x => x.ShouldNotHaveChanged());

            modixContext.ConfigurationActions.ShouldContain(x => x.Id == designatedChannelMapping.CreateActionId);
            var createAction = modixContext.ConfigurationActions.First(x => x.Id == designatedChannelMapping.CreateActionId);

            createAction.GuildId.ShouldBe(data.GuildId);
            createAction.Type.ShouldBe(ConfigurationActionType.DesignatedChannelMappingCreated);
            createAction.Created.ShouldBeInRange(
                DateTimeOffset.Now - TimeSpan.FromSeconds(1),
                DateTimeOffset.Now + TimeSpan.FromSeconds(1));
            createAction.CreatedById.ShouldBe(data.CreatedById);
            createAction.ClaimMappingId.ShouldBeNull();
            createAction.DesignatedChannelMappingId.ShouldBe(designatedChannelMapping.Id);
            createAction.DesignatedRoleMappingId.ShouldBeNull();

            modixContext.ConfigurationActions.Where(x => x.Id != createAction.Id).Select(x => x.Id).ShouldBe(ConfigurationActions.Entities.Where(x => !(x.DesignatedChannelMappingId is null)).Select(x => x.Id));
            modixContext.ConfigurationActions.Where(x => x.Id != createAction.Id).EachShould(x => x.ShouldNotHaveChanged());

            await modixContext.ShouldHaveReceived(2)
            .SaveChangesAsync();
        }