public void Map_WithNoMapperSettings_TheSameTypePropertiesNames_ReturnsMappedObject() { var mapper = _mappingGenerator.Generate <UserBLL, UserPL>(); var actualResult = mapper.Map(_user); Assert.NotNull(actualResult); Assert.IsType <UserPL>(actualResult); Assert.Equal(_user.Id, actualResult.Id); Assert.Equal(_user.FirstName, actualResult.FirstName); Assert.Equal(_user.LastName, actualResult.LastName); Assert.Equal(_user.Age, actualResult.Age); }
public void TestMethod1() { var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Foo, Bar>(); var res = mapper.Map(new Foo()); }
public void Generate() { codeGenerator.Generate(); if (applicationPreferences.IsNhFluent) { nhFluentGenerator.Generate(); } else if (applicationPreferences.IsFluent) { fluentGenerator.Generate(); } else if (applicationPreferences.IsCastle) { castleGenerator.Generate(); } else if (applicationPreferences.IsByCode) { byCodeGenerator.Generate(); } else { mappingGenerator.Generate(); } if (applicationPreferences.GenerateWcfDataContract) { contractGenerator.Generate(); } }
public void Generate(bool writeToFile = true) { codeGenerator.Generate(writeToFile); GeneratedDomainCode = codeGenerator.GeneratedCode; if (applicationPreferences.IsFluent) { fluentGenerator.Generate(writeToFile); GeneratedMapCode = fluentGenerator.GeneratedCode; } else if (applicationPreferences.IsCastle) { castleGenerator.Generate(writeToFile); GeneratedMapCode = castleGenerator.GeneratedCode; } else if (applicationPreferences.IsByCode) { byCodeGenerator.Generate(writeToFile); GeneratedMapCode = byCodeGenerator.GeneratedCode; } else { mappingGenerator.Generate(writeToFile); GeneratedMapCode = mappingGenerator.GeneratedCode; } if (applicationPreferences.GenerateWcfDataContract) { contractGenerator.Generate(writeToFile); } }
protected override bool OnInvoke(IEnumerable <string> extras) { StreamWriter writer = null; try { var outputWriter = string.IsNullOrWhiteSpace(OutputPath) ? Console.Out : (writer = new StreamWriter(OutputPath)); var generator = new MappingGenerator { OverridesPath = OverrideMapping, JavaMappingPath = JavaTypeMapping, IncludeWarnings = !ExcludeWarnings, Verbose = Program.Verbose, }; generator.Generate(AndroidSupportAssembly, AndroidXAssembly, outputWriter); } finally { writer?.Dispose(); } return(true); }
public void TestMapping_MustMapObject_AssertProperties() { var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Source, Destination>(); var expected = new Source() { ArrayField = new[] { 1.1, 2.2, 3.3 }, IntField = 42, ListField = new List <int>() { 1, 2, 3 }, SourceSpecificField = -1, StringField = "string" }; var actual = mapper.Map(expected); Assert.True(expected.ArrayField.SequenceEqual(expected.ArrayField)); //Assert.NotSame(expected.ArrayField, actual.ArrayField); Assert.Equal(expected.IntField, actual.IntField); Assert.Same(expected.ListField, actual.ListField); Assert.Equal(expected.StringField, actual.StringField); Assert.NotEqual(expected.SourceSpecificField, actual.DestinationSpecificField); }
public void CanRunGenerator() { MappingGenerator gen = new MappingGenerator(); gen.Configure(XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("NHibernate.Tool.hbm2net.Tests.Db2hbmConfigTemplate.xml"))); gen.Generate(new StdoutStreamProvider()); }
public void TestNotNull() { MappingGenerator mapGenerator = new MappingGenerator(); Bar bar = mapGenerator.Generate <Foo, Bar>().Map(new Foo()); Assert.IsNotNull(bar); Console.WriteLine(bar); }
public void UserBugNullRererenceWhenSmallIntIsKey() { CreateDbFromSchema("NHibernate.Tool.hbm2net.Tests.Schemas.UserBugNullRererenceWhenSmallIntIsKey.sql"); MappingGenerator gen = new MappingGenerator(); gen.Configure(XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("NHibernate.Tool.hbm2net.Tests.UserBugNullReferenceWhenSmallIntIsAKey.xml"))); gen.Generate(new StdoutStreamProvider()); }
public void TestValueMapping() { MappingGenerator mapGenerator = new MappingGenerator(); Bar bar = mapGenerator.Generate <Foo, Bar>().CopyParam(f => f.FooIntProp, b => b.BarIntProp).Map(new Foo()); Assert.IsTrue(bar.BarIntProp == 1234); Console.WriteLine(bar); Console.WriteLine(bar.BarIntProp); }
public void TestRefMapping() { MappingGenerator mapGenerator = new MappingGenerator(); Bar bar = mapGenerator.Generate <Foo, Bar>().CopyParam(f => f.FooStringProp, b => b.BarStringProp).Map(new Foo()); Assert.IsTrue(bar.BarStringProp == "test"); Console.WriteLine(bar); Console.WriteLine(bar.BarStringProp); }
static void Main() { var mapGenerator = new MappingGenerator(); var foo = new Foo { A = 5, B = "Alla", C = 64 }; var mapper = mapGenerator.Generate <Foo, Bar>(); var res = mapper.Map(foo); }
public void AdventureWorksIntegrationTest() { MappingGenerator gen = new MappingGenerator(); gen.Configure(XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("NHibernate.Tool.hbm2net.Tests.Db2hbmTestAdventureWorks.xml"))); internalStreams.Clear(); // clear all generated files... gen.Generate(this); foreach (var stream in internalStreams) { Console.WriteLine(stream.Key + ":"); Console.WriteLine(stream.Value); } }
public void MapPropertiesTest() { var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Foo, Bar>(); var foo = new Foo { Value1 = "Foo1", Value2 = "Foo2" }; var bar = mapper.Map(foo); Assert.AreEqual(foo.Value1, bar.Value1); Assert.AreEqual(foo.Value2, bar.Value2); Assert.AreEqual(foo.Value3, bar.Value3); }
public void MapSourceToDestination() { SourceType srcTypeInstance = new SourceType("Ivan", 21, true, new SomeType()); MappingGenerator mappingGenerator = new MappingGenerator(); Mapper <SourceType, DestinationType> mapper = mappingGenerator.Generate <SourceType, DestinationType>(); DestinationType destTypeInstance = mapper.Map(srcTypeInstance); Assert.IsNotNull(destTypeInstance); Assert.AreEqual(srcTypeInstance.Name, destTypeInstance.Name); Assert.AreNotEqual(srcTypeInstance.IsActive, destTypeInstance.IsNotActive); Assert.AreNotEqual(srcTypeInstance.Id, destTypeInstance.Id); Assert.AreEqual(srcTypeInstance.Title, destTypeInstance.Title); }
public void MapDestinationToSource() { DestinationType destTypeInstance = new DestinationType("John", 1, true, new SomeType()); MappingGenerator mappingGenerator = new MappingGenerator(); Mapper <DestinationType, SourceType> mapper = mappingGenerator.Generate <DestinationType, SourceType>(); SourceType srcTypeInstance = mapper.Map(destTypeInstance); Assert.IsNotNull(srcTypeInstance); Assert.AreEqual(destTypeInstance.Name, srcTypeInstance.Name); Assert.AreNotEqual(destTypeInstance.IsNotActive, srcTypeInstance.IsActive); Assert.AreNotEqual(destTypeInstance.Id, srcTypeInstance.Id); Assert.AreEqual(destTypeInstance.Title, srcTypeInstance.Title); }
public void Map() { var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Foo, Bar>(); Foo foo = new Foo() { HowOldYouOnTracker = 2, DoYouLikeWorkOnAProject = false, Why = "Special thanks to Dan Paladino, to new method of work and to great help desk team.. oh sorry, ignore desk team.." }; Bar bar = mapper.Map(foo); Assert.AreEqual(foo.HowOldYouOnTracker, bar.HowOldYouOnTracker); Assert.AreEqual(foo.DoYouLikeWorkOnAProject, bar.DoYouLikeWorkOnAProject); Assert.AreEqual(foo.Why, bar.Why); }
public void Map() { MappingGenerator mapGenerator = new MappingGenerator(); Mapper <Foo, Bar> mapper = mapGenerator.Generate <Foo, Bar>(); Foo foo = new Foo { Name = "Jesse", Age = 23 }; Bar bar = mapper.Map(foo); Assert.AreEqual(foo.Name, bar.Name); Assert.AreEqual(foo.Age, bar.Age); }
public void MappingIsNullBeerItemTest() { var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Food, Bar>(); var food = new Food { Id = 1, Name = null }; var res = mapper.Map(food); Assert.IsNotNull(res); Assert.IsInstanceOfType(res, typeof(Bar)); Assert.AreEqual(food.Id, res.Id); Assert.AreEqual(food.Name, res.Name); Assert.IsNull(food.BeerItem); }
public void Run() { Console.Clear(); Console.WriteLine("task 2"); var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Foo, Bar>(); var source = new Foo() { Name = "alex", Value = 5 }; var res = mapper.Map(source); Console.WriteLine($"{source.GetType().Name}: Name = {source.Name}; Value = {source.Value}"); Console.WriteLine($"{res.GetType().Name}: Name = {res.Name}; Value = {res.Value}"); Console.ReadKey(); }
static void Main(string[] args) { var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <CarEntity, CarModel>(); var carnEntity = new CarEntity { Id = 56, Name = "Chevy Camaro 1968" }; CarModel res = mapper.Map(carnEntity); Console.WriteLine($"Id: {res.Id} Name: { res.Name}"); Console.ReadLine(); }
public void JustProperties() { string hbm = "JustProperties.hbm.xml"; TestHelper.BuildAssemblyFromHbm("NHibernate.DomainModel", hbm); MappingGenerator gen = new MappingGenerator(); gen.Configure(XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("NHibernate.Tool.hbm2net.Tests.Db2hbmTest1.xml"))); string schema = GetSchemaForMSSql(hbm); Console.WriteLine("Generated Schema:"); Console.Write(schema); internalStreams.Clear(); // clear all generated files... gen.Generate(this); Assert.IsTrue(internalStreams.ContainsKey("Simple")); CheckXmlMapping(hbm, "Simple"); }
public void TestMethod3() { Dictionary <string, string> mapping = new Dictionary <string, string> { ["FirstName"] = "Name", ["LastName"] = "Surname" }; var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Foo, Bar>(new Foo { FirstName = "Alex", LastName = "Ivanov" }, mapping); var res = mapper.Map(new Foo()); Console.WriteLine(res); }
public void TestMethod1() { // Arrange var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Foo, Bar>(); var foo = new Foo { SomeInt = 1, SomeString = "Some string" }; // Act var res = mapper.Map(foo); // Assert Assert.IsNotNull(res); Assert.IsNotNull(foo); Assert.AreEqual(foo.SomeInt, res.SomeInt); Assert.AreEqual(foo.SomeString, res.SomeString); }
public void Obj_Can_Be_Mapped() { // Arrange var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Foo, Bar>(); // Act var expectedFoo = new Foo { FirstProp = double.MinValue, SecondProp = string.Empty, ThirdProp = new Guid() }; var actualBar = mapper.Map(expectedFoo); // Assert Assert.AreEqual(expectedFoo.FirstProp, actualBar.FirstProp); Assert.AreEqual(expectedFoo.SecondProp, actualBar.SecondProp); Assert.AreEqual(expectedFoo.ThirdProp, actualBar.ThirdProp); Assert.AreEqual(expectedFoo.Get(), actualBar.Get()); }
public void TestMethod1() { var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Foo, Bar>(); var foo = new Foo { Name = "Foo", Description = "Description of Foo", Price = 10.99, Quantity = 100 }; var bar = mapper.Map(foo); Assert.AreEqual(foo.Name, bar.Name); Assert.AreEqual((int)foo.Price, bar.Price); Assert.AreEqual(foo.Quantity, bar.Quantity); }
public void Map_MapsOneClassToAnother() { const int expectedAge = 20; const string expectedName = "Cool Foo"; var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Foo, Bar>(); var result = mapper.Map(new Foo() { Age = expectedAge, IsCool = true, Name = expectedName }); Assert.IsNotNull(result, "Result should not be null!"); Assert.IsInstanceOf <Bar>(result, "Result should be a Bar!"); Assert.AreEqual(expectedAge, result.Age, "Age should be 20!"); Assert.AreEqual(expectedName, result.Name, string.Format("Name should be: '{0}'", expectedName)); }
public void SetCollection() { string hbm = "PropertiesAndSetCollection.hbm.xml"; TestHelper.BuildAssemblyFromHbm("NHibernate.DomainModel4", hbm); MappingGenerator gen = new MappingGenerator(); gen.Configure(XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("NHibernate.Tool.hbm2net.Tests.Db2hbmTest4.xml"))); string schema = GetSchemaForMSSql(hbm); Console.WriteLine("Generated Schema:"); Console.Write(schema); internalStreams.Clear(); // clear all generated files... gen.Generate(this); Assert.IsTrue(internalStreams.ContainsKey("Widget")); Assert.IsTrue(internalStreams.ContainsKey("Child")); Assert.IsFalse(internalStreams.ContainsKey("Item")); Assert.IsFalse(internalStreams.ContainsKey("CompositeItem")); CheckXmlMapping(hbm, "Widget", "Child"); }
public void MappingIsNullStringTest() { var mapGenerator = new MappingGenerator(); var mapper = mapGenerator.Generate <Food, Bar>(); var food = new Food { Id = 1, Name = null, BeerItem = new Beer { Id = 11, Name = "Duvel", Price = 11.1m } }; var res = mapper.Map(food); Assert.IsNotNull(res); Assert.IsInstanceOfType(res, typeof(Bar)); Assert.AreEqual(food.Id, res.Id); Assert.AreEqual(food.Name, res.Name); Assert.IsNotNull(food.BeerItem); Assert.AreEqual(food.BeerItem.Id, res.BeerItem.Id); Assert.AreEqual(food.BeerItem.Price, res.BeerItem.Price); Assert.AreEqual(food.BeerItem.Name, res.BeerItem.Name); }
public static void Main(string[] args) { XmlConfigurator.Configure(); ILog logger = LogManager.GetLogger("db2hbm"); Db2hbmParameters parms = new Db2hbmParameters(args); try { parms.Parse(); MappingGenerator gen = new MappingGenerator(); if (File.Exists(parms.ConfigFile)) { using (var reader = XmlReader.Create(new StreamReader(parms.ConfigFile))) { gen.Configure(reader); } if (!Directory.Exists(parms.OutputDir)) { Directory.CreateDirectory(parms.OutputDir); } using (var sp = new StreamProvider(parms.OutputDir)) { gen.Generate(sp); } } else { throw new FileNotFoundException(parms.ConfigFile); } } catch (NotEnougthParametersException) { System.Console.Error.WriteLine("Use: db2hbm" + parms.GetShortHelp()); System.Console.Error.WriteLine(parms.GetHelp()); } catch (Exception e) { logger.Error("Fatal error", e); } }