public void ValidateCollapse_InsertOperation_Throws() { var sut = new UpdateOperation("test", "1234"); var newOp = new InsertOperation("test", "1234"); Assert.Throws <InvalidOperationException>(() => sut.ValidateOperationCanCollapse(newOp)); }
private void AppendInsertOperation(IList <BaseOperation> operations, Difference diff) { var insertOperation = new InsertOperation { OwnerMetadata = diff.OwnerMetadata, OwnerPropertyMetadata = diff.OwnerPropertyMetadata, OwnerPrimaryKeyColumn = diff.OwnerMetadata == null ? null : diff.OwnerMetadata.PrimaryKey.Prop.Name, Owner = diff.Owner, TableName = diff.OwnerMetadata == null ? null : diff.OwnerMetadata.TableName, ValueMetadata = diff.ValueMetadata, Value = diff.NewValue }; if (IsViableParentUpdateOnManyToOneRelationship(insertOperation, diff)) { AddUpdateOnParentTableForInsertDeleteOfManyToOneChildRow(operations, diff, insertOperation); } else if (IsViableParentUpdateOnOneToOneWithFkInParent(insertOperation, diff)) { AddUpdateOnParentTableForInsertDeleteOfOneToOneChildRow(operations, diff, insertOperation); } else if (!ShouldFilterOutForParticularCardinalitiesBecauseFkOnParent(insertOperation)) { AddInsertToListAtCorrectLocation(operations, insertOperation); } }
public T Insert <T>(T entity) where T : class { InsertOperation <T> operation = new InsertOperation <T>(this); operation.Execute(entity); return(entity); }
public bool ProcessTransactionRecord(ProcessRecordRequest request) { InsertOperation _insertOperation = new InsertOperation(); _insertOperation.UpdateFraudStatus(request.TransactionId, (request.IsFraud == "y")); return(true); }
public void Collapse_MismatchedItemId_Throws() { var sut = new InsertOperation("test", "1234"); var newOp = new UpdateOperation("test", "4321"); Assert.Throws <ArgumentException>(() => sut.CollapseOperation(newOp)); }
InsertResult <JSONDocument> IDocumentStore.InsertDocument(InsertOperation operation) { UsageStats stats = new UsageStats(); stats.BeginSample(); InsertResult <JSONDocument> result = new InsertResult <JSONDocument>(); CacheItem citem = new CacheItem(); citem.Document = operation.Document; citem.Flag.SetBit(BitsetConstants.DocumentDirty); citem.Flag.SetBit(BitsetConstants.MetaDataDirty); citem.Flag.UnsetBit(BitsetConstants.MarkedForDeletion); CacheInsert(operation.RowId, citem, false); _indexManager.AddToIndex(operation.RowId, operation.Document, operation.OperationId); _parent.MetadataIndex.Add(new DocumentKey(operation.Document.Key), operation.RowId, operation.Document, operation.Context); PersistenceOperation persistenceOperation = new PersistenceInsertOperation(operation.OperationId, _parent.Name, operation.RowId, citem, operation.Context); AddToPersistenceDictionary(persistenceOperation); result.RowId = operation.RowId; if (_statsCollector != null) { stats.EndSample(); _statsCollector.IncrementStatsValue(StatisticsType.AvgInsertTime, stats.Current); _statsCollector.IncrementStatsValue(StatisticsType.InsertsPerSec); } return(result); }
private void AppendInsertOperation(IList<BaseOperation> operations, Difference diff) { var insertOperation = new InsertOperation { OwnerMetadata = diff.OwnerMetadata, OwnerPropertyMetadata = diff.OwnerPropertyMetadata, OwnerPrimaryKeyColumn = diff.OwnerMetadata == null ? null : diff.OwnerMetadata.PrimaryKey.Prop.Name, Owner = diff.Owner, TableName = diff.OwnerMetadata == null ? null : diff.OwnerMetadata.TableName, ValueMetadata = diff.ValueMetadata, Value = diff.NewValue }; if (IsViableParentUpdateOnManyToOneRelationship(insertOperation, diff)) { AddUpdateOnParentTableForInsertDeleteOfManyToOneChildRow(operations, diff, insertOperation); } else if (IsViableParentUpdateOnOneToOneWithFkInParent(insertOperation, diff)) { AddUpdateOnParentTableForInsertDeleteOfOneToOneChildRow(operations, diff, insertOperation); } else if (!ShouldFilterOutForParticularCardinalitiesBecauseFkOnParent(insertOperation)) { AddInsertToListAtCorrectLocation(operations, insertOperation); } }
public void ValidateCollapse_UpdateOperation_OK() { var sut = new InsertOperation("test", "1234"); var newOp = new UpdateOperation("test", "1234"); sut.ValidateOperationCanCollapse(newOp); }
public void Validate_Throws_WithInsertOperation() { var newOperation = new InsertOperation("test", MobileServiceTableKind.Table, "abc"); var ex = AssertEx.Throws <InvalidOperationException>(() => this.operation.Validate(newOperation)); Assert.AreEqual("An insert operation on the item is already in the queue.", ex.Message); }
private static void Transform(InsertOperation o1, InsertOperation o2) { if (o1.Position < o2.Position || (o1.Position == o2.Position && o1.CreatedAt < o2.CreatedAt)) { o2.Position += o1.Length; } }
public async Task ExecuteAsync_LoadsTheItem_IfItIsNotPresent() { var op = new InsertOperation("table", MobileServiceTableKind.Table, "id"); this.store.Setup(s => s.LookupAsync("table", "id")).Returns(Task.FromResult(new JObject())); await this.TestExecuteAsync(op, null, null); }
public void InsertOperation_CreateInverse_CreatesDeleteOperation() { var state = new DocumentState(1, "123456789"); var insert = new InsertOperation(state, 2, 'x'); Assert.IsInstanceOfType(insert.CreateInverse(state), typeof(DeleteOperation)); }
public async Task ExecuteRemote_CallsRemoteServer_WithFailure(HttpStatusCode statusCode) { var client = GetMockClient(); if (statusCode == HttpStatusCode.Conflict || statusCode == HttpStatusCode.PreconditionFailed) { MockHandler.AddResponse(statusCode, new IdEntity { Id = "1234", StringValue = "movie" }); } else { MockHandler.AddResponse(statusCode); } var sut = new InsertOperation("test", "1234") { Item = testObject }; var exception = await Assert.ThrowsAnyAsync <DatasyncInvalidOperationException>(() => sut.ExecuteOperationOnRemoteServiceAsync(client)); if (statusCode == HttpStatusCode.Conflict || statusCode == HttpStatusCode.PreconditionFailed) { Assert.IsAssignableFrom <DatasyncConflictException>(exception); Assert.NotNull(exception.Value); } Assert.NotNull(exception.Request); Assert.NotNull(exception.Response); Assert.Equal(statusCode, exception.Response?.StatusCode); }
public void Operation_CanBeCancelled() { var operation = new InsertOperation("test", "1234"); Assert.False(operation.IsCancelled); operation.Cancel(); Assert.True(operation.IsCancelled); }
public void InsertOperation_CreateInverse_InverseUndoesInsert() { var state = new DocumentState(1, "123456789"); var insert = new InsertOperation(state, 2, 'x'); var insertedstate = insert.ApplyTransform(state.CurrentState); Assert.AreEqual(state.CurrentState, insert.CreateInverse(state).ApplyTransform(insertedstate)); }
public async Task ExecuteAsync_DeletesTheErrors() { var op = new InsertOperation("table", MobileServiceTableKind.Table, "id") { Item = new JObject() }; // putting an item so it won't load it await this.TestExecuteAsync(op, null, null); }
public void Operation_CanSetItem() { var operation = new InsertOperation("test", "1234") { Item = testObject }; Assert.Equal(operation.Item, testObject); }
public async Task ExecuteAsync_SavesTheResult_IfExecuteTableOperationDoesNotThrow() { var op = new InsertOperation("table", MobileServiceTableKind.Table, "id") { Item = new JObject() }; await TestResultSave(op, status : null, resultId : "id", saved : true); }
public void DocumentState_ApplyTransform_TransformGetsApplied() { var DocumentState = new DocumentState(1, "1234"); var transform = new InsertOperation(DocumentState, 0, 'a'); DocumentState.ApplyTransform(new AppliedOperation(transform)); Assert.AreEqual(DocumentState.AppliedOperations.SingleOrDefault().Value, transform); Assert.AreEqual("a1234", DocumentState.CurrentState); }
public void Operation_CanBeUpdated() { var operation = new InsertOperation("test", "1234"); Assert.False(operation.IsUpdated); operation.Update(); Assert.Equal(2, operation.Version); Assert.True(operation.IsUpdated); }
public void DocumentState_ApplyTransform_CaretClampedForInsertBefore() { var DocumentState = new DocumentState(1, "1234"); var transform = new InsertOperation(DocumentState, 0, 'a'); var caretIndex = 4; DocumentState.ApplyTransform(new AppliedOperation(transform), ref caretIndex); Assert.IsTrue(caretIndex <= DocumentState.CurrentState.Length); }
public void DocumentState_ApplyTransform_CaretSameForInsertSame() { var DocumentState = new DocumentState(1, "1234"); var transform = new InsertOperation(DocumentState, 3, 'a'); var caretIndex = 3; DocumentState.ApplyTransform(new AppliedOperation(transform), ref caretIndex); Assert.AreEqual(3, caretIndex); }
public decimal Validate() { SelectOperation SoP = new SelectOperation(); var count = SoP.FindFraudIpExists(ipAddress); if (count > 0) { if (count > 3) { return(1); } if (count > 2) { return(0.9M); } if (count > 1) { return(0.8M); } } var maxMindAPI = "https://www.maxmind.com/geoip/v2.1/city/{0}?use-downloadable-db=1&demo=1"; var http = new HttpClient(); http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var url = String.Format(maxMindAPI, ipAddress); try { var response = http.GetAsync(url).Result; //HttpResponseMessage res1 = http.GetAsync("https://ebanking.bankofmaldives.com.mv/xe/").Result; var result = response.Content.ReadAsStringAsync().Result; IpAddressValidatorResponse obj = JsonConvert.DeserializeObject <IpAddressValidatorResponse>(result); if (obj != null) { //Error Response or Not India if (!string.IsNullOrEmpty(obj.error) || (obj.country != null && !obj.country.iso_code.Equals("IN"))) { InsertOperation op = new InsertOperation(); op.InsertFraudRecord(ipAddress); //new Record return(0.5M); } } return(0); } catch (Exception ex) { //Write Exception } return(0.1M); }
public void Deserialize_Works_WithoutItem() { var expected = new InsertOperation("test", "1234"); serializedObject["item"] = null; // We aren't expecting this. var operation = TableOperation.Deserialize(serializedObject); Assert.IsAssignableFrom <InsertOperation>(operation); Assert.Equal(expected, operation); }
public async Task ExecuteAsync_DoesNotSaveTheResult_IfExecuteTableOperationThrows() { this.store.Setup(s => s.UpsertAsync(MobileServiceLocalSystemTables.SyncErrors, It.IsAny <JObject[]>(), false)).Returns(Task.FromResult(0)); var op = new InsertOperation("table", MobileServiceTableKind.Table, "id") { Item = new JObject() }; await TestResultSave(op, status : HttpStatusCode.PreconditionFailed, resultId : "id", saved : false); }
public void ValidateCollapse_ActiveDeleteOperation_Throws() { var sut = new InsertOperation("test", "1234") { State = TableOperationState.Failed }; var newOp = new DeleteOperation("test", "1234"); Assert.Throws <InvalidOperationException>(() => sut.ValidateOperationCanCollapse(newOp)); }
public void ValidateCollapse_PendingDeleteOperation_OK() { var sut = new InsertOperation("test", "1234"); var newOp = new DeleteOperation("test", "1234") { State = TableOperationState.Pending }; sut.ValidateOperationCanCollapse(newOp); }
public void Collapse_DeleteOperation() { var sut = new InsertOperation("test", "1234"); var newOp = new DeleteOperation("test", "1234"); sut.CollapseOperation(newOp); Assert.True(sut.IsCancelled); Assert.True(newOp.IsCancelled); }
public void GetHashCode_Works() { var sut = new InsertOperation("test", "1234") { Item = testObject }; var hash = "1234".GetHashCode(); Assert.Equal(hash, sut.GetHashCode()); }
public async Task ExecuteAsync_DoesNotSaveTheResult_IfPresentButResultDoesNotHaveId() { this.action = new PushAction(this.opQueue.Object, this.store.Object, MobileServiceTableKind.Table, null, this.handler.Object, this.client.Object, this.context.Object, CancellationToken.None); var op = new InsertOperation("table", MobileServiceTableKind.Table, "id") { Item = new JObject() }; await TestResultSave(op, status : null, resultId : null, saved : false); }
public async Task ExecuteOnOfflineStore_ExistingItem_Throws() { var store = new Mock <IOfflineStore>(); store.Setup(x => x.GetItemAsync("test", "1234", It.IsAny <CancellationToken>())).Returns(Task.FromResult(testObject)); store.Setup(x => x.UpsertAsync("test", It.IsAny <IEnumerable <JObject> >(), It.IsAny <bool>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask); var sut = new InsertOperation("test", "1234"); await Assert.ThrowsAsync <OfflineStoreException>(() => sut.ExecuteOperationOnOfflineStoreAsync(store.Object, testObject)); }
private void AddInsertToListAtCorrectLocation(IList<BaseOperation> operations, InsertOperation insertOperation) { var transformed = Transform(insertOperation); if (transformed == insertOperation) { if (null != insertOperation.OwnerPropertyMetadata && insertOperation.OwnerPropertyMetadata.IsOneToOneRelationship && (!insertOperation.ValueMetadata.IsReferenceData && !insertOperation.OwnerPropertyMetadata.HasAttribute<ReferenceDataAttribute>()) && insertOperation.OwnerPropertyMetadata.HasAttribute<ForeignKeyReferenceAttribute>()) { PrependInsertBeforeParentTableInsert(operations, insertOperation); } else { operations.Add(transformed); } } else { operations.Add(transformed); } }
private static void PrependInsertBeforeParentTableInsert( IList<BaseOperation> operations, InsertOperation insertOperation) { int index = operations.Count - 1; while (index >= 0) { var possibleMatch = operations[index] as InsertOperation; if (null != possibleMatch && possibleMatch.ValueMetadata == insertOperation.OwnerMetadata) { operations.Insert(index, insertOperation); break; } --index; } if (index < 0) { operations.Add(insertOperation); } }
public void Test_InsertTwiceAt0ThenInMiddle() { InsertOperation insert1 = new InsertOperation("world", 0); InsertOperation insert2 = new InsertOperation("hello", 2); textEditorTextContext.Insert(null, insert1); Assert.AreEqual("world", textEditorTextContext.Data, "Inconsistent state after insertion!"); textEditorTextContext.Insert(null, insert2); Assert.AreEqual("wohellorld", textEditorTextContext.Data, "Inconsistent state after insertion!"); }
public void Test_InsertEmptyAt5() { InsertOperation insert = new InsertOperation("text", 5); Assert.Throws(typeof(ArgumentOutOfRangeException), delegate { textEditorTextContext.Insert(null, insert); }, "Insertion out of range was accepted!"); }
public void Test_InsertEmptyAt0() { InsertOperation insert = new InsertOperation("text", 0); textEditorTextContext.Insert(null, insert); Assert.AreEqual("text", textEditorTextContext.Data, "Inconsistent state after insertion!"); }
public void Test_InsertAndDelete() { InsertOperation insert = new InsertOperation("world", 0); DeleteOperation delete = new DeleteOperation(3); textEditorTextContext.Insert(null, insert); Assert.AreEqual("world", textEditorTextContext.Data, "Inconsistent state after insertion!"); textEditorTextContext.Delete(null, delete); Assert.AreEqual("word", textEditorTextContext.Data, "Inconsistent state after deletion!"); }
public InsertCommand(InsertOperation operation) : base(operation) { }
/// <inheritdoc/> public override void Insert(object issuer, InsertOperation operation) { TextBox.TextChanged -= TextBoxChanged; TextBox.Text.Insert(operation.Position, operation.Text.ToString()); TextBox.TextChanged += TextBoxChanged; }
/// <inheritdoc/> public override void Insert(object issuer, InsertOperation operation) { Data = Data.Substring(0, operation.Position) + operation.Text + Data.Substring(operation.Position); OnInserted(new InsertEventArgs(issuer, operation)); OnChanged(new ChangeEventArgs(issuer)); }
public void Test_InsertTwiceAt0ThenAtEnd() { InsertOperation insert1 = new InsertOperation("world", 0); InsertOperation insert2 = new InsertOperation("hello", 5); stringTextContext.Insert(null, insert1); Assert.AreEqual("world", stringTextContext.Data, "Inconsistent state after insertion!"); stringTextContext.Insert(null, insert2); Assert.AreEqual("worldhello", stringTextContext.Data, "Inconsistent state after insertion!"); }
/// <inheritdoc/> public override void Insert(object issuer, InsertOperation operation) { UnsubscribeFromTextBox(); TextBox.Document.Insert(operation.Position, operation.Text.ToString()); SubscribeToTextBox(); }