public void ExecuteBatchesWithNullOperation() { // Arrange Mock <ICloudTable> cloudTableMock = MocksFactory.GetCloudTableMock(); Mock <ITableEntityConverter <Country> > entityConverterMock = MocksFactory.GetTableEntityConverterMock <Country>(); Mock <ITableBatchPartitioner> batchPartitionerMock = MocksFactory.GetTableBatchPartitionerMock(); var executor = new TableRequestSequentialExecutor <Country>(cloudTableMock.Object, entityConverterMock.Object, batchPartitionerMock.Object); var entities = ObjectsFactory.GetCountries(); // Act && Assert Assert.Throws <ArgumentNullException>(() => executor.ExecuteBatches(entities, null)); }
public Task ExecuteBatchesWithoutResultAsyncWithNullOperation() { // Arrange Mock <ICloudTable> cloudTableMock = MocksFactory.GetCloudTableMock(); Mock <ITableEntityConverter <Country> > entityConverterMock = MocksFactory.GetTableEntityConverterMock <Country>(); Mock <ITableBatchPartitioner> batchPartitionerMock = MocksFactory.GetTableBatchPartitionerMock(); var executor = new TableRequestSequentialExecutor <Country>(cloudTableMock.Object, entityConverterMock.Object, batchPartitionerMock.Object); var entities = ObjectsFactory.GetCountries(); // Act && Assert return(Assert.ThrowsAsync <ArgumentNullException>(() => executor.ExecuteBatchesWithoutResultAsync(entities, null, CancellationToken.None))); }
public async Task ExecuteBatchesWithoutResultAsync() { // Arrange Mock <ICloudTable> cloudTableMock = MocksFactory.GetCloudTableMock(); Mock <ITableEntityConverter <Country> > entityConverterMock = MocksFactory.GetTableEntityConverterMock <Country>(); Mock <ITableBatchPartitioner> batchPartitionerMock = MocksFactory.GetTableBatchPartitionerMock(); var executor = new TableRequestSequentialExecutor <Country>(cloudTableMock.Object, entityConverterMock.Object, batchPartitionerMock.Object); var entities = ObjectsFactory.GetCountries(); // Act await executor.ExecuteBatchesWithoutResultAsync(entities, TableOperation.Insert, CancellationToken.None); // Assert entityConverterMock.Verify(p => p.GetEntity(It.IsAny <Country>()), Times.Exactly(2)); batchPartitionerMock.Verify(p => p.GetBatches(It.IsAny <IEnumerable <ITableEntity> >(), It.IsAny <Func <ITableEntity, TableOperation> >()), Times.Once()); }
public void ExecuteBatchesEvenWhenNotEvaluated() { // Arrange Mock <ICloudTable> cloudTableMock = MocksFactory.GetCloudTableMock(); Mock <ITableEntityConverter <Country> > entityConverterMock = MocksFactory.GetTableEntityConverterMock <Country>(); Mock <ITableBatchPartitioner> batchPartitionerMock = MocksFactory.GetTableBatchPartitionerMock(); var executor = new TableRequestSequentialExecutor <Country>(cloudTableMock.Object, entityConverterMock.Object, batchPartitionerMock.Object); var entities = ObjectsFactory.GetCountries(); // Act // We don't evaluate the call as we're not interested in the resulting entities. This should still execute the operations. executor.ExecuteBatches(entities, TableOperation.Insert); // Assert cloudTableMock.Verify(t => t.ExecuteBatch(It.IsAny <TableBatchOperation>())); }
public void ExecuteBatches() { // Arrange Mock <ICloudTable> cloudTableMock = MocksFactory.GetCloudTableMock(); Mock <ITableEntityConverter <Country> > entityConverterMock = MocksFactory.GetTableEntityConverterMock <Country>(); Mock <ITableBatchPartitioner> batchPartitionerMock = MocksFactory.GetTableBatchPartitionerMock(); var executor = new TableRequestSequentialExecutor <Country>(cloudTableMock.Object, entityConverterMock.Object, batchPartitionerMock.Object); var entities = ObjectsFactory.GetCountries(); // Act var result = executor.ExecuteBatches(entities, TableOperation.Insert).ToList(); // Assert Assert.IsAssignableFrom <IEnumerable <Country> >(result); entityConverterMock.Verify(p => p.GetEntity(It.IsAny <Country>()), Times.Exactly(2)); batchPartitionerMock.Verify(p => p.GetBatches(It.IsAny <IEnumerable <ITableEntity> >(), It.IsAny <Func <ITableEntity, TableOperation> >()), Times.Once()); }
public async Task RemoveEntitiesAsync() { // Arrange Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>(); CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient(); var context = new TableSet <Country>(tableClient) { RequestExecutor = mock.Object }; IList <Country> countries = ObjectsFactory.GetCountries(); // Act await context.RemoveAsync(countries); // Assert mock.Verify(executor => executor.ExecuteBatchesWithoutResultAsync(countries, TableOperation.Delete, It.IsAny <CancellationToken>())); }
public void RemoveEntities() { // Arrange Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>(); CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient(); var context = new TableSet <Country>(tableClient) { RequestExecutor = mock.Object }; IList <Country> countries = ObjectsFactory.GetCountries(); // Act context.Remove(countries); // Assert mock.Verify(executor => executor.ExecuteBatchesWithoutResult(countries, TableOperation.Delete), Times.Once()); }
public async Task CreateUpdatedAndDeleteEntitiesAsync() { // Arrange TableSet <Country> tableSet = GetTableSet(); IList <Country> countries = ObjectsFactory.GetCountries(); // Act List <Country> addedEntities = (await tableSet.AddAsync(countries)).ToList(); foreach (Country country in addedEntities) { country.Population *= 2; country.Area *= 1.3; } List <Country> updatedEntities = (await tableSet.UpdateAsync(addedEntities)).ToList(); await tableSet.RemoveAsync(updatedEntities); }
public void CreateUpdatedAndDeleteEntities() { // Arrange TableSet <Country> tableSet = GetTableSet(); IList <Country> countries = ObjectsFactory.GetCountries(); // Act List <Country> addedEntities = tableSet.Add(countries).ToList(); foreach (Country country in addedEntities) { country.Population *= 2; country.Area *= 1.3; } List <Country> updatedEntities = tableSet.Update(addedEntities).ToList(); tableSet.Remove(updatedEntities); }
public async Task AddOrUpdateEntitiesAsync() { // Arrange Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>(); CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient(); var context = new TableSet <Country>(tableClient) { RequestExecutor = mock.Object }; var countries = ObjectsFactory.GetCountries(); // Act var result = await context.AddOrUpdateAsync(countries); // Assert Assert.NotNull(result); mock.Verify(executor => executor.ExecuteBatchesAsync(countries, TableOperation.InsertOrReplace, It.IsAny <CancellationToken>())); Assert.Equal(countries, result); }
public void AddOrUpdateEntities() { // Arrange Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>(); CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient(); var context = new TableSet <Country>(tableClient) { RequestExecutor = mock.Object }; var countries = ObjectsFactory.GetCountries(); // Act var result = context.AddOrUpdate(countries); // Assert Assert.NotNull(result); mock.Verify(executor => executor.ExecuteBatches(countries, TableOperation.InsertOrReplace), Times.Once()); Assert.Equal(countries, result); }