Esempio n. 1
0
        public void InsertSqlScript_Should_Return_0_When_HeaderFileds_And_DataTableRows_Are_Null()
        {
            // Arrange
            GenerateFiles generateFiles = new GenerateFiles(this.config, this.spreadsheet, this.fileSystem, this.outputWriter);

            Header    header    = new Header();
            DataTable dataTable = new DataTable();

            // Act
            int result = generateFiles.InsertSqlScript(header, dataTable);

            // Assert
            result.Should().Be(0);
        }
Esempio n. 2
0
        public void InsertSqlScript_Should_Return_0_When_DataTable_Is_Null()
        {
            // Arrange
            GenerateFiles generateFiles = new GenerateFiles(this.config, this.spreadsheet, this.fileSystem, this.outputWriter);

            Header header = new Header
            {
                Fields = new List <Field>()
            };
            DataTable dataTable = null;

            // Act
            int result = generateFiles.InsertSqlScript(header, dataTable);

            // Assert
            result.Should().Be(0);
        }
Esempio n. 3
0
        public void InsertSqlScript_Should_Return_Oracle_Insert_Script()
        {
            // Arrange
            this.configMock.Setup(c => c.DatabaseVendor).Returns(DatabaseEnum.Vendor.Oracle);
            this.configMock.Setup(c => c.OutTablename).Returns("person");
            GenerateFiles generateFiles = new GenerateFiles(this.config, this.spreadsheet, this.fileSystem, this.outputWriter);

            List <string> lines = new List <string>();

            this.fileSystemMock.Setup(o => o.WriteAllLines(It.IsAny <string>(), It.IsAny <List <string> >(), It.IsAny <Encoding>())).Callback((string path, List <string> contents, Encoding encoding) => lines = contents);

            DataTable dataTable = GetPeopleTest1();

            Header header = new Header
            {
                Fields = new List <Field>
                {
                    new Field
                    {
                        Column = 0,
                        Text   = "LastName",
                        Length = 10,
                        Row    = 0,
                        Type   = Enum.DatabaseEnum.TypeField.Text
                    },
                    new Field
                    {
                        Column = 1,
                        Text   = "FirstName",
                        Length = 20,
                        Row    = 0,
                        Type   = Enum.DatabaseEnum.TypeField.Text
                    },
                    new Field
                    {
                        Column = 2,
                        Text   = "Name",
                        Length = 4,
                        Row    = 0,
                        Type   = Enum.DatabaseEnum.TypeField.Text
                    },
                    new Field
                    {
                        Column = 3,
                        Text   = "DateOfBirth",
                        Length = 20,
                        Row    = 0,
                        Type   = Enum.DatabaseEnum.TypeField.Date
                    },
                    new Field
                    {
                        Column = 4,
                        Text   = "Salary",
                        Length = 30,
                        Row    = 0,
                        Type   = Enum.DatabaseEnum.TypeField.Number
                    },
                    new Field
                    {
                        Column = 5,
                        Extra  = false,
                        Text   = "id",
                        Length = 9,
                        Row    = 0,
                        Type   = Enum.DatabaseEnum.TypeField.Number
                    },
                    new Field
                    {
                        Column = 6,
                        Extra  = true,
                        Text   = "ExternalNumber",
                        Length = 9,
                        Row    = 0,
                        Type   = Enum.DatabaseEnum.TypeField.Number
                    },
                    new Field
                    {
                        Column = 7,
                        Extra  = true,
                        Text   = "Message",
                        Length = 2000,
                        Row    = 0,
                        Type   = Enum.DatabaseEnum.TypeField.Text
                    }
                }
            };

            // Act
            int result = generateFiles.InsertSqlScript(header, dataTable);

            // Assert
            result.Should().Be(2);
            lines.Count.Should().BeGreaterThan(0);
            lines[0].Should().Be("INSERT INTO person (lastname, firstname, name, dateofbirth, salary, id, externalnumber, message) VALUES ('abcdefghijk', 'abc', 'aa', '15-1-2001', '10000000000', 1, null, null);");
            lines[1].Should().Be("INSERT INTO person (lastname, firstname, name, dateofbirth, salary, id, externalnumber, message) VALUES ('abc', 'abcdefghijklmnopqrstw', 'aaa', '15-10-1901', '1000000000000000000000', 2, null, null);");
            lines[2].Should().Be("");
            lines[3].Should().Be($"{Constant.Key.COMMIT};");
        }