public async Task Should_Update_Edition()
        {
            var defaultEdition = UsingDbContext(context => context.Editions.FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName));

            defaultEdition.ShouldNotBeNull();

            var output = await _editionAppService.GetEditionForEdit(new NullableIdDto(defaultEdition.Id));

            //Changing a sample feature value
            var chatFeature = output.FeatureValues.FirstOrDefault(f => f.Name == AppFeatures.ChatFeature);

            if (chatFeature != null)
            {
                chatFeature.Value = chatFeature.Value = "true";
            }

            await _editionAppService.UpdateEdition(
                new UpdateEditionDto
            {
                Edition = new EditionEditDto
                {
                    Id          = output.Edition.Id,
                    DisplayName = "Regular Edition"
                },
                FeatureValues = output.FeatureValues
            });

            UsingDbContext(context =>
            {
                defaultEdition = context.Editions.FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);
                defaultEdition.ShouldNotBe(null);
                defaultEdition?.DisplayName.ShouldBe("Regular Edition");
            });
        }
Ejemplo n.º 2
0
        protected override async void Save()
        {
            //刷新界面设置的选项内容值
            RefreshInputInformation();

            if (!Verify(Model).IsValid)
            {
                return;
            }

            await SetBusyAsync(async() =>
            {
                var vals = SelectedItems
                           .Select(t => t as FlatFeatureModel)
                           .Select(q => new NameValueDto
                {
                    Name  = q.Name,
                    Value = bool.TryParse(q.DefaultValue, out bool result) ? result.ToString() : q.DefaultValue
                }).ToList();

                await WebRequest.Execute(async() =>
                {
                    if (Model.Id > 0)
                    {
                        await appService.UpdateEdition(new UpdateEditionDto()
                        {
                            Edition = Map <EditionEditDto>(Model), FeatureValues = vals,
                        });
                    }
                    else
                    {
                        await appService.CreateEdition(new CreateEditionDto()
                        {
                            Edition = Map <EditionCreateDto>(Model), FeatureValues = vals,
                        });
                    }
                }, async() =>
                {
                    base.Save();
                    await Task.CompletedTask;
                });
            });