public void CanNotUpdateCopyWithAnotherTypeIdOtherThanOriginalPageTypeId() { using (var api = new Api(GetDb(), new ContentServiceFactory(services), storage, cache)) { var page = MissingPage.Create(api); page.Title = "New title"; page.OriginalPageId = PAGE_7_ID; var exn = Assert.Throws <InvalidOperationException>(() => { api.Pages.Save(page); }); Assert.Equal("Copy can not have a different content type", exn.Message); } }
/// <summary> /// Adds a page to this collection. /// </summary> /// <param name="dataStore">An <see cref="IDataStore"/> instance.</param> /// <param name="id"> /// The <see cref="IdItem.Id"/> of the wiki page which links to the referenced wiki page. /// </param> public async Task AddReferenceAsync(IDataStore dataStore, string id) { if (References.Contains(id)) { return; } var result = new MissingPage( Id, MissingPageIdItemTypeName, Title, WikiNamespace, References.ToImmutableList().Add(id)); await dataStore.StoreItemAsync(result).ConfigureAwait(false); }
public async Task CanNotUpdateCopyWithAnotherTypeIdOtherThanOriginalPageTypeId() { using (var api = CreateApi()) { var page = MissingPage.Create(api); page.Title = "New title"; page.OriginalPageId = PAGE_7_ID; var exn = await Assert.ThrowsAsync <InvalidOperationException>(async() => { await api.Pages.SaveAsync(page); }); Assert.Equal("Copy can not have a different content type", exn.Message); } }
public void MissingPageTest() { var value = new MissingPage( MissingPage.GetId("Test Title", "Test Namespace"), MissingPage.MissingPageIdItemTypeName, "Test Title", "Test Namespace", new List <string> { "Test_ID_2" }.AsReadOnly()); var json = JsonSerializer.Serialize(value); Console.WriteLine(); Console.WriteLine(json); var deserialized = JsonSerializer.Deserialize <MissingPage>(json); Assert.AreEqual(value, deserialized); Assert.AreEqual(json, JsonSerializer.Serialize(deserialized)); }
/// <summary> /// Get a new instance of <see cref="MissingPage"/>. /// </summary> /// <param name="dataStore">An <see cref="IDataStore"/> instance.</param> /// <param name="title"> /// The title of this missing page. Must be unique within its namespace, and non-empty. /// </param> /// <param name="wikiNamespace"> /// The namespace to which this page should belong. /// </param> /// <param name="referenceIds">The IDs of the initial pages which references this missing page.</param> public static async Task <MissingPage> NewAsync( IDataStore dataStore, string title, string wikiNamespace, params string[] referenceIds) { if (string.IsNullOrWhiteSpace(title)) { throw new ArgumentException($"{nameof(title)} cannot be empty.", nameof(title)); } var result = new MissingPage( GetId(title, wikiNamespace), MissingPageIdItemTypeName, title, wikiNamespace, referenceIds); await dataStore.StoreItemAsync(result).ConfigureAwait(false); return(result); }
/// <summary> /// Removes a page from this collection. /// </summary> /// <param name="dataStore">An <see cref="IDataStore"/> instance.</param> /// <param name="id"> /// The <see cref="IdItem.Id"/> of the wiki page which no longer links to the referenced /// wiki page. /// </param> public async Task RemoveReferenceAsync(IDataStore dataStore, string id) { if (!References.Contains(id)) { return; } if (References.Count == 1) { await dataStore.RemoveItemAsync <MissingPage>(Id).ConfigureAwait(false); } else { var result = new MissingPage( Id, MissingPageIdItemTypeName, Title, WikiNamespace, References.ToImmutableList().Remove(id)); await dataStore.StoreItemAsync(result).ConfigureAwait(false); } }