/// <summary>Tries to retrieve subjects from the backing RDF source for a dynamically resolved property.</summary> public override bool TryGetMember(GetMemberBinder binder, out object result) { _entity.EnsureIsInitialized(); var propertySpec = new DynamicPropertyAggregate(binder.Name); if (!propertySpec.IsValid) { result = null; return(false); } var property = Ontology.Properties.SingleOrDefault(p => p.Name == propertySpec.Name); if (property == null) { property = new Property(propertySpec.Name).InOntology(Ontology); } result = GetObjects(_entity.Id, property, propertySpec); if (propertySpec.IsList) { var graphOverride = new UnionGraphSelector(); var head = (IRdfListNode <object>) typeof(EntityExtensions).GetTypeInfo() .GetMethod("AsEntity") .MakeGenericMethod(typeof(IRdfListNode <object>)) .Invoke(null, new[] { result }); ((IEntityProxy)head.UnwrapProxy()).OverrideGraphSelection(graphOverride); var rdfListAdapter = new RdfListAdapter <IRdfListOwner, IRdfListNode <object>, object>(_entity.Context, _entity, head, graphOverride); result = new ReadOnlyCollection <dynamic>(rdfListAdapter); } return(true); }
public void Empty_list_should_have_count_zero() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override); // then list.Count.Should().Be(0); }
public void Should_calculate_count_for_new_list() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 5, 6, 7, 8 }; // then list.Count.Should().Be(5); }
public void Should_throw_when_inserting_to_invalid_index([Values(-1, 5, 100)] int index) { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 8, 41, 666 }; // then list.Invoking(l => l.Insert(index, 10)) .ShouldThrow <ArgumentOutOfRangeException>(); }
public void Should_throw_when_getting_elements_by_invalid_index([Values(-1, 4, 666)] int index) { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 8, 41, 666 }; // then list.Invoking(l => { var i = l[index]; }) .ShouldThrow <ArgumentOutOfRangeException>(); }
public void Should_initialize_with_type_initializer_in_correct_order() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 8, 41, 666 }; // then list.Should().ContainInOrder(4, 8, 41, 666); _contextMock.Verify(c => c.Create <IRdfListNode <int> >(It.IsAny <BlankId>()), Times.Exactly(4)); }
public void Should_allow_adding_elements() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override); // when list.Add(4); list.Add(8); // then list.Count.Should().Be(2); _contextMock.Verify(c => c.Create <IRdfListNode <int> >(It.IsAny <BlankId>()), Times.Exactly(2)); }
public void Should_allow_getting_elements_by_index() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 8 }; // then list[0].Should().Be(4); list[1].Should().Be(8); _contextMock.Verify(c => c.Create <IRdfListNode <int> >(It.IsAny <BlankId>()), Times.Exactly(2)); }
public void Should_allow_checking_item_existence(int item, bool expectedResult) { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 8, 8, 41, 666 }; // when var contains = list.Contains(item); // then contains.Should().Be(expectedResult); }
public void Should_allow_removing_last_element() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 666 }; // when list.Remove(666); // then list.Should().BeEmpty(); }
public void Should_update_count_when_cleared() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 5, 6, 7, 8 }; // then list.Clear(); // then list.Count.Should().Be(0); }
public void Should_update_count_when_adding_elements() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 5, 6, 7, 8 }; // then list.Add(10); // then list.Count.Should().Be(6); }
public void Should_allow_removing_elements_by_index(int index, int[] expectedResultCollection) { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 8, 8, 41, 666 }; // when list.RemoveAt(index); // then list.Should().ContainInOrder(expectedResultCollection); _contextMock.Verify(c => c.Delete(It.IsAny <BlankId>()), Times.Exactly(1)); }
public void Should_allow_clearing_entire_list() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 8, 8, 41, 666 }; // when list.Clear(); // then list.Should().BeEmpty(); _contextMock.Verify(c => c.Delete(It.IsAny <BlankId>()), Times.Exactly(5)); }
public void Removing_last_element_and_adding_new_to_end_should_keep_list_linked() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 8, 8, 41, 666 }; // when list.Remove(666); list.Add(1337); // then list.Should().ContainInOrder(4, 8, 8, 41, 1337); }
public void Should_allow_inserting_elements_at_index_with_indexer(int index, int[] expectedCollection) { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 8, 41, 666 }; // when list[index] = 5; // then list.Count.Should().Be(5); list.Should().ContainInOrder(expectedCollection); _contextMock.Verify(c => c.Create <IRdfListNode <int> >(It.IsAny <BlankId>()), Times.Exactly(5)); }
public void Should_allow_removing_last_elements_and_add_new_afterwards() { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 666 }; // when list.Remove(666); list.Add(1337); list.Add(999); // then list.Should().ContainInOrder(1337, 999); }
public void Should_allow_removing_elements(int elementToRemove, int[] expectedResultCollection, bool expectedReturnValue) { // given var list = new RdfListAdapter <IRdfListOwner, IRdfListNode <int>, int>(_context, _entity.Object, _override) { 4, 8, 8, 41, 666 }; // when var removeResult = list.Remove(elementToRemove); // then list.Should().ContainInOrder(expectedResultCollection); removeResult.Should().Be(expectedReturnValue); if (expectedReturnValue) { _contextMock.Verify(c => c.Delete(It.IsAny <BlankId>()), Times.Once); } else { _contextMock.Verify(c => c.Delete(It.IsAny <BlankId>()), Times.Never); } }