public void ReturnsSuccessfulTransitionWhenEverythingWorks() { var state = (CreateEntityState <ITestModel, IDatabaseTestModel, IThreadSafeTestModel>)CreateState(); var entity = new TestModel(-1, SyncStatus.SyncFailed); var withPositiveId = new TestModel(13, SyncStatus.InSync); api.Create(Arg.Any <ITestModel>()) .Returns(Observable.Return(withPositiveId)); dataSource.OverwriteIfOriginalDidNotChange( Arg.Any <IThreadSafeTestModel>(), Arg.Any <IThreadSafeTestModel>()) .Returns(x => Observable.Return(new[] { new UpdateResult <IThreadSafeTestModel>(entity.Id, entityWithId((IThreadSafeTestModel)x[1], entity.Id)) })); dataSource.ChangeId(entity.Id, withPositiveId.Id).Returns(Observable.Return(withPositiveId)); var transition = state.Start(entity).SingleAsync().Wait(); var persistedEntity = ((Transition <IThreadSafeTestModel>)transition).Parameter; dataSource.Received().ChangeId(entity.Id, withPositiveId.Id); transition.Result.Should().Be(state.Done); persistedEntity.Id.Should().Be(withPositiveId.Id); persistedEntity.SyncStatus.Should().Be(SyncStatus.InSync); }
private IObservable <ITransition> updateId( IEnumerable <IConflictResolutionResult <TThreadsafeModel> > results, TThreadsafeModel originalEntity, TThreadsafeModel serverEntity) { return(dataSource.ChangeId(originalEntity.Id, serverEntity.Id) .Select(transitionBasedOnResolutionResult(results, originalEntity, serverEntity))); }
public void ReturnsTheEntityChangedTransitionWhenEntityChangesLocally() { var state = (CreateEntityState <ITestModel, IDatabaseTestModel, IThreadSafeTestModel>)CreateState(); var at = new DateTimeOffset(2017, 9, 1, 12, 34, 56, TimeSpan.Zero); var entity = new TestModel { Id = 1, At = at, SyncStatus = SyncStatus.SyncNeeded }; api.Create(Arg.Any <ITestModel>()) .Returns(Observable.Return(entity)); dataSource .OverwriteIfOriginalDidNotChange(Arg.Any <IThreadSafeTestModel>(), Arg.Any <IThreadSafeTestModel>()) .Returns(Observable.Return(new[] { new IgnoreResult <IThreadSafeTestModel>(entity.Id) })); dataSource.ChangeId(Arg.Any <long>(), entity.Id).Returns(Observable.Return(entity)); var transition = state.Start(entity).SingleAsync().Wait(); var parameter = ((Transition <IThreadSafeTestModel>)transition).Parameter; transition.Result.Should().Be(state.EntityChanged); parameter.Id.Should().Be(entity.Id); }
private IObservable <ITransition> updateId(long originalId, long id) => dataSource.ChangeId(originalId, id).Select(EntityChanged.Transition);