Permalink
Browse files

Moved Class File Generation and Assembly Generation to a new project …

…RunTimeCodeGeneration, as I am using this piece in one of my projects.Move FileSystemService to BuildDTOsFromExcel project as it is only needed in that project. Added methods to ClassFileGeneration. Added log4net logging for AssemblyGeneration. Logging is only limited to Assembly Generation.
  • Loading branch information...
1 parent 6d4c71d commit fc45d9a85f76c21a53a792120443dc3304d2e27b @shashankshetty shashankshetty committed Jul 2, 2009
Showing with 29,887 additions and 543 deletions.
  1. +22 −3 ExcelMapper.build
  2. BIN lib/log4net.dll
  3. +28,655 −0 lib/log4net.xml
  4. +28 −0 src/BuildDTOsFromExcel.Tests/App.config
  5. +21 −1 src/BuildDTOsFromExcel.Tests/BuildDTOsFromExcel.Tests.csproj
  6. +43 −0 src/BuildDTOsFromExcel.Tests/EngineTests.cs
  7. +1 −3 src/BuildDTOsFromExcel.Tests/ExtensionTests.cs
  8. +2 −2 src/BuildDTOsFromExcel.Tests/{ → FileService}/FileParserTests.cs
  9. +6 −27 src/{ExcelMapper.Tests/Service → BuildDTOsFromExcel.Tests}/FileService/FileSystemServiceTests.cs
  10. +1 −0 src/BuildDTOsFromExcel.Tests/TestDirectory/File1.txt
  11. +1 −0 src/BuildDTOsFromExcel.Tests/TestDirectory/File2.txt
  12. BIN src/BuildDTOsFromExcel.Tests/TestDirectory/Users.xlsx
  13. +8 −2 src/BuildDTOsFromExcel/BuildDTOsFromExcel.csproj
  14. +13 −13 src/BuildDTOsFromExcel/Engine.cs
  15. +2 −4 src/BuildDTOsFromExcel/Extensions.cs
  16. +1 −3 src/BuildDTOsFromExcel/{ → FileService}/FileParser.cs
  17. +1 −9 src/{ExcelMapper/Service → BuildDTOsFromExcel}/FileService/FileSystemService.cs
  18. +1 −1 src/BuildDTOsFromExcel/{ → FileService}/IFileParser.cs
  19. +1 −2 src/{ExcelMapper/Service → BuildDTOsFromExcel}/FileService/IFileSystemService.cs
  20. +18 −1 src/BuildDTOsFromExcel/Program.cs
  21. +28 −0 src/ExcelMapper.Tests/App.config
  22. +5 −4 src/ExcelMapper.Tests/ExcelMapper.Tests.csproj
  23. +37 −54 src/ExcelMapper.Tests/ExcelToDTOMapperTests.cs
  24. +7 −7 src/ExcelMapper.Tests/Repository/ExcelRepositoryTests.cs
  25. +0 −84 src/ExcelMapper.Tests/Service/AssemblyGeneratorTests.cs
  26. +0 −44 src/ExcelMapper.Tests/Service/ClassFileGeneratorTests.cs
  27. +1 −2 src/ExcelMapper.Tests/TestData.cs
  28. +16 −0 src/ExcelMapper.sln
  29. +7 −1 src/ExcelMapper/Configuration/BootStrapper.cs
  30. +0 −3 src/ExcelMapper/Configuration/ExcelMapperRegistry.cs
  31. +0 −34 src/ExcelMapper/DTO/ClassProperties.cs
  32. +0 −8 src/ExcelMapper/DefaultSettings.cs
  33. +6 −12 src/ExcelMapper/ExcelMapper.csproj
  34. +11 −10 src/ExcelMapper/ExcelToDTOMapper.cs
  35. +8 −7 src/ExcelMapper/Repository/ExcelRepository.cs
  36. +2 −2 src/ExcelMapper/Repository/IRepository.cs
  37. +0 −59 src/ExcelMapper/Service/AssemblyGenerator.cs
  38. +0 −39 src/ExcelMapper/Service/ClassFileGenerator.cs
  39. +0 −12 src/ExcelMapper/Service/ClassGenerator.cs
  40. +0 −44 src/ExcelMapper/Service/FileService/FileWriter.cs
  41. +0 −13 src/ExcelMapper/Service/FileService/IFileWriter.cs
  42. +0 −9 src/ExcelMapper/Service/IAssemblyGenerator.cs
  43. +0 −9 src/ExcelMapper/Service/IClassGenerator.cs
  44. +28 −0 src/RunTimeCodeGenerator.Tests/App.config
  45. +81 −0 src/RunTimeCodeGenerator.Tests/AssemblyGeneration/AssemblyGeneratorTests.cs
  46. +111 −0 src/RunTimeCodeGenerator.Tests/ClassGeneration/ClassFileGeneratorTests.cs
  47. +11 −12 ...eService/FileWriterTests.cs → RunTimeCodeGenerator.Tests/ClassGeneration/ClassFileWriterTests.cs}
  48. +14 −0 src/RunTimeCodeGenerator.Tests/ClassGeneration/ClassWithMethods.cs
  49. +7 −0 src/RunTimeCodeGenerator.Tests/ClassGeneration/ClassWithProperties.cs
  50. +36 −0 src/RunTimeCodeGenerator.Tests/Properties/AssemblyInfo.cs
  51. +85 −0 src/RunTimeCodeGenerator.Tests/RunTimeCodeGenerator.Tests.csproj
  52. +11 −0 src/RunTimeCodeGenerator.Tests/TestData.cs
  53. +28 −0 src/RunTimeCodeGenerator/App.config
  54. +3 −3 ...Mapper/DTO/AssemblyProperties.cs → RunTimeCodeGenerator/AssemblyGeneration/AssemblyAttributes.cs}
  55. +54 −0 src/RunTimeCodeGenerator/AssemblyGeneration/AssemblyGenerator.cs
  56. +7 −0 src/RunTimeCodeGenerator/AssemblyGeneration/IAssemblyGenerator.cs
  57. +27 −0 src/RunTimeCodeGenerator/BootStrapper.cs
  58. +16 −0 src/RunTimeCodeGenerator/ClassGeneration/AccessLevel.cs
  59. +41 −0 src/RunTimeCodeGenerator/ClassGeneration/ClassAttributes.cs
  60. +118 −0 src/RunTimeCodeGenerator/ClassGeneration/ClassFileGenerator.cs
  61. +52 −0 src/RunTimeCodeGenerator/ClassGeneration/ClassFileWriter.cs
  62. +10 −0 src/RunTimeCodeGenerator/ClassGeneration/ClassGenerator.cs
  63. +12 −0 src/RunTimeCodeGenerator/ClassGeneration/IClassFileWriter.cs
  64. +7 −0 src/RunTimeCodeGenerator/ClassGeneration/IClassGenerator.cs
  65. +18 −0 src/RunTimeCodeGenerator/ClassGeneration/Method.cs
  66. +18 −0 src/RunTimeCodeGenerator/ClassGeneration/Property.cs
  67. +36 −0 src/RunTimeCodeGenerator/Properties/AssemblyInfo.cs
  68. +83 −0 src/RunTimeCodeGenerator/RunTimeCodeGenerator.csproj
  69. +20 −0 src/RunTimeCodeGenerator/RunTimeCodeGeneratorRegistry.cs
View
@@ -26,6 +26,11 @@
<echo message="Copying artifacts to build directory"/>
<copy todir="${build.dir}" overwrite="true">
+ <fileset basedir="src\RunTimeCodeGenerator\bin">
+ <include name="*.*" />
+ </fileset>
+ </copy>
+ <copy todir="${build.dir}" overwrite="true">
<fileset basedir="src\ExcelMapper\bin\x86">
<include name="*.*" />
</fileset>
@@ -37,6 +42,12 @@
</copy>
<copy todir="${build.dir}" overwrite="true">
+ <fileset basedir="src\RunTimeCodeGenerator.Tests\bin\Debug">
+ <include name="*" />
+ <include name="**\*.*" />
+ </fileset>
+ </copy>
+ <copy todir="${build.dir}" overwrite="true">
<fileset basedir="src\ExcelMapper.Tests\bin\x86\Debug">
<include name="*" />
<include name="**\*.*" />
@@ -50,19 +61,27 @@
</copy>
</target>
- <target name="test" depends="run-ExcelMapperTests, run-BuildDTOsFromExcel" />
+ <target name="test" depends="RunTimeCodeGeneratorTests, ExcelMapperTests, BuildDTOsFromExcel" />
<target name="build" depends="compile, test" description="Clean, Compile, run tests" />
- <target name="run-ExcelMapperTests">
+ <target name="RunTimeCodeGeneratorTests">
+ <exec program="${nunit-console.exe}" workingdir="${build.dir}">
+ <arg value="RunTimeCodeGenerator.Tests.dll" />
+ <arg value="/xml:RunTimeCodeGeneratorTests.xml" />
+ <arg value="/nologo" />
+ </exec>
+ </target>
+
+ <target name="ExcelMapperTests">
<exec program="${nunit-console.exe}" workingdir="${build.dir}">
<arg value="ExcelMapper.Tests.dll" />
<arg value="/xml:ExcelMapperTests.xml" />
<arg value="/nologo" />
</exec>
</target>
- <target name="run-BuildDTOsFromExcel">
+ <target name="BuildDTOsFromExcel">
<exec program="${nunit-console.exe}" workingdir="${build.dir}">
<arg value="BuildDTOsFromExcel.Tests.dll" />
<arg value="/xml:BuildDTOsFromExcelTests.xml" />
View
Binary file not shown.
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <configSections>
+ <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
+ </configSections>
+ <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>
+</configuration>
@@ -32,6 +32,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\Microsoft.Practices.ServiceLocation.dll</HintPath>
+ </Reference>
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nunit.framework.dll</HintPath>
@@ -54,8 +58,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="FileParserTests.cs" />
+ <Compile Include="EngineTests.cs" />
+ <Compile Include="FileService\FileParserTests.cs" />
<Compile Include="ExtensionTests.cs" />
+ <Compile Include="FileService\FileSystemServiceTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@@ -68,6 +74,20 @@
<Name>ExcelMapper</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <Content Include="TestDirectory\File1.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="TestDirectory\File2.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ <None Include="TestDirectory\Users.xlsx">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ </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.
@@ -0,0 +1,43 @@
+using BuildDTOsFromExcel.FileService;
+
+using ExcelMapper;
+using ExcelMapper.Configuration;
+
+using Microsoft.Practices.ServiceLocation;
+
+using NUnit.Framework;
+
+namespace BuildDTOsFromExcel.Tests
+{
+ public class EngineTests
+ {
+ [TestFixture]
+ public class When_given_a_list_of_excel_files
+ {
+ private IEngine _engine;
+
+ [SetUp]
+ public void SetUp()
+ {
+ ExcelMapperServiceLocator.SetUp();
+ _engine = new Engine(new FileParser(new FileSystemService()), ServiceLocator.Current.GetInstance<IExcelToDTOMapper>());
+ }
+
+ [Test]
+ public void Should_create_class_files_for_each_tab_and_write_a_success_message_if_excelmapper_run_is_success()
+ {
+ string[] args = new[] { "TestDirectory\\Users.xlsx" };
+
+ Assert.AreEqual(DefaultSettings.SuccessMessage, _engine.Run(args));
+ }
+
+ [Test]
+ public void Should_write_an_error_message_if_the_excelmapper_fails()
+ {
+ string[] args = new[] { "TestDirectory\\User.xlsx" };
+
+ Assert.AreEqual(DefaultSettings.ErrorMessage, _engine.Run(args));
+ }
+ }
+ }
+}
@@ -1,7 +1,5 @@
using System.Collections.Generic;
-using ExcelMapper;
-
using NUnit.Framework;
namespace BuildDTOsFromExcel.Tests
@@ -24,7 +22,7 @@ public void Should_return_the_default_assembly_name_it_if_it_exists_in_the_array
{
string[] args = new[] { "file1", "file2" };
string assemblyName = args.GetAssemblyName();
- Assert.AreEqual(DefaultSettings.Assembly, assemblyName);
+ Assert.AreEqual(DefaultSettings.AssemblyName, assemblyName);
}
}
@@ -1,13 +1,13 @@
using System.Collections.Generic;
using System.IO;
-using ExcelMapper.Service.FileService;
+using BuildDTOsFromExcel.FileService;
using NUnit.Framework;
using Rhino.Mocks;
-namespace BuildDTOsFromExcel.Tests
+namespace BuildDTOsFromExcel.Tests.FileService
{
public class FileParserTests
{
@@ -1,20 +1,20 @@
using System;
-using System.IO;
using System.Linq;
-using ExcelMapper.Service.FileService;
+using BuildDTOsFromExcel.FileService;
using NUnit.Framework;
-namespace ExcelMapper.Tests.Service.FileService
+namespace BuildDTOsFromExcel.Tests.FileService
{
public class FileSystemServiceTests
{
[TestFixture]
public class When_given_a_directory
{
private IFileSystemService _fileSystemService;
- private const string SearchPattern = "*.xlsx";
+ private const string Directory = "TestDirectory";
+ private const string SearchPattern = "*.txt";
[SetUp]
public void SetUp()
@@ -27,11 +27,11 @@ public void Should_return_files_in_current_working_directory_if_directory_name_i
{
Assert.IsTrue(_fileSystemService.GetFiles(null, SearchPattern).ToList().Count > 0);
}
-
+
[Test]
public void Should_give_the_list_of_files_within_the_directory()
{
- Assert.IsTrue(_fileSystemService.GetFiles(TestData.ExcelDirectory, SearchPattern).ToList().Count > 0);
+ Assert.IsTrue(_fileSystemService.GetFiles(Directory, SearchPattern).ToList().Count > 0);
}
}
@@ -62,26 +62,5 @@ public void Should_return_the_directory_filename_combination_path()
Assert.AreEqual(String.Format("{0}\\{1}", _directoryName, _fileName), _fileSystemService.GetFilePath(_fileName, _directoryName));
}
}
-
- [TestFixture]
- public class When_asked_to_delete_a_file
- {
- private IFileSystemService _fileSystemService;
- private const string FileName = "TestFile";
-
- [SetUp]
- public void SetUp()
- {
- File.Create(FileName).Close();
- _fileSystemService = new FileSystemService();
- }
-
- [Test]
- public void Should_delete_the_file()
- {
- _fileSystemService.Delete(FileName);
- Assert.IsFalse(File.Exists(FileName));
- }
- }
}
}
@@ -0,0 +1 @@
+
@@ -0,0 +1 @@
+
Binary file not shown.
@@ -36,6 +36,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
+ <Reference Include="StructureMap, Version=2.5.3.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\StructureMap.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -52,9 +56,11 @@
<ItemGroup>
<Compile Include="Engine.cs" />
<Compile Include="Extensions.cs" />
- <Compile Include="FileParser.cs" />
+ <Compile Include="FileService\FileParser.cs" />
+ <Compile Include="FileService\FileSystemService.cs" />
+ <Compile Include="FileService\IFileSystemService.cs" />
<Compile Include="IEngine.cs" />
- <Compile Include="IFileParser.cs" />
+ <Compile Include="FileService\IFileParser.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@@ -1,25 +1,25 @@
-using System;
-using System.Collections.Generic;
+using BuildDTOsFromExcel.FileService;
using ExcelMapper;
-using ExcelMapper.Configuration;
-using ExcelMapper.Service.FileService;
-
-using Microsoft.Practices.ServiceLocation;
namespace BuildDTOsFromExcel
{
public class Engine : IEngine
{
- public string Run(string[] args)
+ private readonly IFileParser _parser;
+ private readonly IExcelToDTOMapper _excelToDTOMapper;
+
+ public Engine(IFileParser parser, IExcelToDTOMapper excelToDTOMapper)
{
- ExcelMapperServiceLocator.SetUp();
+ _parser = parser;
+ _excelToDTOMapper = excelToDTOMapper;
+ }
- string assemblyName = args.GetAssemblyName();
- List<string> files = new FileParser(ServiceLocator.Current.GetInstance<IFileSystemService>()).Parse(args.GetFiles());
- return ServiceLocator.Current.GetInstance<IExcelToDTOMapper>().Run(assemblyName, files)
- ? ("Successfully created the assembly")
- : (String.Format("Error in processing. See {0} for details", DefaultSettings.LogFile));
+ public string Run(string[] args)
+ {
+ return _excelToDTOMapper.Run(args.GetAssemblyName(), _parser.Parse(args.GetFiles()))
+ ? DefaultSettings.SuccessMessage
+ : DefaultSettings.ErrorMessage;
}
}
}
@@ -2,13 +2,11 @@
using System.Collections.Generic;
using System.Linq;
-using ExcelMapper;
-
namespace BuildDTOsFromExcel
{
public static class Extensions
{
- const string AssemblyPredicate = "/Assembly:";
+ private const string AssemblyPredicate = "/Assembly:";
public static List<string> GetFiles(this string[] args)
{
@@ -18,7 +16,7 @@ public static List<string> GetFiles(this string[] args)
public static string GetAssemblyName(this string[] args)
{
string assembly = Array.Find(args, arg => arg.Contains(AssemblyPredicate));
- return !String.IsNullOrEmpty(assembly) ? assembly.Replace(AssemblyPredicate, String.Empty) : DefaultSettings.Assembly;
+ return !String.IsNullOrEmpty(assembly) ? assembly.Replace(AssemblyPredicate, String.Empty) : DefaultSettings.AssemblyName;
}
}
}
@@ -2,9 +2,7 @@
using System.Collections.Generic;
using System.IO;
-using ExcelMapper.Service.FileService;
-
-namespace BuildDTOsFromExcel
+namespace BuildDTOsFromExcel.FileService
{
public class FileParser : IFileParser
{
Oops, something went wrong.

0 comments on commit fc45d9a

Please sign in to comment.