public void It_creates_state_entry_adapter() { var entry = TestStateEntry.Mock().WithType(typeof(PocoTestType)).WithEntity(new PocoTestType()); var adapter = _factory.CreateFromStateEntry(entry); Assert.NotNull(adapter); Assert.IsType <StateEntryTableEntityAdapter <PocoTestType> >(adapter); }
public void It_throws_concurrency_exception() { QueueError(TestTableResult.WithStatus(HttpStatusCode.PreconditionFailed)); var entries = new List <StateEntry> { TestStateEntry.Mock().WithState(EntityState.Added).WithType("Test1") }; Assert.Equal( Strings.ETagPreconditionFailed, Assert.ThrowsAsync <DbUpdateConcurrencyException>(() => SaveChangesAsync(entries)).Result.Message); }
public void It_throws_dbupdate_exception() { QueueError(TestTableResult.BadRequest()); var entries = new List <StateEntry> { TestStateEntry.Mock().WithState(EntityState.Added).WithProperty("PartitionKey", "A"), }; Assert.Equal( Strings.SaveChangesFailed, Assert.ThrowsAsync <DbUpdateException>(() => SaveChangesAsync(entries)).Result.Message); }
public void It_saves() { QueueResult(TestTableResult.OK(), TestTableResult.OK(), TestTableResult.OK()); var entries = new List <StateEntry> { TestStateEntry.Mock().WithState(EntityState.Added).WithType("Test1"), TestStateEntry.Mock().WithState(EntityState.Modified).WithType("Test1"), TestStateEntry.Mock().WithState(EntityState.Deleted).WithType("Test1"), }; var succeeded = SaveChangesAsync(entries).Result; Assert.Equal(3, succeeded); }
public void It_separates_by_partition_key() { QueueResult(new[] { TestTableResult.OK(), TestTableResult.OK(), TestTableResult.OK() }, new[] { TestTableResult.OK(), TestTableResult.OK(), TestTableResult.OK() }); var entries = new List <StateEntry> { TestStateEntry.Mock().WithState(EntityState.Added).WithProperty("PartitionKey", "A"), TestStateEntry.Mock().WithState(EntityState.Modified).WithProperty("PartitionKey", "A"), TestStateEntry.Mock().WithState(EntityState.Deleted).WithProperty("PartitionKey", "A"), TestStateEntry.Mock().WithState(EntityState.Added).WithProperty("PartitionKey", "B"), TestStateEntry.Mock().WithState(EntityState.Modified).WithProperty("PartitionKey", "B"), TestStateEntry.Mock().WithState(EntityState.Deleted).WithProperty("PartitionKey", "B"), }; Assert.Equal(6, SaveChangesAsync(entries).Result); }
public void It_maps_entity_state_to_table_operations(EntityState entityState, TableOperationType operationType) { var entry = TestStateEntry.Mock().WithState(entityState); var request = CreateRequest(new AtsTable("Test"), entry); if (request == null) { Assert.True(EntityState.Unknown.HasFlag(entityState) || EntityState.Unchanged.HasFlag(entityState)); } else { var propInfo = typeof(TableOperation).GetProperty("OperationType", BindingFlags.NonPublic | BindingFlags.Instance); var type = (TableOperationType)propInfo.GetValue(request.Operation); Assert.Equal(operationType, type); } }
public void It_saves_changes(int expectedChanges) { var entries = new List <StateEntry>(expectedChanges); var responses = new List <TableResult>(expectedChanges); for (var i = 0; i < expectedChanges; i++) { entries.Add(TestStateEntry.Mock().WithState(EntityState.Added).WithType("TestType").WithProperty("PartitionKey", "A")); responses.Add(TestTableResult.OK()); if (responses.Count >= 100) { QueueResult(responses); responses = new List <TableResult>(); } } if (responses.Any()) { QueueResult(responses); } var actualChanges = SaveChangesAsync(entries).Result; Assert.Equal(expectedChanges, actualChanges); }