public void PublishingShouldFailIfOwnerIsEmpty() { var contentManager = _container.Resolve <IContentManager>(); var item = contentManager.Create <ICommonPart>("test-item", VersionOptions.Draft, init => { }); var user = contentManager.New <IUser>("User"); _authn.Setup(x => x.GetAuthenticatedUser()).Returns(user); _authz.Setup(x => x.TryCheckAccess(StandardPermissions.SiteOwner, user, item)).Returns(true); item.Owner = user; var updater = new UpdatModelStub() { Owner = "" }; _container.Resolve <DefaultShapeTableManagerTests.TestShapeProvider>().Discover = b => b.Describe("Parts_Common_Owner_Edit").From(TestFeature()) .Placement(ShapePlacementParsingStrategy.BuildPredicate(c => true, new KeyValuePair <string, string>("Path", "~/yadda")), new PlacementInfo { Location = "Match" }); contentManager.UpdateEditor(item.ContentItem, updater); Assert.That(updater.ModelErrors.ContainsKey("OwnerEditor.Owner"), Is.True); }
public void PathConstraintShouldMatch() { // all path have a trailing / as per the current implementation // todo: (sebros) find a way to 'use' the current implementation in DefaultContentDisplay.BindPlacement instead of emulating it var rules = new[] { Tuple.Create("~/my-blog", "~/my-blog/", true), Tuple.Create("~/my-blog/", "~/my-blog/", true), // star match Tuple.Create("~/my-blog*", "~/my-blog/", true), Tuple.Create("~/my-blog*", "~/my-blog/my-post/", true), Tuple.Create("~/my-blog/*", "~/my-blog/", true), Tuple.Create("~/my-blog/*", "~/my-blog123/", false), Tuple.Create("~/my-blog*", "~/my-blog123/", true) }; foreach (var rule in rules) { var path = rule.Item1; var context = rule.Item2; var match = rule.Item3; _container.Resolve <TestShapeProvider>().Discover = builder => builder.Describe("Hello").From(TestFeature()) .Placement(ShapePlacementParsingStrategy.BuildPredicate(c => true, new KeyValuePair <string, string>("Path", path), new[] { new PathPlacementParseMatchProvider() }), new PlacementInfo { Location = "Match" }); var manager = _container.Resolve <IShapeTableManager>(); var hello = manager.GetShapeTable(null).Descriptors["Hello"]; var result = hello.Placement(new ShapePlacementContext { Path = context }); if (match) { Assert.That(result.Location, Is.EqualTo("Match"), String.Format("{0}|{1}", path, context)); } else { Assert.That(result.Location, Is.Null, String.Format("{0}|{1}", path, context)); } } }
private Func <ShapePlacementContext, bool> BuildPredicate(Func <ShapePlacementContext, bool> predicate, KeyValuePair <string, JToken> term) { return(ShapePlacementParsingStrategy.BuildPredicate(predicate, term, _placementNodeFilterProviders)); }
private static bool CheckFilter(ShapePlacementContext ctx, PlacementNode filter) => ShapePlacementParsingStrategy.CheckFilter(ctx, filter);