public void SavingAction_On_Major_Pending_Approve2() { Test(() => { var gc = CreateNodeInMemory(ApprovingType.True, VersioningType.MajorOnly); InitializeAsExisting(gc, 2, 114, "V4.0.P"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 111), new NodeHead.NodeVersion(VersionNumber.Parse("V2.0.P"), 112), new NodeHead.NodeVersion(VersionNumber.Parse("V3.0.P"), 113), new NodeHead.NodeVersion(VersionNumber.Parse("V4.0.P"), 114) }); action.Approve(); SavingAssert(action, "V4.0.P", 114, "V2.0.A", 114, null, new List <int> { 112, 113 }); }); }
public void SavingAction_Off_None_Locked_CheckIn1() { Test(() => { var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.None); InitializeAsExisting(gc, 2, 113, "V1.2.L"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 111), new NodeHead.NodeVersion(VersionNumber.Parse("V1.1.D"), 112), new NodeHead.NodeVersion(VersionNumber.Parse("V1.2.L"), 113) }); action.CheckIn(); Assert.IsNotNull(action.ExpectedVersion); Assert.AreEqual("V1.0.A", action.ExpectedVersion.ToString()); Assert.AreEqual(111, action.ExpectedVersionId); Assert.AreEqual(2, action.DeletableVersionIds.Count); Assert.IsTrue(action.DeletableVersionIds.Contains(113)); Assert.IsTrue(action.DeletableVersionIds.Contains(112)); }); }
public void SavingAction_Off_Major_Locked_CheckIn_Repair1() { Test(() => { var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.MajorOnly); InitializeAsExisting(gc, 2, 116, "V3.2.L"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 111), new NodeHead.NodeVersion(VersionNumber.Parse("V1.2.D"), 112), new NodeHead.NodeVersion(VersionNumber.Parse("V2.0.R"), 113), new NodeHead.NodeVersion(VersionNumber.Parse("V3.0.P"), 114), new NodeHead.NodeVersion(VersionNumber.Parse("V3.1.P"), 115), new NodeHead.NodeVersion(VersionNumber.Parse("V3.2.L"), 116) }); action.CheckIn(); SavingAssert(action, "V3.2.L", 116, "V2.0.A", 116, 0, new List <int> { 112, 113, 114, 115 }); }); }
private static ListItem[] GetListItems(IEnumerable <ContentType> contentTypes, Node contextNode) { var dict = new SortedDictionary <string, string>(); if (contentTypes == null) { return(new ListItem[0]); } foreach (var contentType in contentTypes) { if (!SavingAction.CheckManageListPermission(contentType.NodeType, contextNode)) { continue; } var title = string.IsNullOrEmpty(contentType.DisplayName) ? contentType.Name : contentType.DisplayName; if (!dict.ContainsKey(title)) { dict.Add(title, contentType.Name); } } return(dict.Keys.Count == 0 ? new ListItem[0] : dict.Keys.Select(key => new ListItem(key, dict[key])).ToArray()); }
public void SavingAction_Default_Default_Create_SaveAndCheckIn() { var content = Content.CreateNew("Car", Repository.Root, "car"); var action = SavingAction.Create(content.ContentHandler); action.CheckOut(); }
public void SavingAction_On_None_Locked_CheckIn1() { // do not save the content in this test // do not change the parent to TestRoot //1.0A 1.0A //1.1D 1.1D //2.0A 2.0A //2.1D 2.2P <-- //2.2L <-- var gc = CreateNodeInMemory(ApprovingType.True, VersioningType.None); InitializeAsExisting(gc, 100, 115, "V2.2.L"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 111), new NodeHead.NodeVersion(VersionNumber.Parse("V1.1.D"), 112), new NodeHead.NodeVersion(VersionNumber.Parse("V2.0.A"), 113), new NodeHead.NodeVersion(VersionNumber.Parse("V2.1.D"), 114), new NodeHead.NodeVersion(VersionNumber.Parse("V2.2.L"), 115) }); action.CheckIn(); Assert.IsTrue(action.ExpectedVersion != null, "ExpectedVersion is null"); Assert.IsTrue(action.ExpectedVersion.ToString() == "V3.0.P", String.Concat("ExpectedVersion is ", action.ExpectedVersion.ToString(), ". Expected: V2.1.P")); Assert.IsTrue(action.ExpectedVersionId == 115, String.Concat("ExpectedVersionId is ", action.ExpectedVersionId, ". Expected:115")); Assert.IsTrue(action.DeletableVersionIds.Count == 1, String.Concat("DeletableVersionIds contains ", action.DeletableVersionIds.Count, "items. Expected: 1")); Assert.IsTrue(action.DeletableVersionIds.Contains(114), String.Concat("DeletableVersionIds does not contain 114")); }
private void EnterEditMode() { var wpm = this.WPManager; if (wpm == null) { return; } var mode = wpm.SupportedDisplayModes[DisplayModeEdit]; if (mode == null) { return; } wpm.DisplayMode = mode; if (SavingAction.HasCheckOut(Portal.Page.Current)) { Portal.Page.Current.CheckOut(); } ResetVersioningButtons(); }
public void SavingAction_On_None_Locked_CheckIn1() { Test(() => { //1.0A 1.0A //1.1D 1.1D //2.0A 2.0A //2.1D 2.2P <-- //2.2L <-- var gc = CreateNodeInMemory(ApprovingType.True, VersioningType.None); InitializeAsExisting(gc, 1, 115, "V2.2.L"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 111), new NodeHead.NodeVersion(VersionNumber.Parse("V1.1.D"), 112), new NodeHead.NodeVersion(VersionNumber.Parse("V2.0.A"), 113), new NodeHead.NodeVersion(VersionNumber.Parse("V2.1.D"), 114), new NodeHead.NodeVersion(VersionNumber.Parse("V2.2.L"), 115) }); action.CheckIn(); Assert.IsNotNull(action.ExpectedVersion); Assert.AreEqual("V3.0.P", action.ExpectedVersion.ToString()); Assert.AreEqual(115, action.ExpectedVersionId); Assert.AreEqual(1, action.DeletableVersionIds.Count); Assert.IsTrue(action.DeletableVersionIds.Contains(114)); }); }
public static void MultistepSave(Node node) { var savingAction = SavingAction.Create(node); savingAction.MultistepSaving = true; savingAction.ExpectedVersionId = node.VersionId; savingAction.Execute(); }
public void SavingAction_Default_Default_Create_SaveAndCheckIn() { Test(() => { var content = Content.CreateNew("SystemFolder", Repository.Root, "SystemFolder1"); var action = SavingAction.Create(content.ContentHandler); action.CheckOut(); }); }
public void SavingAction_Off_None_DifferentUsers_CheckOut1() { var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.None); InitializeAsExisting(gc, 100, 111, "V2.0.L", true, RepositoryConfiguration.VisitorUserId, DateTime.Today.AddDays(-1)); Assert.IsFalse(SavingAction.HasCheckOut(gc), "Node is locked by another user but has checkout!"); Assert.IsFalse(SavingAction.HasCheckIn(gc), "Node is locked by another user but has checkin!"); Assert.IsFalse(SavingAction.HasUndoCheckOut(gc), "Node is locked by another user but has undo checkout!"); }
//----------------------------------------------------------------------------------------------------------------------------------- operations /// <summary> /// Handles GET operations. Parameters come from the URL or the request stream. /// </summary> /// <param name="portalContext"></param> /// <param name="odataReq"></param> internal void WriteOperationResult(PortalContext portalContext, ODataRequest odataReq) { object response = null; var content = ODataHandler.LoadContentByVersionRequest(odataReq.RepositoryPath); if (content == null) { throw new ContentNotFoundException(string.Format(SNSR.GetString("$Action,ErrorContentNotFound"), odataReq.RepositoryPath)); } var action = ODataHandler.ActionResolver.GetAction(content, odataReq.Scenario, odataReq.PropertyName, null, null); if (action == null) { // check if this is a versioning action (e.g. a checkout) SavingAction.AssertVersioningAction(content, odataReq.PropertyName, true); throw new InvalidContentActionException(InvalidContentActionReason.UnknownAction, content.Path); } if (!action.IsODataOperation) { throw new ODataException("Not an OData operation.", ODataExceptionCode.IllegalInvoke); } if (action.CausesStateChange) { throw new ODataException("OData action cannot be invoked with HTTP GET.", ODataExceptionCode.IllegalInvoke); } if (action.Forbidden || (action.GetApplication() != null && !action.GetApplication().Security.HasPermission(PermissionType.RunApplication))) { throw new InvalidContentActionException("Forbidden action: " + odataReq.PropertyName); } var parameters = GetOperationParameters(action, portalContext.OwnerHttpContext.Request); response = action.Execute(content, parameters); var responseAsContent = response as Content; if (responseAsContent != null) { WriteSingleContent(responseAsContent, portalContext); return; } int count; response = ProcessOperationResponse(response, portalContext, odataReq, out count); //Write(response, portalContext); WriteOperationResult(response, portalContext, odataReq, count); }
// --------------------------------------------------------------------------------------------------------------- operations /// <summary> /// Handles GET operations. Parameters come from the URL or the request stream. /// </summary> internal async Task WriteGetOperationResultAsync(HttpContext httpContext, ODataRequest odataReq, IConfiguration appConfig) { var content = ODataMiddleware.LoadContentByVersionRequest(odataReq.RepositoryPath, httpContext); if (content == null) { throw new ContentNotFoundException(string.Format(SNSR.GetString("$Action,ErrorContentNotFound"), odataReq.RepositoryPath)); } var action = ODataMiddleware.ActionResolver.GetAction(content, odataReq.Scenario, odataReq.PropertyName, null, null, httpContext, appConfig); if (action == null) { // check if this is a versioning action (e.g. a checkout) SavingAction.AssertVersioningAction(content, odataReq.PropertyName, true); SnTrace.System.WriteError($"OData: {odataReq.PropertyName} operation not found " + $"for content {content.Path} and user {User.Current.Username}."); throw new InvalidContentActionException(InvalidContentActionReason.UnknownAction, content.Path, null, odataReq.PropertyName); } if (!action.IsODataOperation) { throw new ODataException("Not an OData operation.", ODataExceptionCode.IllegalInvoke); } if (action.CausesStateChange) { throw new ODataException("OData action cannot be invoked with HTTP GET.", ODataExceptionCode.IllegalInvoke); } if (action.Forbidden || (action.GetApplication() != null && !action.GetApplication().Security.HasPermission(PermissionType.RunApplication))) { throw new InvalidContentActionException("Forbidden action: " + odataReq.PropertyName); } var response = action is ODataOperationMethodExecutor odataAction ? (odataAction.IsAsync ? await odataAction.ExecuteAsync(content) : action.Execute(content)) : action.Execute(content, GetOperationParameters(action, httpContext.Request)); if (response is Content responseAsContent) { await WriteSingleContentAsync(responseAsContent, httpContext) .ConfigureAwait(false); return; } response = ProcessOperationResponse(response, odataReq, httpContext, out var count); await WriteOperationResultAsync(response, httpContext, odataReq, count) .ConfigureAwait(false); }
public void SavingAction_Off_None_DifferentUsers_CheckOut1() { Test(true, () => { var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.None); InitializeAsExisting(gc, 1, 111, "V2.0.L", true, Identifiers.VisitorUserId, DateTime.Today.AddDays(-1)); Assert.IsFalse(SavingAction.HasCheckOut(gc)); Assert.IsFalse(SavingAction.HasCheckIn(gc)); Assert.IsFalse(SavingAction.HasUndoCheckOut(gc)); }); }
private static void SetVersionHistory(SavingAction action, Node node, IEnumerable <NodeHead.NodeVersion> versionHistory) { var lastMajorVer = versionHistory.Where(v => v.VersionNumber.Minor == 0 && v.VersionNumber.Status == VersionStatus.Approved).LastOrDefault(); var lastMinorVer = versionHistory.LastOrDefault(); var head = NodeHead.CreateFromNode(node, lastMinorVer.VersionId, lastMajorVer == null ? 0 : lastMajorVer.VersionId); var fieldInfo = head.GetType().GetField("_versions", BindingFlags.NonPublic | BindingFlags.Instance); fieldInfo.SetValue(head, versionHistory); var methodInfo = action.GetType().GetMethod("SetNodeHead", BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(NodeHead) }, null); methodInfo.Invoke(action, new object[] { head }); }
public void SavingAction_Off_MajorMinor_StartMultistepSave_03() { Test(() => { var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.MajorAndMinor); InitializeAsExisting(gc, 1, 111, "V1.1.L", true, 100, DateTime.Today); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 110), new NodeHead.NodeVersion(VersionNumber.Parse("V1.1.L"), 111) }); action.StartMultistepSave(); }); }
private static void CreatingTest(bool hasApproving, VersioningType mode, string expectedVersion) { var gc = CreateNodeInMemory(hasApproving ? ApprovingType.True : ApprovingType.False, mode); var action = SavingAction.Create(gc); action.CheckOutAndSave(); Assert.IsTrue(action.CurrentVersion == null, "action.CurrentVersion is not null"); Assert.IsTrue(action.CurrentVersionId == 0, $"action.CurrentVersionId is {action.CurrentVersionId}. Expected: 0"); Assert.IsTrue(action.ExpectedVersion != null, "action.ExpectedVersion is null"); Assert.IsTrue(action.ExpectedVersion.ToString() == expectedVersion, $"action.CurrentVersion is {action.ExpectedVersion}. Expected: {expectedVersion}."); Assert.IsTrue(action.ExpectedVersionId == 0, $"action.ExpectedVersionId is ", action.ExpectedVersionId, ". Expected: 0"); Assert.IsTrue(action.LockerUserId == null, "action.LockerUserId not null"); Assert.IsTrue(action.DeletableVersionIds.Count == 0, $"action..DeletableVersions.Count is {action.DeletableVersionIds.Count}. Expected: 0"); }
public void SavingAction_On_None_Pending_Reject1() { var gc = CreateNodeInMemory(ApprovingType.True, VersioningType.None); InitializeAsExisting(gc, 123, 111, "V1.0.P"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.P"), 111) }); action.Reject(); SavingAssert(action, "V1.0.P", 111, "V1.0.R", 111, null, new List <int>()); }
private static ListItem[] GetOtherListItems(IEnumerable <Node> nodes, Node contextNode) { if (nodes == null) { return(new ListItem[0]); } var dict = new SortedDictionary <string, string>(); foreach (var node in nodes) { var displayName = string.Empty; var name = string.Empty; var c = node as GenericContent; var ctd = node as ContentType; if (ctd != null) // content type { if (!SavingAction.CheckManageListPermission(ctd.NodeType, contextNode)) { continue; } var content = Content.Create(ctd); displayName = content.DisplayName; name = content.Name; } else if (c != null) // content template { if (!SavingAction.CheckManageListPermission(c.NodeType, contextNode)) { continue; } var content = Content.Create(c); displayName = content.DisplayName; name = content.Path; } var validTitle = string.IsNullOrEmpty(displayName) ? name : displayName; if (!dict.ContainsKey(validTitle)) { dict.Add(validTitle, name); } } return(dict.Keys.Count == 0 ? new ListItem[0] : dict.Keys.Select(key => new ListItem(key, dict[key])).ToArray()); }
public void SavingAction_Off_None_Approved_Save() { // do not save the content in this test // do not change the parent to TestRoot var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.None); InitializeAsExisting(gc, 123, 456, "V1.0.A"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 456) }); action.CheckOutAndSave(); SavingAssert(action, "V1.0.A", 456, "V2.0.L", 0, 1, new List <int>()); }
public void SavingAction_Off_Full_Draft_Publish1() { var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.MajorAndMinor); InitializeAsExisting(gc, 123, 112, "V1.1.D"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 111), new NodeHead.NodeVersion(VersionNumber.Parse("V1.1.D"), 112) }); action.Publish(); SavingAssert(action, "V1.1.D", 112, "V2.0.A", 112, 0, new List <int>()); }
public void SavingAction_Off_None_Approved_Save() { Test(true, () => { var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.None); InitializeAsExisting(gc, 2, 456, "V1.0.A"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 456) }); action.CheckOutAndSave(); SavingAssert(action, "V1.0.A", 456, "V2.0.L", 0, 1, new List <int>()); }); }
public void SavingAction_Off_MajorMinor_StartMultistepSave_02() { Test(true, () => { var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.MajorAndMinor); InitializeAsExisting(gc, 1, 111, "V2.0.A"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 110), new NodeHead.NodeVersion(VersionNumber.Parse("V2.0.A"), 111) }); action.StartMultistepSave(); SavingAssert(action, "V2.0.A", 111, "V2.1.L", 0, 1, new List <int>()); }); }
public void SavingAction_On_Full_Pending_Approve2() { var gc = CreateNodeInMemory(ApprovingType.True, VersioningType.MajorAndMinor); InitializeAsExisting(gc, 123, 113, "V0.3.P"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V0.1.P"), 111), new NodeHead.NodeVersion(VersionNumber.Parse("V0.2.D"), 112), new NodeHead.NodeVersion(VersionNumber.Parse("V0.3.P"), 113) }); action.Approve(); SavingAssert(action, "V0.3.P", 113, "V1.0.A", 113, null, new List <int>()); }
//======================================================================= Event handlers protected override void OnButtonClick(object sender, EventArgs e) { var button = sender as IButtonControl; if (button == null) { return; } switch (button.CommandName) { case "Reject": var reason = this.CommentsTextBox == null ? string.Empty : this.CommentsTextBox.Text; if (OnReject == null) { //retrieve the current content var gc = ContextBoundPortlet.GetContextNodeForControl(this) as GenericContent; if (gc == null) { return; } if (SavingAction.HasReject(gc)) { gc["RejectReason"] = reason; gc.Reject(); var p = Page as PageBase; if (p != null) { p.Done(false); } } } else { OnReject(sender, new VersioningActionEventArgs(VersioningAction.Reject, reason)); } break; } }
private static bool IsInvalidVersioningAction(Content context, string actionName) { if (string.IsNullOrEmpty(actionName) || context == null) { return(false); } actionName = actionName.ToLower(); var generic = context.ContentHandler as GenericContent; if (generic == null) { return(false); } switch (actionName) { case "checkin": return(!SavingAction.HasCheckIn(generic)); case "checkout": return((generic.VersioningMode <= VersioningType.None && !(generic is IFile || generic.NodeType.IsInstaceOfOrDerivedFrom("Page"))) || !SavingAction.HasCheckOut(generic)); case "undocheckout": return(!SavingAction.HasUndoCheckOut(generic)); case "forceundocheckout": return(!SavingAction.HasForceUndoCheckOutRight(generic)); case "publish": return(generic.VersioningMode <= VersioningType.None || !SavingAction.HasPublish(generic)); case "approve": case "reject": return(!generic.Approvable); default: return(false); } }
public void SavingAction_On_Full_Locked_Publish1() { Test(() => { var gc = CreateNodeInMemory(ApprovingType.True, VersioningType.MajorAndMinor); InitializeAsExisting(gc, 2, 113, "V1.2.L"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 111), new NodeHead.NodeVersion(VersionNumber.Parse("V1.1.D"), 112), new NodeHead.NodeVersion(VersionNumber.Parse("V1.2.L"), 113) }); action.Publish(); SavingAssert(action, "V1.2.L", 113, "V1.2.P", 113, 0, new List <int>()); }); }
public void SavingAction_On_Full_Draft_Publish2() { var gc = CreateNodeInMemory(ApprovingType.True, VersioningType.MajorAndMinor); InitializeAsExisting(gc, 123, 115, "V1.2.R"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V0.1.P"), 111), new NodeHead.NodeVersion(VersionNumber.Parse("V0.2.D"), 112), new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 113), new NodeHead.NodeVersion(VersionNumber.Parse("V1.1.D"), 114), new NodeHead.NodeVersion(VersionNumber.Parse("V1.2.R"), 115) }); action.Publish(); SavingAssert(action, "V1.2.R", 115, "V1.3.P", 0, 0, new List <int>()); }
/// <summary> /// Handles POST operations. Parameters come from request stream. /// </summary> internal async Task WritePostOperationResultAsync(HttpContext httpContext, ODataRequest odataReq, IConfiguration appConfig) { var content = ODataMiddleware.LoadContentByVersionRequest(odataReq.RepositoryPath, httpContext); if (content == null) { throw new ContentNotFoundException(string.Format(SNSR.GetString("$Action,ErrorContentNotFound"), odataReq.RepositoryPath)); } var action = ODataMiddleware.ActionResolver.GetAction(content, odataReq.Scenario, odataReq.PropertyName, null, null, httpContext, appConfig); if (action == null) { // check if this is a versioning action (e.g. a checkout) SavingAction.AssertVersioningAction(content, odataReq.PropertyName, true); throw new InvalidContentActionException(InvalidContentActionReason.UnknownAction, content.Path, null, odataReq.PropertyName); } if (action.Forbidden || (action.GetApplication() != null && !action.GetApplication().Security.HasPermission(PermissionType.RunApplication))) { throw new InvalidContentActionException("Forbidden action: " + odataReq.PropertyName); } var response = action is ODataOperationMethodExecutor odataAction ? (odataAction.IsAsync ? await odataAction.ExecuteAsync(content) : action.Execute(content)) : action.Execute(content, await GetOperationParametersAsync(action, httpContext, odataReq)); if (response is Content responseAsContent) { await WriteSingleContentAsync(responseAsContent, httpContext) .ConfigureAwait(false); return; } response = ProcessOperationResponse(response, odataReq, httpContext, out var count); await WriteOperationResultAsync(response, httpContext, odataReq, count) .ConfigureAwait(false); }
public void SavingAction_Off_Major_SaveAndCheckIn_Repair1() { var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.MajorOnly); InitializeAsExisting(gc, 123, 114, "V3.0.P"); var action = SavingAction.Create(gc); SetVersionHistory(action, gc, new[] { new NodeHead.NodeVersion(VersionNumber.Parse("V1.0.A"), 111), new NodeHead.NodeVersion(VersionNumber.Parse("V1.2.D"), 112), new NodeHead.NodeVersion(VersionNumber.Parse("V2.0.R"), 113), new NodeHead.NodeVersion(VersionNumber.Parse("V3.0.P"), 114) }); action.CheckOutAndSaveAndCheckIn(); SavingAssert(action, "V3.0.P", 114, "V2.0.A", 114, 0, new List <int> { 112, 113 }); }
private static void SetVersionHistory(SavingAction action, Node node, IEnumerable<NodeHead.NodeVersion> versionHistory) { var lastMajorVer = versionHistory.Where(v => v.VersionNumber.Minor == 0 && v.VersionNumber.Status == VersionStatus.Approved).LastOrDefault(); var lastMinorVer = versionHistory.LastOrDefault(); var head = NodeHead.CreateFromNode(node, lastMinorVer.VersionId, lastMajorVer == null ? 0 : lastMajorVer.VersionId); var fieldInfo = head.GetType().GetField("_versions", BindingFlags.NonPublic | BindingFlags.Instance); fieldInfo.SetValue(head, versionHistory); var methodInfo = action.GetType().GetMethod("SetNodeHead", BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(NodeHead) }, null); methodInfo.Invoke(action, new object[] { head }); }