public async Task write_csv_async_returns_number_of_items_written() { using (var writer = new CsvWriter(new StringWriter())) { writer.WriteRecord("some", "record"); var items = new TestType1[] { new TestType1 { Property1 = "1", Property2 = "2", Property3 = "3" }, new TestType1 { Property1 = "4", Property2 = "5", Property3 = "6" } }; Assert.Equal(2, await items.WriteCsvAsync(writer)); Assert.Equal(2, await items.WriteCsvAsync(writer, false)); } }
public void write_csv_writes_all_public_properties_by_default() { using (var stringWriter = new StringWriter()) using (var writer = new CsvWriter(stringWriter)) { writer.NewLine = "<EOL>"; var items = new TestType1[] { new TestType1 { Property1 = "1", Property2 = "2", Property3 = "3" }, new TestType1 { Property1 = "4", Property2 = "5", Property3 = "6" } }; items.WriteCsv(writer); var result = stringWriter.ToString(); // can't assert exact contents because order of properties is undefined (and changes) Assert.Contains("Property1", result); Assert.Contains("Property2", result); Assert.Contains("1", result); Assert.Contains("2", result); Assert.Contains("4", result); Assert.Contains("5", result); } }
private async Task DatabaseSetUp() { var connection = GetRequiredService <IDbConnectionFactory>() .CreateConnection(); await connection.ExecuteAsync(TestType1.CreateTableScript()); await connection.ExecuteAsync(TestType2.CreateTableScript()); await connection.ExecuteAsync(TestType3.CreateTableScript()); await connection.ExecuteAsync(TestType4.CreateTableScript()); await connection.ExecuteAsync(TestType5.CreateTableScript()); await connection.ExecuteAsync(TestType6.CreateTableScript()); await connection.ExecuteAsync(TestType7.CreateTableScript()); await connection.ExecuteAsync(TestType8.CreateTableScript()); await connection.ExecuteAsync(TestType9.CreateTableScript()); await connection.ExecuteAsync(TestType10.CreateTableScript()); await connection.ExecuteAsync(TestType11.CreateTableScript()); await connection.ExecuteAsync(TestType12.CreateTableScript()); await connection.ExecuteAsync(TestType13.CreateTableScript()); await connection.ExecuteAsync(TestType14.CreateTableScript()); }
public async Task write_csv_async_writes_only_requested_properties_if_specified() { using (var stringWriter = new StringWriter()) using (var writer = new CsvWriter(stringWriter)) { writer.NewLine = "<EOL>"; var items = new TestType1[] { new TestType1 { Property1 = "1", Property2 = "2", Property3 = "3" }, new TestType1 { Property1 = "4", Property2 = "5", Property3 = "6" } }; await items.WriteCsvAsync(writer, true, new string[] { "Property2" }); Assert.Equal("Property2<EOL>2<EOL>5<EOL>", stringWriter.ToString()); } }
private async Task DatabaseTeardown() { var connection = GetRequiredService <IDbConnectionFactory>() .CreateConnection(); await connection.ExecuteAsync(TestType1.DropTableScript()); await connection.ExecuteAsync(TestType2.DropTableScript()); await connection.ExecuteAsync(TestType3.DropTableScript()); await connection.ExecuteAsync(TestType4.DropTableScript()); await connection.ExecuteAsync(TestType5.DropTableScript()); await connection.ExecuteAsync(TestType6.DropTableScript()); await connection.ExecuteAsync(TestType7.DropTableScript()); await connection.ExecuteAsync(TestType8.DropTableScript()); await connection.ExecuteAsync(TestType9.DropTableScript()); await connection.ExecuteAsync(TestType10.DropTableScript()); await connection.ExecuteAsync(TestType11.DropTableScript()); await connection.ExecuteAsync(TestType12.DropTableScript()); await connection.ExecuteAsync(TestType13.DropTableScript()); await connection.ExecuteAsync(TestType14.DropTableScript()); }
public async Task ShouldInsertTestType1() { var connection = GetRequiredService <IDbConnectionFactory>() .CreateConnection(); var givenId = Fixture.Create <long>(); var givenItem = new TestType1 { Id = givenId, Name = Fixture.Create <string>() }; await connection.InsertAsync(givenItem); var items = (await connection .QueryAsync <TestType1>(@"SELECT * FROM TestType1s")) .ToList(); items.Count.Should().Be(1); var retrievedItem = items.First(); givenItem.Id.Should().Be(1); retrievedItem.Id.Should().NotBe(givenId); retrievedItem.Id.Should().Be(1); retrievedItem.Name.Should().Be(givenItem.Name); }
public static TestType1 CreateTestType1(int keyProp, string valueProp) { TestType1 testType1 = new TestType1(); testType1.KeyProp = keyProp; testType1.ValueProp = valueProp; return(testType1); }
public void SetValue() { TestType1 i = new TestType1(); _info.SetValue(i, 4711); int x = (int)_info.GetValue(i); Assert.AreEqual(4711, x); }
static void Main() { TestType1 t1 = new TestType1(); TestType2 t2 = new TestType2(); Console.WriteLine("Attempting generic function on t1 and t2"); OutputThing(t1); OutputThing(t2); Console.WriteLine("Attempting generic function on string 'S'"); OutputThing("S"); Console.WriteLine("Attempting with func<type>(param) syntax - this enforces type checking at compile time as well..."); // ReSharper disable once RedundantTypeArgumentsOfMethod //Note that compiler performs type inference for this line, you cant pass in wrong parameter values. OutputThing <string>("S"); //Console.WriteLine("...and this fails if uncommented..."); //OutputThing<string>(1); Console.WriteLine("The real power of generics"); Console.WriteLine("Here is how c# can use function pointers - using the delegates!"); string[] names = { "Pune", "Mumbai", "Delhi", "Chennai", "London", "Swindon" }; //The line below declares an action target (in c++ terms, its a function pointer). //This action target defines function address our 'Apply' function needs to call. //Notice how this code works without any side effects and without any dependency //on external state maintenance. The 'Apply' function works only based on supplied //parameters, without maintaining any class or module level state variables or //any external resource, etc. If 'Apply' method calls another function directly //this sort of builds a hard bound dependency on that function, instead this method //intentionally takes a delegate (or function pointer) as a parameter, which means //calling code can define target method to be invoked. Action <string> messageTarget = delegate(string s) { PrintOnConsole(s); }; Apply(names, messageTarget); Console.WriteLine("Done!"); Console.ReadKey(); }
public void TestMethod(int parameter1, TestType1 parameter2) { }
public void Invoke() { TestType1 cii = _info.Invoke(new object[] { }) as TestType1; Assert.IsNotNull(cii); }