public void It_can_attach_one_object_to_another_event_if_it_was_created_as_part_of_previous_snapshot() { const string relationName = "RelationName"; var refererObjectId = ObjectId.NewUniqueId(); var refereeObjectId = ObjectId.NewUniqueId(); var objectTypeId = ObjectTypeId.NewUniqueId(); var changeSet = new UncommittedChangeSet(null, "Some comment") .Add(new CreateObjectCommand(objectTypeId, refererObjectId)) .Add(new CreateObjectCommand(objectTypeId, refereeObjectId)); var snapshot = new IncrementalCachingSnapshot(NullSnapshot.Instance, commandExecutor, changeSet); var nextChangeSet = new UncommittedChangeSet(changeSet.Id, "Some comment") .Add(new AttachObjectCommand(refererObjectId, refereeObjectId, relationName)); var nextSnapshot = new IncrementalCachingSnapshot(snapshot, commandExecutor, nextChangeSet); var currentObjectState = nextSnapshot.GetById(refererObjectId); Assert.IsTrue(currentObjectState.GetRelated(relationName).Any(x => x == refereeObjectId)); var previousObjectState = snapshot.GetById(refererObjectId); Assert.IsFalse(previousObjectState.GetRelated(relationName).Any(x => x == refereeObjectId)); }
public void If_data_store_thorws_exception_facade_state_is_reloaded() { var changeSetId = ChangeSetId.NewUniqueId(); var objectId = ObjectId.NewUniqueId(); var objectTypeId = ObjectTypeId.NewUniqueId(); var commands = new List <AbstractCommand> { new CreateObjectCommand(objectTypeId, objectId) }; dataStore.ChangeSets.Add(new ChangeSet(changeSetId, null, "Some comment", commands)); dataStore.OnStored += (sender, args) => { throw new Exception("Some nasty exception happened AFTER storing value"); }; var facade = new DataFacade(commandExecutor, dataStore, new IncrementalCachingSnapshotFactory()); var newChangeSet = new UncommittedChangeSet(changeSetId, "Some comment"); newChangeSet.Add(new ModifyAttributeCommand(objectId, "TextValue", "SomeText")); try { facade.Commit(newChangeSet); } catch (Exception) { //Intentionally swallowing exception } var o = facade.GetById(objectId, newChangeSet.Id); //Would throw if new change set was not loaded into memory. }
public void It_returns_null_for_not_registered_type_id() { var objectTypeId = ObjectTypeId.NewUniqueId(); var repository = new ObjectTypeDescriptorRepository(); var notRegistered = repository.GetByTypeId(objectTypeId); Assert.IsNull(notRegistered); }
public void It_return_all_unempty_contexts() { var composite = new CompositeCommandExecutionContext(); composite.GetFor(ObjectId.NewUniqueId()).Create(ObjectTypeId.NewUniqueId()); composite.GetFor(ObjectId.NewUniqueId()).Create(ObjectTypeId.NewUniqueId()); composite.GetFor(ObjectId.NewUniqueId()); Assert.AreEqual(2, composite.GetAll().Count()); }
public void It_throws_exception_when_trying_to_register_two_types_with_same_id() { var objectTypeId = ObjectTypeId.NewUniqueId(); var repository = new ObjectTypeDescriptorRepository(); var firstTypeDescriptor = new ObjectTypeDescriptor(typeof(object), objectTypeId, new AttributeDescriptor[] { }, new RelationDescriptor[] { }); var secondTypeDescriptor = new ObjectTypeDescriptor(typeof(int), objectTypeId, new AttributeDescriptor[] { }, new RelationDescriptor[] { }); repository.RegisterTypeDescriptor(firstTypeDescriptor); Assert.Throws <InvalidOperationException>(() => repository.RegisterTypeDescriptor(secondTypeDescriptor)); }
public void It_returns_object_type_by_its_id() { var objectTypeId = ObjectTypeId.NewUniqueId(); var repository = new ObjectTypeDescriptorRepository(); var typeDescriptor = new ObjectTypeDescriptor(typeof(object), objectTypeId, new AttributeDescriptor[] {}, new RelationDescriptor[] {}); repository.RegisterTypeDescriptor(typeDescriptor); var registered = repository.GetByTypeId(objectTypeId); Assert.IsNotNull(registered); }
public void It_can_create_object_and_get_by_id() { var objectId = ObjectId.NewUniqueId(); var objectTypeId = ObjectTypeId.NewUniqueId(); var changeSet = new UncommittedChangeSet(null, "Some comment") .Add(new CreateObjectCommand(objectTypeId, objectId)); var snapshot = new IncrementalCachingSnapshot(NullSnapshot.Instance, commandExecutor, changeSet); var o = snapshot.GetById(objectId); Assert.IsNotNull(o); }
public void It_can_get_object_by_id_even_if_it_was_creates_as_part_of_previous_snapshot() { var objectId = ObjectId.NewUniqueId(); var objectTypeId = ObjectTypeId.NewUniqueId(); var changeSet = new UncommittedChangeSet(null, "Some comment") .Add(new CreateObjectCommand(objectTypeId, objectId)); var snapshot = new IncrementalCachingSnapshot(NullSnapshot.Instance, commandExecutor, changeSet); var nextSnapshot = new IncrementalCachingSnapshot(snapshot, commandExecutor, new UncommittedChangeSet(changeSet.Id, "Some comment")); var o = nextSnapshot.GetById(objectId); Assert.IsNotNull(o); }
public void It_stores_and_returns_object_attributes() { const string attributeName = "Attribute"; var objectId = ObjectId.NewUniqueId(); var objectTypeId = ObjectTypeId.NewUniqueId(); var changeSet = new UncommittedChangeSet(null, "Some comment") .Add(new CreateObjectCommand(objectTypeId, objectId)) .Add(new ModifyAttributeCommand(objectId, attributeName, "SomeValue")); var snapshot = new IncrementalCachingSnapshot(NullSnapshot.Instance, commandExecutor, changeSet); var o = snapshot.GetById(objectId); Assert.AreEqual("SomeValue", o.GetAttributeValue(attributeName)); }
public void It_creates_object_and_returns_it_by_id() { var changeSetId = ChangeSetId.NewUniqueId(); var objectId = ObjectId.NewUniqueId(); var objectTypeId = ObjectTypeId.NewUniqueId(); var commands = new List <AbstractCommand> { new CreateObjectCommand(objectTypeId, objectId) }; dataStore.ChangeSets.Add(new ChangeSet(changeSetId, null, "Some comment", commands)); var facade = new DataFacade(commandExecutor, dataStore, new IncrementalCachingSnapshotFactory()); var o = facade.GetById(objectId, changeSetId); Assert.IsNotNull(o); }
public void It_can_attach_one_object_to_another() { const string relationName = "RelationName"; var refererObjectId = ObjectId.NewUniqueId(); var refereeObjectId = ObjectId.NewUniqueId(); var objectTypeId = ObjectTypeId.NewUniqueId(); var changeSet = new UncommittedChangeSet(null, "Some comment") .Add(new CreateObjectCommand(objectTypeId, refererObjectId)) .Add(new CreateObjectCommand(objectTypeId, refereeObjectId)) .Add(new AttachObjectCommand(refererObjectId, refereeObjectId, relationName)); var snapshot = new IncrementalCachingSnapshot(NullSnapshot.Instance, commandExecutor, changeSet); var o = snapshot.GetById(refererObjectId); var relatedToFirst = o.GetRelated(relationName); Assert.IsTrue(relatedToFirst.Any(x => x == refereeObjectId)); }
public void Property_values_set_on_later_change_sets_override_those_set_on_earlier_change_sets() { const string property = "Property"; var objectId = ObjectId.NewUniqueId(); var objectTypeId = ObjectTypeId.NewUniqueId(); var changeSet = new UncommittedChangeSet(null, "Some comment") .Add(new CreateObjectCommand(objectTypeId, objectId)) .Add(new ModifyAttributeCommand(objectId, property, "SomeValue")); var snapshot = new IncrementalCachingSnapshot(NullSnapshot.Instance, commandExecutor, changeSet); var nextChangeSet = new UncommittedChangeSet(changeSet.Id, "Some comment") .Add(new ModifyAttributeCommand(objectId, property, "OverridingValue")); var nextSnapshot = new IncrementalCachingSnapshot(snapshot, commandExecutor, nextChangeSet); var o = nextSnapshot.GetById(objectId); Assert.AreEqual("OverridingValue", o.GetAttributeValue(property)); }
public void After_executing_commands_all_objects_of_requested_type_are_present_in_the_composite_context() { var requestedType = ObjectTypeId.NewUniqueId(); var collection = new CommandsByObjectTypeCollection(); var commandExecutor = new CommandExecutor() .RegisterCommandHandler(new CreateObjectCommandHandler()) .RegisterCommandHandler(new ModifyAttributeCommandHandler()); collection.Add(new CreateObjectCommand(requestedType, ObjectId.NewUniqueId())); collection.Add(new CreateObjectCommand(requestedType, ObjectId.NewUniqueId())); collection.Add(new CreateObjectCommand(ObjectTypeId.NewUniqueId(), ObjectId.NewUniqueId())); collection.Add(new CreateObjectCommand(ObjectTypeId.NewUniqueId(), ObjectId.NewUniqueId())); var compositeContext = new CompositeCommandExecutionContext(); collection.ExecuteCommands(requestedType, commandExecutor, compositeContext); var objectStates = compositeContext.GetAll(); Assert.AreEqual(2, objectStates.Count(x => x.TypeId == requestedType)); }