Пример #1
0
        private void CreateBlock <TBlockType>(ContentReference parent, Action <TBlockType> build = null)
            where TBlockType : BlockData
        {
            var command = new CreateBlock(
                Fixture.GetContentType(typeof(TBlockType)),
                parent,
                IpsumGenerator.Generate(1, 3, false)
                );

            if (build != null)
            {
                command.Build = p => build.Invoke((TBlockType)p);
            }

            _blocks.Add(command.Execute());
        }
        private void CreateBlock <TBlockType>(ContentReference parent, CultureInfo culture = null, Action <TBlockType> build = null)
            where TBlockType : BlockData
        {
            TBlockType block = default;

            if (Fixture.Cultures.Count == 0)
            {
                throw new InvalidOperationException("Need atleast one culture");
            }

            List <CultureInfo> cultures = new List <CultureInfo>(Fixture.Cultures);

            if (culture != null)
            {
                cultures.Clear();
                cultures.Add(culture);
            }

            foreach (var c in cultures)
            {
                if (block is null)
                {
                    var command = new CreateBlock(
                        Fixture.GetContentType(typeof(TBlockType)),
                        parent,
                        IpsumGenerator.Generate(1, 3, false)
                        );

                    command.Culture = c;
                    command.Build   = CreateBuild(build);

                    block = (TBlockType)command.Execute();
                    Add(block);

                    continue;
                }

                if (build == null)
                {
                    Update(block, c, null);
                    continue;
                }

                Update((TBlockType)(BlockData)block, c, p => build.Invoke((TBlockType)(BlockData)p));
            }
        }