Example #1
0
        public async Task AddOrUpdateEntitiesWithNullParameterAsync()
        {
            // Arrange
            Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>();
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context = new TableSet <Country>(tableClient)
            {
                RequestExecutor = mock.Object
            };

            IEnumerable <Country> result = null;

            // Act
            try
            {
                result = await context.AddOrUpdateAsync((IEnumerable <Country>) null, CancellationToken.None);
            }
            catch (ArgumentNullException)
            {
            }

            // Assert
            Assert.Null(result);
            mock.Verify(executor => executor.ExecuteBatches(It.IsAny <IEnumerable <Country> >(), It.IsAny <Func <ITableEntity, TableOperation> >()), Times.Never());
        }
Example #2
0
        public void CreateTableSetWithNullTableNameParameter()
        {
            CloudTableClient   tableClient = ObjectsFactory.GetCloudTableClient();
            TableSet <Country> context     = null;

            // Act && Assert
            Assert.Throws <ArgumentNullException>(() => { context = new TableSet <Country>(tableClient, null); });

            Assert.Null(context);
        }
Example #3
0
        public void CreateTableSetWithTableClientAndNameParameters()
        {
            // Arrange
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            const string     tableName   = "tableName";

            // Act
            var context = new TableSet <Country>(tableClient, tableName);

            // Assert
            Assert.Equal(tableName, context.RequestExecutorFactory.CloudTable.Name);
        }
Example #4
0
        public void ChangeTableSetExecutionMode()
        {
            // Arrange
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context = new TableSet <Country>(tableClient);

            // Act
            context.ExecutionMode = ExecutionMode.Parallel;

            // Assert
            Assert.Equal(ExecutionMode.Parallel, context.ExecutionMode);
            Assert.IsType <TableRequestParallelExecutor <Country> >(context.RequestExecutor);
        }
Example #5
0
        public void CreateTableSetWithTableClientParameter()
        {
            // Arrange
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();

            // Act
            var context = new TableSet <Country>(tableClient);

            // Assert
            Assert.Equal(typeof(Country).Name, context.RequestExecutorFactory.CloudTable.Name);
            Assert.Equal(ExecutionMode.Sequential, context.ExecutionMode);
            Assert.IsType <TableRequestSequentialExecutor <Country> >(context.RequestExecutor);
        }
        public void RemoveEmptyCollection()
        {
            // Arrange
            Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>();
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context = new TableSet <Country>(tableClient)
            {
                RequestExecutor = mock.Object
            };

            var countries = new List <Country>();

            // Act
            context.Remove(countries);
        }
Example #7
0
        public void SetTheSameExecutionMode()
        {
            // Arrange
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context  = new TableSet <Country>(tableClient);
            var executor = context.RequestExecutor;

            // Act
            context.ExecutionMode = ExecutionMode.Sequential;

            // Assert
            Assert.Equal(ExecutionMode.Sequential, context.ExecutionMode);
            Assert.IsType <TableRequestSequentialExecutor <Country> >(context.RequestExecutor);
            Assert.Same(executor, context.RequestExecutor);
        }
        public void RemoveEntitiesWithNullParameter()
        {
            // Arrange
            Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>();
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context = new TableSet <Country>(tableClient)
            {
                RequestExecutor = mock.Object
            };

            // Act
            Assert.Throws <ArgumentNullException>(() => context.Remove((IList <Country>)null));

            // Assert
            mock.Verify(executor => executor.ExecuteBatches(It.IsAny <IList <Country> >(), It.IsAny <Func <ITableEntity, TableOperation> >()), Times.Never());
        }
        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 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>()));
        }
Example #11
0
        public void AddOrUpdateEmptyCollection()
        {
            // Arrange
            Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>();
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context = new TableSet <Country>(tableClient)
            {
                RequestExecutor = mock.Object
            };

            var countries = new List <Country>();

            // Act
            var result = context.AddOrUpdate(countries);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(countries, result);
        }
Example #12
0
        public void AddOrUpdateEntitiesWithNullParameter()
        {
            // Arrange
            Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>();
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context = new TableSet <Country>(tableClient)
            {
                RequestExecutor = mock.Object
            };

            IEnumerable <Country> result = null;

            // Act
            Assert.Throws <ArgumentNullException>(() => { result = context.AddOrUpdate((IEnumerable <Country>)null); });

            // Assert
            Assert.Null(result);
            mock.Verify(executor => executor.ExecuteBatches(It.IsAny <IEnumerable <Country> >(), It.IsAny <Func <ITableEntity, TableOperation> >()), Times.Never());
        }
Example #13
0
        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);
        }
Example #14
0
        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);
        }
Example #15
0
        public void AddEntity_FluentMapping()
        {
            // Arrange
            Mock <ITableRequestExecutor <Address> > mock = MocksFactory.GetQueryExecutorMock <Address>();
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context = new TableSet <Address>(tableClient)
            {
                RequestExecutor = mock.Object
            };

            Address model = ObjectsFactory.GetAddress();

            // Act
            Address result = context.Add(model);

            // Assert
            Assert.NotNull(result);
            mock.Verify(executor => executor.Execute(model, TableOperation.Insert), Times.Once());
            Assert.Equal(model, result);
        }
        public void AddEntity()
        {
            // Arrange
            Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>();
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context = new TableSet <Country>(tableClient)
            {
                RequestExecutor = mock.Object
            };

            Country country = ObjectsFactory.GetCountry();

            // Act
            Country result = context.Add(country);

            // Assert
            Assert.NotNull(result);
            mock.Verify(executor => executor.Execute(country, TableOperation.Insert), Times.Once());
            Assert.Equal(country, result);
        }
        public async Task AddEntityAsync()
        {
            // Arrange
            Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>();
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context = new TableSet <Country>(tableClient)
            {
                RequestExecutor = mock.Object
            };

            Country country = ObjectsFactory.GetCountry();

            // Act
            Country result = await context.AddAsync(country);

            // Assert
            Assert.NotNull(result);
            mock.Verify(executor => executor.ExecuteAsync(country, TableOperation.Insert, It.IsAny <CancellationToken>()));
            Assert.Equal(country, result);
        }
        public async Task RemoveEntityWithNullParameterAsync()
        {
            // Arrange
            Mock <ITableRequestExecutor <Country> > mock = MocksFactory.GetQueryExecutorMock <Country>();
            CloudTableClient tableClient = ObjectsFactory.GetCloudTableClient();
            var context = new TableSet <Country>(tableClient)
            {
                RequestExecutor = mock.Object
            };

            // Act
            try
            {
                await context.RemoveAsync((Country)null, CancellationToken.None);
            }
            catch (ArgumentNullException)
            {
            }

            // Assert
            mock.Verify(executor => executor.Execute(It.IsAny <Country>(), It.IsAny <Func <ITableEntity, TableOperation> >()), Times.Never());
        }