public void Fails_to_append_absolute() { var ctid1 = HarshContentTypeId.Parse("0x01"); var ctid2 = HarshContentTypeId.Parse("0x01"); Assert.Throws <ArgumentException>(() => ctid1.Append(ctid2)); }
public void Parses_absolute_ids(String input, String expectedToString) { var result = HarshContentTypeId.Parse(input); Assert.True(result.IsAbsolute); Assert.Equal(expectedToString, result.ToString()); }
public void Appends_two_ids(String expected, String a, String b) { var ctidA = HarshContentTypeId.Parse(a); var ctidB = HarshContentTypeId.Parse(b); Assert.Equal(expected, ctidA.Append(ctidB).ToString()); }
public async Task Default_group_is_used() { var prov = new HarshContentType() { Id = HarshContentTypeId.Parse("0x010044fbfdb9defa4244831062437d181c6f"), Name = "44fbfdb9defa4244831062437d181c6f", }; ContentType ct = null; try { var ctx = Context.PushState(new DefaultContentTypeGroup() { Value = Group }); await prov.ProvisionAsync(ctx); var cto = LastObjectOutput <ContentType>(); Assert.True(cto.ObjectAdded); ct = cto.Object; Assert.NotNull(ct); Assert.Equal(Group, ct.Group); } finally { ct?.DeleteObject(); await ClientContext.ExecuteQueryAsync(); } }
public void IsChildOf(Boolean expected, String ctidStr, String parentStr) { var ctid = HarshContentTypeId.Parse(ctidStr); var parent = HarshContentTypeId.Parse(parentStr); Assert.Equal(expected, ctid.IsChildOf(parent)); }
public void IsChildOf_fails(Type exceptionType, String ctidStr, String parentStr) { var ctid = HarshContentTypeId.Parse(ctidStr); var parent = HarshContentTypeId.Parse(parentStr); Assert.Throws(exceptionType, () => ctid.IsChildOf(parent)); }
public async Task Valid_id_gets_resolved(String id) { var resolver = Resolve.ContentType().ById(HarshContentTypeId.Parse(id)); var ct = Assert.Single(await ResolveAsync(resolver)); Assert.False(ct.IsNull()); Assert.Equal(id, await ct.EnsurePropertyAvailable(c => c.StringId)); }
public override String ToString() { if (_result == null) { _result = Build(_entityTypeInfo); } return(_result.ToString()); }
public override String ToString() { if (_result == null) { _result = Build(_entityTypeInfo); } return _result.ToString(); }
private HarshContentTypeId Build(TypeInfo t) { if (t.AsType() == typeof(HarshEntity)) { // don't recurse up to Object. we should never get // here anyway, since entities are supposed to inherit from // something with an absolute ID specified, // not directly from the HarshEntity class. return(null); } var cta = t.GetCustomAttribute <ContentTypeAttribute>(inherit: false); if (cta == null) { if (t == _entityTypeInfo) { throw Logger.Fatal.InvalidOperationFormat( SR.ContentTypeIdBuilder_NoContentTypeAttribute, t.FullName ); } else { throw Logger.Fatal.InvalidOperationFormat( SR.ContentTypeIdBuilder_NoContentTypeAttributeBaseClass, t.FullName, _entityTypeInfo.FullName ); } } var ctid = HarshContentTypeId.Parse(cta.ContentTypeId); if (ctid.IsAbsolute) { // an absolute ID. do not recurse further up the // class hierarchy, take it as it is return(ctid); } else { // not an absolute ID, append the parent type ID first var result = Build(t.BaseType.GetTypeInfo()); if (result == null) { throw Logger.Fatal.InvalidOperationFormat( SR.ContentTypeIdBuilder_NoAbsoluteIDInHierarchy, _entityTypeInfo.FullName ); } return(result.Append(ctid)); } }
public async Task Content_type_gets_added() { var name = Guid.NewGuid().ToString("n"); var ctid = HarshContentTypeId.Parse("0x01").Append(HarshContentTypeId.Parse(name)); var ctProv = new HarshContentType() { Id = ctid, Name = name, }; var listProv = new HarshList() { Title = name, Url = "Lists/" + name, Children = { new HarshContentTypeRef() { ContentTypes = Resolve.ContentType().ById(ctid) } } }; await ctProv.ProvisionAsync(Context); var ctResult = LastObjectOutput <ContentType>(); var ct = ctResult.Object; RegisterForDeletion(ct); await listProv.ProvisionAsync(Context); var listResult = LastObjectOutput <List>(); var list = listResult.Object; RegisterForDeletion(list); Assert.IsType <ObjectAdded <List> >(listResult); Assert.NotNull(list); ClientContext.Load( list, l => l.ContentTypesEnabled, l => l.ContentTypes.Include(lct => lct.StringId), l => l.Id ); await ClientContext.ExecuteQueryAsync(); Assert.True(list.ContentTypesEnabled); Assert.Contains(list.ContentTypes, lct => lct.StringId.StartsWith(ctid.ToString() + "00")); }
public async Task Existing_content_type_is_not_provisioned() { var prov = new HarshContentType() { Name = "Item", Id = HarshContentTypeId.Parse("0x01"), }; await prov.ProvisionAsync(Context); var output = LastObjectOutput <ContentType>(); Assert.False(output.ObjectAdded); }
public async Task Content_type_gets_removed() { var guid = Guid.NewGuid().ToString("n"); var ctid = $"0x0100{guid}"; var ct = Web.ContentTypes.Add(new ContentTypeCreationInformation() { Id = ctid, Name = guid, Group = "HarshPoint" }); await ClientContext.ExecuteQueryAsync(); RegisterForDeletion(ct); var list = await CreateList(); var listCt = list.ContentTypes.AddExistingContentType(ct); ClientContext.Load(listCt, c => c.StringId); await ClientContext.ExecuteQueryAsync(); var prov = new HarshContentTypeRef() { ContentTypes = Resolve.ContentType().ById(HarshContentTypeId.Parse(ctid)), Lists = Resolve.List().ById(list.Id), }; await prov.UnprovisionAsync( Context.AllowDeleteUserData() ); var actualListCts = ClientContext.LoadQuery( list.ContentTypes.Include(c => c.StringId) ); await ClientContext.ExecuteQueryAsync(); Assert.DoesNotContain( listCt.StringId, actualListCts.Select(c => c.StringId), StringComparer.InvariantCultureIgnoreCase ); }
public ContentTypeTests(ITestOutputHelper output) : base(output) { _guid = Guid.NewGuid().ToString("n"); _id = HarshContentTypeId.Parse("0x01").Append(HarshContentTypeId.Parse(_guid)); }
private static Boolean ContainsContentType(IEnumerable <HarshContentTypeId> ids, ContentType ct) { var ctid = HarshContentTypeId.Get(ct); return(ids.Any(id => ctid.IsDirectChildOf(id))); }
public ContentTypeTests(ITestOutputHelper output) : base(output) { _guid = Guid.NewGuid().ToString("n"); _id = HarshContentTypeId.Parse("0x01").Append(HarshContentTypeId.Parse(_guid)); }
public void Fails_to_append_null() { Assert.Throws <ArgumentNullException>(() => HarshContentTypeId.Parse("0x").Append(null)); }
public void Throws_for_invalid_ids(String invalidId, Type exceptionType) { Assert.Throws(exceptionType, () => HarshContentTypeId.Parse(invalidId)); }