private async Task <int?> PushCoreAsync() { if (_familyId == null) { throw new InvalidOperationException("No familyId has been specified; the service must be initialized first with a valid familyId."); } var pushRequest = Dto.pushRequest(State); if (pushRequest.IsSome()) { var pushResponse = await _cosmos.PushAsync(_familyId, pushRequest.Value); var import = Dto.changesAsImport(pushResponse); if (import.IsSome()) { var message = StateTypes.StateMessage.NewImport(import.Value); State = StateModule.updateUsingStandardClock(message, State); OnChange?.Invoke(); return(import.Value.EarliestTimestamp.AsNullable()); } else { return(null); } } else { return(null); } }
private async Task <int?> PushCoreAsync() { var pushRequest = Dto.pushRequest(State); if (pushRequest.IsSome()) { var pushResponse = await _cosmos.PushAsync(FamilyIdModule.serialize(State !.FamilyId), pushRequest.Value); var import = Dto.changesAsImport(pushResponse); if (import.IsSome()) { var message = StateTypes.StateMessage.NewImport(import.Value); State = StateModule.updateUsingStandardClock(message, State); OnChange?.Invoke(); return(import.Value.EarliestTimestamp.AsNullable()); } else { return(null); } } else { return(null); } }
private async Task PullCoreAsync(int?after, int?before) { var pullResponse = (after is null && before is null) ? await _cosmos.PullEverythingAsync(FamilyIdModule.serialize(State !.FamilyId)) : await _cosmos.PullIncrementalAsync(FamilyIdModule.serialize(State !.FamilyId), after ?? int.MinValue, before); var import = Dto.changesAsImport(pullResponse); if (import.IsSome()) { var message = StateTypes.StateMessage.NewImport(import.Value); State = StateModule.updateUsingStandardClock(message, State); OnChange?.Invoke(); } }
private async Task PullCoreAsync(int?after, int?before) { if (_familyId == null) { throw new InvalidOperationException("No familyId has been specified; the service must be initialized first with a valid familyId."); } var pullResponse = (after is null && before is null) ? await _cosmos.PullEverythingAsync(_familyId) : await _cosmos.PullIncrementalAsync(_familyId, after ?? int.MinValue, before); var import = Dto.changesAsImport(pullResponse); if (import.IsSome()) { var message = StateTypes.StateMessage.NewImport(import.Value); State = StateModule.updateUsingStandardClock(message, State); OnChange?.Invoke(); } }
public async Task CanPushThenPullSameNumberOfItems() { // Would be easier to test using F# since could compare the actual State variables // with the eTag values removed using var c = await CreateTargetAsync(); var stateA = StateModule.createSampleData(FamilyIdModule.anonymous, UserIdModule.anonymous); await Dto.pushRequest(stateA).DoAsync(changes => c.PushAsync(_familyId, changes)); var pulledChanges = await c.PullEverythingAsync(_familyId); var pulledChangesAsImport = Dto.changesAsImport(pulledChanges); var stateB = StateModule.importChanges(pulledChangesAsImport.Value, stateA); Assert.Equal(stateA.Items.Item.Count, stateB.Items.Item.Count); Assert.Equal(stateA.Categories.Item.Count, stateB.Categories.Item.Count); Assert.Equal(stateA.Stores.Item.Count, stateB.Stores.Item.Count); Assert.Equal(stateA.NotSoldItems.Item.Count, stateB.NotSoldItems.Item.Count); Assert.Equal(stateA.Purchases.Item.Count, stateB.Purchases.Item.Count); }