public IMediaBuilder <TMediaType> Upload <TMediaType>(string file, Action <TMediaType> build = null) where TMediaType : MediaData
        {
            if (!File.Exists(file))
            {
                throw new FileNotFoundException($"could not find file {file}, verify that you have set \"Copy to Output Directory = Copy always\"");
            }

            var command = new UploadFile(
                IpsumGenerator.Generate(3, false).Replace(" ", "_"),
                file,
                Fixture.GetContentType(typeof(TMediaType)),
                GetParent()
                );

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

            var media = command.Execute();

            _medias.Add(media);

            return(new MediaBuilder <TMediaType>(Fixture, _medias));
        }
        public void Create_WhenSitePageHasBuilder_BuilderRun()
        {
            var heading = IpsumGenerator.Generate(1, 4, false);

            Fixture.RegisterBuilder <SitePage>(p => p.Heading = heading);

            Fixture.Create <ArticlePage>(p => Assert.Equal(heading, p.Heading));
        }
示例#3
0
        public void CreateBlock_WhenSiteBlockHasBuilder_BuilderRun()
        {
            var heading = IpsumGenerator.Generate(1, 4, false);

            Fixture.RegisterBuilder <SiteBlock>(p => p.Heading = heading);

            Fixture.CreateBlock <HeroBlock>(p => Assert.Equal(heading, p.Heading));
        }
示例#4
0
        public void CreateBlock_WhenBlockHasBuilder_BuilderRunFirst()
        {
            var preamble = IpsumGenerator.Generate(12, 14, false);

            Fixture.RegisterBuilder <HeroBlock>(p => p.Preamble = preamble);

            Fixture.CreateBlock <HeroBlock>(p => Assert.Equal(preamble, p.Preamble));
        }
示例#5
0
        public void CreateSite()
        {
            List <string> sellingPoints = new List <string>()
            {
                "Online meeting",
                "distance cooperation",
                "project calendar",
                "white board",
                "online presentations",
                "Project planning",
                "Reporting and statistics",
                "Email handling of tasks",
                "Risk calculations",
                "Direct communication to members",
            };

            Fixture.CreateSite <StartPage>()
            .CreateMany <ProductPage>(5, (p, _) =>
            {
                p.UniqueSellingPoints = sellingPoints.PickRandom(3, 7).ToList();
                p.MetaDescription     = IpsumGenerator.Generate(12, 23);
            })
            .Upload <ImageFile>(Resources.Get("/images"), (f, p) => {
                p.PageImage = f.ContentLink;
            })
            .Update <StartPage>((p, products) => {
                p.ProductPageLinks = new LinkItemCollection();

                foreach (var product in products)
                {
                    p.ProductPageLinks.Add(
                        new LinkItem()
                    {
                        Href = product.LinkURL,
                        Text = product.Name
                    });
                }
            });

            Fixture.CreateBlock <JumbotronBlock, StartPage>((b, s) =>
            {
                ProductPage product = (ProductPage)Fixture.Contents.Where(p => p is ProductPage).PickRandom();

                b.Heading    = product.Name;
                b.SubHeading = IpsumGenerator.Generate(15, 17, false);
                b.ButtonText = $"Read more";
                b.ButtonLink = new Url(product.LinkURL);

                s.MainContentArea = new ContentArea();

                s.MainContentArea.Items.Add(
                    new ContentAreaItem()
                {
                    ContentLink = b.GetContentLink()
                }
                    );
            });
        }
        public void Upload_WhenPageHasBuilder_BuilderRunFirst()
        {
            var alt = IpsumGenerator.Generate(12, 14, false);

            Fixture.RegisterBuilder <ImageFile>(p => p.Alt = alt);

            Fixture.Upload <ImageFile>(
                Resources.Get("/images").PickRandom(),
                p => Assert.Equal(alt, p.Alt)
                );
        }
        public void Upload_WhenSiteBlockHasBuilder_BuilderRun()
        {
            var heading = IpsumGenerator.Generate(1, 4, false);

            Fixture.RegisterBuilder <SiteImageFile>(p => p.Heading = heading);

            Fixture.Upload <ImageFile>(
                Resources.Get("/images").PickRandom(),
                p => Assert.Equal(heading, p.Heading)
                );
        }
        public void Upload_WithBuildAction_ImageIsPublished()
        {
            string heading = IpsumGenerator.Generate(2, 5, false);

            Fixture.Upload <ImageFile>(Resources.Get("/images").PickRandom(), p => p.Heading = heading);

            Assert.IsPublished(Fixture.Latest);
            Assert.Equal(
                heading,
                ((ImageFile)Fixture.Latest.First()).Heading
                );
        }
示例#9
0
        public void Create_WithBuildAction_PageIsPublished()
        {
            string heading = IpsumGenerator.Generate(2, 5, false);

            Fixture.Create <StartPage>(p => p.Heading = heading);

            Assert.IsPublished(Fixture.Latest);
            Assert.Equal(
                heading,
                ((StartPage)Fixture.Latest.First()).Heading
                );
        }
示例#10
0
        public void Update_WithLatest_LatestPageIsUpdated()
        {
            string expected = "Updated";

            Fixture.Create <StartPage>(p => p.Heading = IpsumGenerator.Generate(2, 3, false));
            Fixture.Update <StartPage>(p => p.Heading = "Updated");

            Assert.Equal(
                expected,
                ((StartPage)Fixture.Latest.First()).Heading
                );
        }
        public void Create_WithBuildAction_BlockIsPublished()
        {
            string heading = IpsumGenerator.Generate(2, 5, false);

            Fixture.CreateBlock <HeroBlock>(p => p.Heading = heading);

            Assert.IsPublished(Fixture.Latest);
            Assert.Equal(
                heading,
                ((HeroBlock)Fixture.Latest.First()).Heading
                );
        }
        private void Create <TPageType>(ContentReference parent, CultureInfo culture = null, Action <TPageType> build = null)
            where TPageType : PageData
        {
            TPageType page = 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 (page is null)
                {
                    var command = new CreatePage(
                        Fixture.GetContentType(typeof(TPageType)),
                        parent,
                        IpsumGenerator.Generate(1, 3, false)
                        );

                    command.Culture = c;

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

                    page = (TPageType)command.Execute();
                    Add(page);

                    continue;
                }

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

                Update((T)(PageData)page, c, p => build.Invoke((TPageType)(PageData)p));
            }
        }
示例#13
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));
            }
        }
        public IMediaBuilder <TMediaType> Upload <TMediaType>(string file, ContentReference parent, Action <TMediaType> build = null) where TMediaType : MediaData
        {
            ValidateFile(file);

            var command = new UploadFile(
                IpsumGenerator.Generate(3, false).Replace(" ", "_"),
                file,
                Fixture.GetContentType(typeof(TMediaType)),
                parent
                );

            command.Build = CreateBuild(build);

            var media = command.Execute();

            _medias.Add(media);

            return(new MediaBuilder <TMediaType>(Fixture, _medias));
        }
示例#16
0
 public ActionResult Search(string search)
 {
     if (!String.IsNullOrEmpty(search))
     {
         // AR-139 Requirement: letting users to search with & character
         // that is searching using multiple words
         if (Regex.IsMatch(search, @"[\'\<\(\&\;]"))
         {
             ViewBag.Search = "-";
             ViewBag.Result = "Bad Input!";
         }
         else
         {
             ViewBag.Search = search;
             ViewBag.Result = IpsumGenerator.GenerateIpsum(3);
         }
     }
     return(View());
 }
        private IMediaBuilder <TMediaType> UploadWhenHasLatest <TMediaType>(string file, Action <TMediaType> build)
            where TMediaType : MediaData
        {
            foreach (var latest in Fixture.Latest)
            {
                var command = new UploadFile(
                    IpsumGenerator.Generate(3, false).Replace(" ", "_"),
                    file,
                    Fixture.GetContentType(typeof(TMediaType)),
                    GetParent(latest)
                    );

                command.Build = CreateBuild(build);

                var media = command.Execute();
                _medias.Add(media);
            }

            return(new MediaBuilder <TMediaType>(Fixture, _medias));
        }
示例#18
0
        public ActionResult Search(string search)
        {
            if (!String.IsNullOrEmpty(search))
            {
                // AR-342 Requirement: being able to search
                // multiple words with & and empty characters

                // AR-572 Fast Track: being able to search
                // similar words with # character
                if (Regex.IsMatch(search, @"^[\w]+$"))
                {
                    ViewBag.Search = search;
                    ViewBag.Result = IpsumGenerator.GenerateIpsum(3);
                }
                else
                {
                    ViewBag.Search = "-";
                    ViewBag.Result = "Bad Input!";
                }
            }
            return(View());
        }
        public IMediaBuilder <TMediaType> Upload <TMediaType>(string file, Action <TMediaType> build = null) where TMediaType : MediaData
        {
            ValidateFile(file);

            if (Fixture.Latest.Count > 0)
            {
                return(UploadWhenHasLatest(file, build));
            }

            var command = new UploadFile(
                IpsumGenerator.Generate(3, false).Replace(" ", "_"),
                file,
                Fixture.GetContentType(typeof(TMediaType)),
                GetParent()
                );

            command.Build = CreateBuild(build);

            var media = command.Execute();

            _medias.Add(media);

            return(new MediaBuilder <TMediaType>(Fixture, _medias));
        }
示例#20
0
 public ActionResult Search(string search)
 {
     ViewBag.Search = search;
     ViewBag.Result = IpsumGenerator.GenerateIpsum(3);
     return(View());
 }
示例#21
0
        public async void CreateSite(int _)
        {
            List <string> sellingPoints = new List <string>()
            {
                "Online meeting",
                "distance cooperation",
                "project calendar",
                "white board",
                "online presentations",
                "Project planning",
                "Reporting and statistics",
                "Email handling of tasks",
                "Risk calculations",
                "Direct communication to members",
            };

            var cultures = new CultureInfo[]
            {
                CultureInfo.GetCultureInfo("sv"),
                CultureInfo.GetCultureInfo("en")
            };

            Fixture.CreateSite <StartPage>(cultures)
            .CreateMany <ProductPage>(5, (p, _) =>
            {
                p.UniqueSellingPoints = sellingPoints.PickRandom(3, 7).ToList();
                p.MetaDescription     = IpsumGenerator.Generate(12, 23);
            })
            .Update <StartPage>((p, products) => {
                p.ProductPageLinks = new LinkItemCollection();

                foreach (var product in products)
                {
                    p.ProductPageLinks.Add(
                        new LinkItem()
                    {
                        Href = product.LinkURL,
                        Text = product.Name
                    });
                }
            });

            /*
             * Fixture.CreateBlock<JumbotronBlock, StartPage>((b, s) =>
             * {
             *  ProductPage product = (ProductPage)Fixture.Contents.Where(p => p is ProductPage).PickRandom();
             *
             *  b.Heading = product.Name;
             *  b.SubHeading = IpsumGenerator.Generate(15, 17, false);
             *  b.ButtonText = $"Read more";
             *  b.ButtonLink = new Url(product.LinkURL);
             *
             *  s.MainContentArea = new ContentArea();
             *
             *  s.MainContentArea.Items.Add(
             *      new ContentAreaItem() { ContentLink = b.GetContentLink() }
             *  );
             * });
             *
             * var client = Fixture.Engine.CreateClient();
             *
             * var response = await client.GetAsync("/");
             * response.EnsureSuccessStatusCode();
             */
        }