Esempio n. 1
0
        public void WriteToServerThrowsArgumentExceptionWhenRecordsIsEmpty()
        {
            // Arrange
            BulkInsertService <TestClass, OtherClass> service = GetBulkServiceInstance();

            // Act and Asert
            Assert.Throws <ArgumentException>(
                () => service.WriteToServer(null, "tableName")
                );
        }
Esempio n. 2
0
        public void WriteToServerThrowsArgumentExceptionWhenTableNameIsNullOrWhiteSpace(string tableName)
        {
            // Arrange
            BulkInsertService <TestClass, OtherClass> service = GetBulkServiceInstance();

            var data = new List <TestClass>()
            {
                new TestClass()
                {
                    Id = 3
                }
            };

            // Act and asert
            Assert.Throws <ArgumentException>(
                () => service.WriteToServer(data, tableName)
                );
        }
Esempio n. 3
0
        public void WriteToServerShouldMapAndCallBulkInsert()
        {
            var records = new List <TestClass>()
            {
                new TestClass()
                {
                    Id = 30
                }
            };
            const string tableName       = "TableName";
            var          transformedData = new OtherClass();

            // Arrange
            var bulkInsertMoq = new Mock <IBulkInsert <OtherClass> >();

            var dataTransformerMoq = new Mock <IDataTransformer <IEnumerable <TestClass>, OtherClass> >();

            dataTransformerMoq.Setup(m => m.Transform(records))
            .Returns(transformedData);

            var mappingAdapterMoq = new Mock <IMappingAdapter <TestClass> >();

            mappingAdapterMoq.Setup(m => m.GetTableName())
            .Returns(tableName);

            // Act
            var service = new BulkInsertService <TestClass, OtherClass>(
                bulkInsert: bulkInsertMoq.Object,
                dataTransformer: dataTransformerMoq.Object,
                mappingAdapter: mappingAdapterMoq.Object
                );

            service.WriteToServer(records);

            // Assert
            bulkInsertMoq.Verify(m => m.Write(tableName, transformedData));
            dataTransformerMoq.Verify(m => m.Transform(records), Times.Once);
            mappingAdapterMoq.Verify(m => m.GetTableName(), Times.Once);

            bulkInsertMoq.VerifyNoOtherCalls();
            dataTransformerMoq.VerifyNoOtherCalls();
            mappingAdapterMoq.VerifyNoOtherCalls();
        }