コード例 #1
0
        public async Task write_csv_async_uses_object_to_string_converter_if_specified()
        {
            using (var stringWriter = new StringWriter())
                using (var writer = new CsvWriter(stringWriter))
                {
                    writer.NewLine = "<EOL>";

                    var items = new TestType2[]
                    {
                        new TestType2
                        {
                            Property1 = "1",
                            Property2 = 2d,
                            Property3 = 3,
                            Property4 = 4m
                        },
                        new TestType2
                        {
                            Property1 = "5",
                            Property2 = 6d,
                            Property3 = 7,
                            Property4 = 8m
                        }
                    };

                    await items.WriteCsvAsync(writer, true, new string[] { "Property1", "Property2" }, o => o.ToString() + "_SUFFIX");

                    Assert.Equal("Property1,Property2<EOL>1_SUFFIX,2_SUFFIX<EOL>5_SUFFIX,6_SUFFIX<EOL>", stringWriter.ToString());
                }
        }
コード例 #2
0
        public async Task ShouldInsertTestType2()
        {
            var connection = GetRequiredService <IDbConnectionFactory>()
                             .CreateConnection();
            var initialId = Guid.NewGuid().ToString();
            var item      = new TestType2
            {
                Id   = initialId,
                Name = Guid.NewGuid().ToString()
            };

            await connection.InsertAsync(item);

            item.Id.Should().Be(initialId);

            var retrievedItems = (await connection
                                  .QueryAsync <TestType2>("select * from TestType2s"))
                                 .ToList();

            retrievedItems.Count.Should().Be(1);
            var retrievedItem = retrievedItems.First();

            retrievedItem.Id.Should().Be(item.Id);
            retrievedItem.Name.Should().Be(item.Name);
        }
コード例 #3
0
        public void write_csv_writes_converts_property_values_to_strings()
        {
            using (var stringWriter = new StringWriter())
                using (var writer = new CsvWriter(stringWriter))
                {
                    writer.NewLine = "<EOL>";

                    var items = new TestType2[]
                    {
                        new TestType2
                        {
                            Property1 = "1",
                            Property2 = 2d,
                            Property3 = 3,
                            Property4 = 4m
                        },
                        new TestType2
                        {
                            Property1 = "5",
                            Property2 = 6d,
                            Property3 = 7,
                            Property4 = 8m
                        }
                    };

                    items.WriteCsv(writer);
                    Assert.Equal("Property1,Property2,Property3,Property4<EOL>1,2,3,4<EOL>5,6,7,8<EOL>", stringWriter.ToString());
                }
        }
コード例 #4
0
        public async Task write_csv_async_writes_converts_null_property_values_to_empty_strings()
        {
            using (var stringWriter = new StringWriter())
                using (var writer = new CsvWriter(stringWriter))
                {
                    writer.NewLine = "<EOL>";

                    var items = new TestType2[]
                    {
                        new TestType2
                        {
                            Property1 = null,
                            Property2 = 2d,
                            Property3 = 3,
                            Property4 = 4m
                        },
                        new TestType2
                        {
                            Property1 = null,
                            Property2 = 6d,
                            Property3 = 7,
                            Property4 = null
                        }
                    };

                    await items.WriteCsvAsync(writer);

                    Assert.Equal("Property1,Property2,Property3,Property4<EOL>,2,3,4<EOL>,6,7,<EOL>", stringWriter.ToString());
                }
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        public static TestType2 CreateTestType2(int keyProp, string valueProp, global::Event.String.Int.ComplexType complexValueProp)
        {
            TestType2 testType2 = new TestType2();

            testType2.KeyProp   = keyProp;
            testType2.ValueProp = valueProp;
            if ((complexValueProp == null))
            {
                throw new global::System.ArgumentNullException("complexValueProp");
            }
            testType2.ComplexValueProp = complexValueProp;
            return(testType2);
        }
コード例 #8
0
        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();
        }
コード例 #9
0
 public void AddToSet2(TestType2 testType2)
 {
     base.AddObject("set2", testType2);
 }
コード例 #10
0
 public virtual void AddToSet2(TestType2 testType2)
 {
     base.AddObject("Set2", testType2);
 }
コード例 #11
0
        public async Task write_csv_async_uses_object_to_string_converter_if_specified()
        {
            using (var stringWriter = new StringWriter())
            using (var writer = new CsvWriter(stringWriter))
            {
                writer.NewLine = "<EOL>";

                var items = new TestType2[]
                {
                    new TestType2
                    {
                        Property1 = "1",
                        Property2 = 2d,
                        Property3 = 3,
                        Property4 = 4m
                    },
                    new TestType2
                    {
                        Property1 = "5",
                        Property2 = 6d,
                        Property3 = 7,
                        Property4 = 8m
                    }
                };

                await items.WriteCsvAsync(writer, true, new string[] { "Property1", "Property2" }, o => o.ToString() + "_SUFFIX");
                Assert.Equal("Property1,Property2<EOL>1_SUFFIX,2_SUFFIX<EOL>5_SUFFIX,6_SUFFIX<EOL>", stringWriter.ToString());
            }
        }
コード例 #12
0
        public async Task write_csv_async_writes_converts_null_property_values_to_empty_strings()
        {
            using (var stringWriter = new StringWriter())
            using (var writer = new CsvWriter(stringWriter))
            {
                writer.NewLine = "<EOL>";

                var items = new TestType2[]
                {
                    new TestType2
                    {
                        Property1 = null,
                        Property2 = 2d,
                        Property3 = 3,
                        Property4 = 4m
                    },
                    new TestType2
                    {
                        Property1 = null,
                        Property2 = 6d,
                        Property3 = 7,
                        Property4 = null
                    }
                };

                await items.WriteCsvAsync(writer);
                Assert.Equal("Property1,Property2,Property3,Property4<EOL>,2,3,4<EOL>,6,7,<EOL>", stringWriter.ToString());
            }
        }
コード例 #13
0
        public void write_csv_writes_converts_property_values_to_strings()
        {
            using (var stringWriter = new StringWriter())
            using (var writer = new CsvWriter(stringWriter))
            {
                writer.NewLine = "<EOL>";

                var items = new TestType2[]
                {
                    new TestType2
                    {
                        Property1 = "1",
                        Property2 = 2d,
                        Property3 = 3,
                        Property4 = 4m
                    },
                    new TestType2
                    {
                        Property1 = "5",
                        Property2 = 6d,
                        Property3 = 7,
                        Property4 = 8m
                    }
                };

                items.WriteCsv(writer);
                Assert.Equal("Property1,Property2,Property3,Property4<EOL>1,2,3,4<EOL>5,6,7,8<EOL>", stringWriter.ToString());
            }
        }