Permalink
Browse files

Added CustomLogger and removed log4net, added FileConfiguration that …

…is passed to the repository constructor, instead of passing a file name to the method. This is done to accomodate one of our custom apps.
  • Loading branch information...
1 parent 356833e commit c22cb9300f7640f7555968fc851e5d0c57fbd693 @shashankshetty shashankshetty committed Jul 14, 2009
Showing with 450 additions and 28,732 deletions.
  1. BIN lib/XDDNDK2.dll
  2. BIN lib/log4net.dll
  3. +0 −28,655 lib/log4net.xml
  4. BIN src/ExcelMapper.Tests/Excel/{Users.xls → UsersXls.xls}
  5. BIN src/ExcelMapper.Tests/Excel/{Users.xlsx → UsersXlsx.xlsx}
  6. +7 −2 src/ExcelMapper.Tests/ExcelMapper.Tests.csproj
  7. +65 −15 src/ExcelMapper.Tests/ExcelToDTOMapperTests.cs
  8. +3 −3 src/ExcelMapper.Tests/Repository/Connection/ConnectionTests.cs
  9. +14 −6 src/ExcelMapper.Tests/Repository/ExcelRepositoryTests.cs
  10. +23 −0 src/ExcelMapper.Tests/RunTimCodeGeneratorLoggingConfig.xml
  11. +6 −5 src/ExcelMapper.Tests/TestData.cs
  12. +3 −1 src/ExcelMapper/Configuration/ExcelMapperRegistry.cs
  13. +12 −0 src/ExcelMapper/Configuration/FileConfiguration.cs
  14. +6 −2 src/ExcelMapper/ExcelMapper.csproj
  15. +10 −4 src/ExcelMapper/ExcelToDTOMapper.cs
  16. +2 −2 src/ExcelMapper/Repository/Connection/{Connection.cs → ConnectionBuilder.cs}
  17. +1 −1 src/ExcelMapper/Repository/Connection/{IConnection.cs → IConnectionBuilder.cs}
  18. +12 −9 src/ExcelMapper/Repository/ExcelRepository.cs
  19. +3 −3 src/ExcelMapper/Repository/IRepository.cs
  20. +3 −4 src/RunTimeCodeGenerator.Tests/AssemblyGeneration/AssemblyGeneratorTests.cs
  21. +2 −2 src/RunTimeCodeGenerator.Tests/ClassGeneration/ClassFileGeneratorTests.cs
  22. +32 −0 src/RunTimeCodeGenerator.Tests/Logging/FileListenerTests.cs
  23. +36 −0 src/RunTimeCodeGenerator.Tests/Logging/LogTests.cs
  24. +26 −0 src/RunTimeCodeGenerator.Tests/Logging/LoggerTests.cs
  25. +3 −0 src/RunTimeCodeGenerator.Tests/RunTimeCodeGenerator.Tests.csproj
  26. +1 −2 src/RunTimeCodeGenerator.Tests/TestData.cs
  27. +4 −9 src/RunTimeCodeGenerator/AssemblyGeneration/AssemblyGenerator.cs
  28. +1 −1 src/RunTimeCodeGenerator/ClassGeneration/ClassAttributes.cs
  29. +1 −1 src/RunTimeCodeGenerator/DefaultSettings.cs
  30. +12 −0 src/RunTimeCodeGenerator/Logging/ConsoleListener.cs
  31. +23 −0 src/RunTimeCodeGenerator/Logging/FileListener.cs
  32. +7 −0 src/RunTimeCodeGenerator/Logging/IListener.cs
  33. +9 −0 src/RunTimeCodeGenerator/Logging/ILogFactory.cs
  34. +17 −0 src/RunTimeCodeGenerator/Logging/ILogger.cs
  35. +15 −0 src/RunTimeCodeGenerator/Logging/Log.cs
  36. +15 −0 src/RunTimeCodeGenerator/Logging/LogFactory.cs
  37. +50 −0 src/RunTimeCodeGenerator/Logging/Logger.cs
  38. +16 −0 src/RunTimeCodeGenerator/Logging/MessageType.cs
  39. +10 −5 src/RunTimeCodeGenerator/RunTimeCodeGenerator.csproj
View
Binary file not shown.
View
Binary file not shown.
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -93,13 +93,18 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <None Include="Excel\Users.xls">
+ <None Include="Excel\UsersXls.xls">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
- <None Include="Excel\Users.xlsx">
+ <None Include="Excel\UsersXlsx.xlsx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
+ <ItemGroup>
+ <Content Include="RunTimCodeGeneratorLoggingConfig.xml">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Reflection;
using ExcelMapper.Configuration;
using ExcelMapper.Repository;
@@ -24,6 +25,7 @@ public class When_asked_to_convert_excel_worksheets_to_DTO
private IRepository _excelRepository;
private IClassGenerator _classGenerator;
private IAssemblyGenerator _assemblyGenerator;
+ private IFileConfiguration _fileConfiguration;
private IExcelToDTOMapper _excelToDtoMapper;
private List<string> _excelFiles;
@@ -37,11 +39,12 @@ public void SetUp()
_excelRepository = MockRepository.GenerateMock<IRepository>();
_classGenerator = MockRepository.GenerateMock<IClassGenerator>();
_assemblyGenerator = MockRepository.GenerateMock<IAssemblyGenerator>();
- _excelToDtoMapper = new ExcelToDTOMapper(_excelRepository, _classGenerator, _assemblyGenerator);
+ _fileConfiguration = MockRepository.GenerateMock<IFileConfiguration>();
+ _excelToDtoMapper = new ExcelToDTOMapper(_excelRepository, _classGenerator, _assemblyGenerator, _fileConfiguration);
_excelFiles = new List<string>
{
- "TestExcel"
+ "TestExcel.xls"
};
_workSheetNames = new List<string>
{
@@ -57,9 +60,9 @@ public void Should_create_one_dto_for_each_of_the_worksheet()
{
AddProperties();
- _excelRepository.Expect(x => x.GetWorkSheetNames("")).IgnoreArguments().Return(_workSheetNames);
- _excelRepository.Expect(x => x.GetClassAttributes("", "")).IgnoreArguments().Return(_classAttributes1);
- _excelRepository.Expect(x => x.GetClassAttributes("", "")).IgnoreArguments().Return(_classAttributes2);
+ _excelRepository.Expect(x => x.GetWorkSheetNames()).IgnoreArguments().Return(_workSheetNames);
+ _excelRepository.Expect(x => x.GetClassAttributes("")).IgnoreArguments().Return(_classAttributes1);
+ _excelRepository.Expect(x => x.GetClassAttributes("")).IgnoreArguments().Return(_classAttributes2);
_classGenerator.Expect(x => x.Create(null)).IgnoreArguments();
_assemblyGenerator.Expect(x => x.Compile(null, null)).IgnoreArguments().Return(true);
@@ -69,9 +72,9 @@ public void Should_create_one_dto_for_each_of_the_worksheet()
[Test]
public void Should_not_create_dto_if_there_are_no_properties()
{
- _excelRepository.Expect(x => x.GetWorkSheetNames("")).IgnoreArguments().Return(_workSheetNames);
- _excelRepository.Expect(x => x.GetClassAttributes("", "")).IgnoreArguments().Return(_classAttributes1);
- _excelRepository.Expect(x => x.GetClassAttributes("", "")).IgnoreArguments().Return(_classAttributes2);
+ _excelRepository.Expect(x => x.GetWorkSheetNames()).IgnoreArguments().Return(_workSheetNames);
+ _excelRepository.Expect(x => x.GetClassAttributes("")).IgnoreArguments().Return(_classAttributes1);
+ _excelRepository.Expect(x => x.GetClassAttributes("")).IgnoreArguments().Return(_classAttributes2);
_classGenerator.Expect(x => x.Create(_classAttributes1)).IgnoreArguments();
_assemblyGenerator.Expect(x => x.Compile(null, null)).IgnoreArguments().Return(true);
@@ -83,9 +86,9 @@ public void Should_not_create_an_assembly_if_the_compile_fails()
{
AddProperties();
- _excelRepository.Expect(x => x.GetWorkSheetNames("")).IgnoreArguments().Return(_workSheetNames);
- _excelRepository.Expect(x => x.GetClassAttributes("", _workSheetNames[0])).IgnoreArguments().Return(_classAttributes1);
- _excelRepository.Expect(x => x.GetClassAttributes("", _workSheetNames[0])).IgnoreArguments().Return(_classAttributes2);
+ _excelRepository.Expect(x => x.GetWorkSheetNames()).IgnoreArguments().Return(_workSheetNames);
+ _excelRepository.Expect(x => x.GetClassAttributes(_workSheetNames[0])).IgnoreArguments().Return(_classAttributes1);
+ _excelRepository.Expect(x => x.GetClassAttributes(_workSheetNames[0])).IgnoreArguments().Return(_classAttributes2);
_classGenerator.Expect(x => x.Create(null)).IgnoreArguments();
_assemblyGenerator.Expect(x => x.Compile(null, null)).IgnoreArguments().Return(false);
@@ -117,14 +120,17 @@ public void SetUp()
[TearDown]
public void TearDown()
{
- File.Delete(_assemblyName);
-
FileInfo[] files = GetCurrentDirectoryCSFiles();
foreach (var file in files)
{
File.Delete(file.Name);
}
+
+ //if (Directory.Exists(TestData.LogsDirectory))
+ //{
+ // Directory.Delete(TestData.LogsDirectory, true);
+ //}
}
private static FileInfo[] GetCurrentDirectoryCSFiles()
@@ -137,13 +143,57 @@ public void Should_create_an_assembly_of_dto_corresponding_to_worksheets_in_the_
{
List<string> excelFiles = new List<string>
{
- TestData.UsersXlsx
+ "Test.xlsx"
};
- Assert.IsTrue(_excelToDtoMapper.Run(TestData.AssemblyName, excelFiles));
+ Assert.IsTrue(_excelToDtoMapper.Run(TestData.AssemblyName, excelFiles));
Assert.IsTrue(File.Exists(_assemblyName));
Assert.IsTrue(GetCurrentDirectoryCSFiles().Length > 0);
}
+
+ [Test]
+ public void Should_create_an_assembly_of_dto_corresponding_to_worksheets_in_the_excel_with_given_namespace_appended_to_filename()
+ {
+ List<string> excelFiles = new List<string>
+ {
+ TestData.UsersXlsx
+ };
+ bool assemblyCompiled = _excelToDtoMapper.Run(TestData.AssemblyName, excelFiles);
+
+ if (!assemblyCompiled)
+ {
+ Assert.Fail("Assembly failed to compile");
+ }
+ Assembly assembly = Assembly.LoadFile(Path.GetFullPath(_assemblyName));
+ Type[] types = assembly.GetTypes();
+ Assert.AreEqual(TestData.AssemblyName + "." + "UsersXlsx", types[0].Namespace);
+ }
+
+ [Test]
+ public void Should_create_an_assembly_of_dto_with_identical_classes_in_two_different_namespaces()
+ {
+ List<string> excelFiles = new List<string>
+ {
+ TestData.UsersXls,
+ TestData.UsersXlsx
+ };
+ bool assemblyCompiled = _excelToDtoMapper.Run(TestData.AssemblyName, excelFiles);
+
+ if (!assemblyCompiled)
+ {
+ Assert.Fail("Assembly failed to compile");
+ }
+ Assembly assembly = Assembly.LoadFile(Path.GetFullPath(_assemblyName));
+ Type[] types = assembly.GetTypes();
+
+ Console.WriteLine(types.Length);
+ Console.WriteLine(types[0].Name);
+ Console.WriteLine(types[1].Name);
+ Console.WriteLine(types[2].Name);
+ Assert.IsTrue(types.Length == 2);
+ Assert.AreEqual(TestData.AssemblyName + "." + "UsersXlsx", types[0].Namespace);
+ Assert.AreEqual(TestData.AssemblyName + "." + "UsersXls", types[1].Namespace);
+ }
}
}
}
@@ -16,22 +16,22 @@ public class When_asked_for_a_connection
{
private string _file;
private IConnectionString _connectionString;
- private IConnection _connection;
+ private IConnectionBuilder _connectionBuilder;
[SetUp]
public void SetUp()
{
_file = TestData.UsersXlsx;
_connectionString = MockRepository.GenerateMock<IConnectionString>();
- _connection = new global::ExcelMapper.Repository.Connection.Connection(_connectionString);
+ _connectionBuilder = new global::ExcelMapper.Repository.Connection.ConnectionBuilder(_connectionString);
}
[Test]
public void Should_open_a_new_OleDbConnection()
{
_connectionString.Expect(x => x.Get(_file)).Return(TestData.UsersXlsConnectionString);
- using (OleDbConnection connection = _connection.GetConnection(_file))
+ using (OleDbConnection connection = _connectionBuilder.GetConnection(_file))
{
Assert.IsInstanceOfType(typeof(OleDbConnection), connection);
Assert.AreEqual(ConnectionState.Open, connection.State);
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
+using ExcelMapper.Configuration;
using ExcelMapper.Repository;
using ExcelMapper.Repository.Connection;
using ExcelMapper.Tests.DTO;
@@ -20,6 +21,7 @@ public class ExcelRepositoryTestsBase
{
private IConnectionString _connectionString;
protected IRepository _excelRepository;
+ protected IFileConfiguration _fileConfiguration;
protected string _xlsxFile;
protected string _xlsFile;
@@ -29,7 +31,8 @@ public class ExcelRepositoryTestsBase
public void SetUp()
{
_connectionString = MockRepository.GenerateMock<IConnectionString>();
- _excelRepository = new ExcelRepository(new ExcelMapper.Repository.Connection.Connection(_connectionString));
+ _fileConfiguration = MockRepository.GenerateMock<IFileConfiguration>();
+ _excelRepository = new ExcelRepository(new ConnectionBuilder(_connectionString), _fileConfiguration);
_xlsxFile = TestData.UsersXlsx;
_xlsFile = TestData.UsersXls;
@@ -46,7 +49,8 @@ public class When_given_an_Excel_File : ExcelRepositoryTestsBase
[Test]
public void Should_give_the_list_of_WorkSheets_in_the_excel()
{
- List<string> workSheets = _excelRepository.GetWorkSheetNames(_xlsxFile).ToList();
+ _fileConfiguration.Expect(x => x.FileName).Return(_xlsxFile);
+ List<string> workSheets = _excelRepository.GetWorkSheetNames().ToList();
Assert.IsTrue(workSheets.Count == 3);
Assert.IsTrue(workSheets.Exists(x => x.Equals(String.Format("{0}$", _workSheetName))));
}
@@ -58,7 +62,8 @@ public class When_given_a_WorkSheet : ExcelRepositoryTestsBase
[Test]
public void Should_return_Class_Properties_object_that_includes_all_the_properties_in_the_class()
{
- ClassAttributes classAttributes = _excelRepository.GetClassAttributes(_xlsxFile, String.Format("{0}$", _workSheetName));
+ _fileConfiguration.Expect(x => x.FileName).Return(_xlsxFile);
+ ClassAttributes classAttributes = _excelRepository.GetClassAttributes(String.Format("{0}$", _workSheetName));
Assert.IsNotNull(classAttributes);
Assert.AreEqual(_workSheetName, classAttributes.Name);
Assert.IsTrue(classAttributes.Properties.Count == 4);
@@ -71,8 +76,9 @@ public class When_given_a_excel_file_name_and_worksheet_name : ExcelRepositoryTe
[Test]
public void Should_map_the_excel_columns_to_the_given_dto_object()
{
+ _fileConfiguration.Expect(x => x.FileName).Return(_xlsxFile);
User expectedUser = TestData.GetUsers(_xlsxFile, _workSheetName).FirstOrDefault();
- User actualUser = _excelRepository.Get<User>(_xlsxFile, _workSheetName).FirstOrDefault();
+ User actualUser = _excelRepository.Get<User>(_workSheetName).FirstOrDefault();
Assert.IsNotNull(actualUser);
@@ -85,17 +91,19 @@ public void Should_map_the_excel_columns_to_the_given_dto_object()
[Test]
public void Should_return_dto_objects_for_each_row_in_the_Xlsx_worksheet()
{
+ _fileConfiguration.Expect(x => x.FileName).Return(_xlsxFile);
List<User> expectedCourts = TestData.GetUsers(_xlsxFile, _workSheetName).ToList();
- List<User> actualCourts = _excelRepository.Get<User>(_xlsxFile, _workSheetName).ToList();
+ List<User> actualCourts = _excelRepository.Get<User>(_workSheetName).ToList();
Assert.IsNotNull(actualCourts);
Assert.AreEqual(expectedCourts.Count, actualCourts.Count);
}
[Test]
public void Should_return_dto_objects_for_each_row_in_the_Xls_worksheet()
{
+ _fileConfiguration.Expect(x => x.FileName).Return(_xlsFile);
List<User> expectedSuits = TestData.GetUsers(_xlsFile, _workSheetName).ToList();
- List<User> actualSuits = _excelRepository.Get<User>(_xlsFile, _workSheetName).ToList();
+ List<User> actualSuits = _excelRepository.Get<User>(_workSheetName).ToList();
Assert.IsNotNull(actualSuits);
Assert.AreEqual(expectedSuits.Count, actualSuits.Count);
}
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<log4net>
+ <appender name="Console" type="log4net.Appender.ConsoleAppender">
+ <layout type="log4net.Layout.PatternLayout">
+ <conversionPattern value="%5level [%thread](%file:%line) - %message%newline" />
+ </layout>
+ </appender>
+ <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
+ <file value="Logs/RunTimeCodeGenerator.log" />
+ <appendToFile value="true" />
+ <maximumFileSize value="1000KB" />
+ <maxSizeRollBackups value="10" />
+ <layout type="log4net.Layout.PatternLayout">
+ <conversionPattern value="%date %level %thread %logger - %message%newline" />
+ </layout>
+ </appender>
+ <root>
+ <level value="WARN" />
+ <!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
+ <appender-ref ref="Console" />
+ <appender-ref ref="RollingFile" />
+ </root>
+</log4net>
@@ -10,15 +10,16 @@ namespace ExcelMapper.Tests
{
public class TestData
{
- public static string UsersXlsx = @"Excel\Users.xlsx";
- public static string UsersXls = @"Excel\Users.xls";
- public static string UsersXlsxConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Excel\\Users.xlsx;Extended Properties=\"Excel 12.0 Xml;HDR=YES;\"";
- public static string UsersXlsConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Excel\\Users.xls;Extended Properties=\"Excel 8.0;HDR=YES;\"";
+ public static string UsersXlsx = @"Excel\UsersXlsx.xlsx";
+ public static string UsersXls = @"Excel\UsersXls.xls";
+ public static string UsersXlsxConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Excel\\UsersXlsx.xlsx;Extended Properties=\"Excel 12.0 Xml;HDR=YES;\"";
+ public static string UsersXlsConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Excel\\UsersXls.xls;Extended Properties=\"Excel 8.0;HDR=YES;\"";
public static string AssemblyName = "TestAssembly";
+ public static string LogsDirectory = "Logs";
public static IEnumerable<User> GetUsers(string file, string workSheet)
{
- using (OleDbConnection connection = new Connection(new ConnectionString()).GetConnection(file))
+ using (OleDbConnection connection = new ConnectionBuilder(new ConnectionString()).GetConnection(file))
{
using (OleDbCommand command = connection.CreateCommand())
{
@@ -10,7 +10,9 @@ public ExcelMapperRegistry()
{
ForRequestedType<IRepository>()
.TheDefaultIsConcreteType<ExcelRepository>();
-
+ ForRequestedType<IFileConfiguration>()
+ .AsSingletons()
+ .TheDefaultIsConcreteType<FileConfiguration>();
Scan(s =>
{
s.AssemblyContainingType<ExcelMapperRegistry>();
@@ -0,0 +1,12 @@
+namespace ExcelMapper.Configuration
+{
+ public interface IFileConfiguration
+ {
+ string FileName { get; set; }
+ }
+
+ public class FileConfiguration : IFileConfiguration
+ {
+ public string FileName { get; set; }
+ }
+}
@@ -71,14 +71,15 @@
<ItemGroup>
<Compile Include="Configuration\BootStrapper.cs" />
<Compile Include="Configuration\ExcelMapperRegistry.cs" />
+ <Compile Include="Configuration\FileConfiguration.cs" />
<Compile Include="Configuration\StructureMapServiceLocator.cs" />
<Compile Include="Configuration\ExcelMapperServiceLocator.cs" />
<Compile Include="IExcelToDTOMapper.cs" />
<Compile Include="ExcelToDTOMapper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Repository\Connection\Connection.cs" />
+ <Compile Include="Repository\Connection\ConnectionBuilder.cs" />
<Compile Include="Repository\Connection\ConnectionString.cs" />
- <Compile Include="Repository\Connection\IConnection.cs" />
+ <Compile Include="Repository\Connection\IConnectionBuilder.cs" />
<Compile Include="Repository\Connection\IConnectionString.cs" />
<Compile Include="Repository\ExcelRepository.cs" />
<Compile Include="Repository\Extensions\DataReaderExtensions.cs" />
@@ -90,6 +91,9 @@
<Name>RunTimeCodeGenerator</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <WCFMetadata Include="Service References\" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Oops, something went wrong.

0 comments on commit c22cb93

Please sign in to comment.