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_throws_exception_when_trying_to_load_object_in_context_of_non_existing_change_set() { var objectId = ObjectId.NewUniqueId(); var changeSetId = ChangeSetId.NewUniqueId(); var facade = new DataFacade(commandExecutor, dataStore, new IncrementalCachingSnapshotFactory()); Assert.Throws <InvalidOperationException>(() => facade.GetById(objectId, changeSetId)); }
public void It_appends_substring_of_comment_and_ellipsis_as_title_if_it_is_longer_than_30_characters() { var changeSet = new ChangeSet(ChangeSetId.NewUniqueId(), null, "Comment longer than 30 characters", new AbstractCommand[] { }); var model = CreateModel(changeSet); Assert.AreEqual("Comment longer than 30 char...", model.RootNodes[0].Title); }
public void It_appends_comment_as_title_if_it_is_shorter_or_equal_to_30_characters() { var changeSet = new ChangeSet(ChangeSetId.NewUniqueId(), null, "Comment with exactly 30 chars", new AbstractCommand[] { }); var model = CreateModel(changeSet); Assert.AreEqual("Comment with exactly 30 chars", model.RootNodes[0].Title); }
public void It_adds_point_to_the_timeline() { var timeline = new Timeline("Timeline", new TestingReferenceValueType(), new Point[] { }); timeline.AddPoint(new Point(ChangeSetId.NewUniqueId(), timeline.ReferenceType.GetCurrentValue())); Assert.AreEqual(1, timeline.Points.Count()); }
public void If_throws_when_trying_to_add_point_with_incompatible_type() { var timeline = new Timeline("Timeline", new TestingReferenceValueType(), new Point[] { }); TestDelegate act = () => timeline.AddPoint(new Point(ChangeSetId.NewUniqueId(), 100m)); Assert.Throws <InvalidOperationException>(act); }
public void SetUp() { objectId = ObjectId.NewUniqueId(); objectTypeId = new ObjectTypeId(new Guid(objectTypeIdValue)); changeSetId = ChangeSetId.NewUniqueId(); typeRepository = new ObjectTypeDescriptorRepository().RegisterUsingReflection <TestingObject>(); dataFacadeMock = new Mock <IDataFacade>(); objectFacade = new ObjectFacade(dataFacadeMock.Object, typeRepository, new Mock <ICommandExecutor>().Object); }
public void It_throws_exception_when_trying_to_load_two_change_sets_with_same_ids() { var changeSetId = ChangeSetId.NewUniqueId(); dataStore.ChangeSets.Add(new ChangeSet(changeSetId, null, "Some comment", new AbstractCommand[] {})); dataStore.ChangeSets.Add(new ChangeSet(changeSetId, null, "Some comment", new AbstractCommand[] {})); var facade = new DataFacade(commandExecutor, dataStore, new IncrementalCachingSnapshotFactory()); Assert.Throws <InvalidOperationException>(() => facade.GetById(ObjectId.NewUniqueId(), changeSetId)); }
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 Last_valid_change_set_is_the_one_with_the_greatest_reference_value_smaller_or_equal_the_actual_value() { var firstChangeSet = ChangeSetId.NewUniqueId(); var secondChangeSet = ChangeSetId.NewUniqueId(); var thirdChangeSet = ChangeSetId.NewUniqueId(); var timeline = new Timeline("Timeline", new TestingReferenceValueType(), new[] { new Point(firstChangeSet, 10), new Point(secondChangeSet, 20), new Point(thirdChangeSet, 30) }); Assert.AreEqual(secondChangeSet, timeline.GetLastValidChangeSet(25)); Assert.AreEqual(secondChangeSet, timeline.GetLastValidChangeSet(20)); Assert.AreEqual(firstChangeSet, timeline.GetLastValidChangeSet(19)); }
public void It_removes_point_from_the_timeline() { var firstChangeSet = ChangeSetId.NewUniqueId(); var secondChangeSet = ChangeSetId.NewUniqueId(); var thirdChangeSet = ChangeSetId.NewUniqueId(); var timeline = new Timeline("Timeline", new TestingReferenceValueType(), new[] { new Point(firstChangeSet, 10), new Point(secondChangeSet, 20), new Point(thirdChangeSet, 30) }); timeline.RemovePointFor(secondChangeSet); Assert.AreEqual(2, timeline.Points.Count()); Assert.IsTrue(timeline.Points.Any(x => x.ChangeSetId == firstChangeSet)); Assert.IsTrue(timeline.Points.Any(x => x.ChangeSetId == thirdChangeSet)); }
public void It_can_handle_1000_objects_with_10_changes_each() { var dataStore = new InMemoryDataStore(); var objectIds = GenerateObjectIds(1000); ChangeSetId?previousChangeSetId = null; ChangeSetId currentChangeSetId = ChangeSetId.NewUniqueId(); dataStore.ChangeSets.Add(new ChangeSet(currentChangeSetId, previousChangeSetId, "Some comment", GenerateCreateCommands(objectIds))); previousChangeSetId = currentChangeSetId; for (int i = 0; i < 9; i++) { currentChangeSetId = ChangeSetId.NewUniqueId(); dataStore.ChangeSets.Add(new ChangeSet(currentChangeSetId, previousChangeSetId, "Some comment", GenerateUpdateCommands(i, objectIds))); previousChangeSetId = currentChangeSetId; } var commandExecutor = new CommandExecutor() .RegisterCommandHandler(new CreateObjectCommandHandler()) .RegisterCommandHandler(new ModifyAttributeCommandHandler()); var objectTypeRepository = new ObjectTypeDescriptorRepository() .RegisterUsingReflection <TestingObject>(); var dataFacade = new DataFacade(commandExecutor, dataStore, new IncrementalCachingSnapshotFactory()); var objectFacade = new ObjectFacade(dataFacade, objectTypeRepository, commandExecutor); var stopwatch = new Stopwatch(); stopwatch.Start(); var currentView = objectFacade.GetSnapshot(currentChangeSetId); var allObjects = currentView.List <TestingObject>().ToList(); stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); Assert.AreEqual(1000, allObjects.Count); foreach (var testingObject in allObjects) { Assert.AreEqual("8", testingObject.TextValue); } }
private static ChangeSet CreateChangeSet(ChangeSetId?parentChangeSetId) { return(new ChangeSet(ChangeSetId.NewUniqueId(), parentChangeSetId, "Some comment", new AbstractCommand[] { })); }