public void Map_ShouldBeAbleToResolveDependencyViaContext() { // Arrange var fromObj = new FromObj { Field1 = "Field1" }; var dependencyObj = new DependencyObj { Field2 = 2 }; Mock.Provide(dependencyObj); Mock.Provide((MappingEngine)Mapper.Engine); Mapper.AddProfile(new FromToProfile()); // Act var toObj = Mock.Create <MappingEngineWrapper>().Map <ToObj>(fromObj); // Assert Assert.That(toObj, Is.Not.Null); Assert.That(toObj.Field1, Is.EqualTo(fromObj.Field1)); Assert.That(toObj.Field2, Is.EqualTo(dependencyObj.Field2)); }
public static void WriteFile <T>(string filename, string[] headers, char delimiter, List <T> list, FromObj <T> mapper) { using (FileStream f = new FileStream(filename, FileMode.Create, FileAccess.Write)) { using (StreamWriter s = new StreamWriter(f)) { if (headers != null) { s.WriteLine(string.Join(delimiter.ToString(), headers)); } foreach (var o in list) { List <object> cols = new List <object>(); mapper(o, cols); for (int i = 0; i < cols.Count; i++) { // qoute string if needed -> \" \r \n delim var str = cols[i].ToString(); bool quote = false; if (str.IndexOf('\"') >= 0) { quote = true; str = str.Replace("\"", "\"\""); } if (quote == false && str.IndexOf('\n') >= 0) { quote = true; } if (quote == false && str.IndexOf('\r') >= 0) { quote = true; } if (quote == false && str.IndexOf(delimiter) >= 0) { quote = true; } if (quote) { s.Write("\""); } s.Write(str); if (quote) { s.Write("\""); } if (i < cols.Count - 1) { s.Write(delimiter); } } s.WriteLine(); } s.Flush(); } f.Close(); } }