public async Task CreateDIGeneric() { using (var api = CreateApi()) { var page = await MyDIPage.CreateAsync(api); Assert.NotNull(page); Assert.Equal("My service value", page.Body.Value); } }
public override async Task InitializeAsync() { _services = CreateServiceCollection() .AddSingleton <IMyService, MyService>() .BuildServiceProvider(); using (var api = CreateApi()) { Piranha.App.Init(api); Piranha.App.Fields.Register <MyFourthField>(); new ContentTypeBuilder(api) .AddType(typeof(MissingPage)) .AddType(typeof(MyBlogPage)) .AddType(typeof(MyPage)) .AddType(typeof(MyCollectionPage)) .AddType(typeof(MyDIPage)) .Build(); var site = new Site { Id = SITE_ID, Title = "My Test Site", InternalId = "MyTestSite", IsDefault = true }; await api.Sites.SaveAsync(site); var page1 = await MyPage.CreateAsync(api); page1.Id = PAGE_1_ID; page1.SiteId = SITE_ID; page1.Title = "My first page"; page1.MetaKeywords = "Keywords"; page1.MetaDescription = "Description"; page1.OgTitle = "Og Title"; page1.OgDescription = "Og Description"; page1.Ingress = "My first ingress"; page1.Body = "My first body"; page1.Blocks.Add(new Extend.Blocks.TextBlock { Body = "Sollicitudin Aenean" }); page1.Blocks.Add(new Extend.Blocks.TextBlock { Body = "Ipsum Elit" }); page1.Published = DateTime.Now; await api.Pages.SaveAsync(page1); var page2 = await MyPage.CreateAsync(api); page2.Id = PAGE_2_ID; page2.SiteId = SITE_ID; page2.Title = "My second page"; page2.MetaFollow = false; page2.MetaIndex = false; page2.Ingress = "My second ingress"; page2.Body = "My second body"; await api.Pages.SaveAsync(page2); var page3 = await MyPage.CreateAsync(api); page3.Id = PAGE_3_ID; page3.SiteId = SITE_ID; page3.Title = "My third page"; page3.Ingress = "My third ingress"; page3.Body = "My third body"; await api.Pages.SaveAsync(page3); var page4 = await MyCollectionPage.CreateAsync(api); page4.SiteId = SITE_ID; page4.Title = "My collection page"; page4.SortOrder = 1; page4.Texts.Add(new TextField { Value = "First text" }); page4.Texts.Add(new TextField { Value = "Second text" }); page4.Texts.Add(new TextField { Value = "Third text" }); await api.Pages.SaveAsync(page4); var page5 = await MyBlogPage.CreateAsync(api); page5.SiteId = SITE_ID; page5.Title = "Blog Archive"; await api.Pages.SaveAsync(page5); var page6 = await MyDIPage.CreateAsync(api); page6.Id = PAGE_DI_ID; page6.SiteId = SITE_ID; page6.Title = "My Injection Page"; await api.Pages.SaveAsync(page6); var page7 = await MyPage.CreateAsync(api); page7.Id = PAGE_7_ID; page7.SiteId = SITE_ID; page7.Title = "My base page"; page7.Ingress = "My base ingress"; page7.Body = "My base body"; page7.ParentId = PAGE_1_ID; page7.SortOrder = 1; await api.Pages.SaveAsync(page7); var page8 = await MyPage.CreateAsync(api); page8.OriginalPageId = PAGE_7_ID; page8.Id = PAGE_8_ID; page8.SiteId = SITE_ID; page8.Title = "My copied page"; page8.ParentId = PAGE_1_ID; page8.SortOrder = 2; page8.IsHidden = true; page8.Route = "test-route"; await api.Pages.SaveAsync(page8); } }