Пример #1
0
        public void categoryname_column_in_table()
        {
            // Arrange
            IColumns columns = new CategoryColumns();
            ITable table = new CategoryTable(columns, null);

            // Act
            IColumn categoryColumn = (CategoryNameColumn)table.Columns[1];
            string name = categoryColumn.Name;

            // Assert
            Assert.AreEqual("CategoryName", name);
        }
Пример #2
0
        public void create_complete_mapper_for_category_table()
        {
            // Arrange
            IColumns columns = new CategoryColumns();
            columns.Add(new DateTimeColumn());

            ITable table = new CategoryTable(columns, null);
            string expected = "model.Id = (int)entity.Id;" + Environment.NewLine;
            expected += "model.CategoryName = entity.CategoryName;" + Environment.NewLine;
            expected += "model.rowversion = entity.Rowversion.AsBase64String();" + Environment.NewLine;
            expected += "model.DateCreated = entity.DateCreated;" + Environment.NewLine;

            // Act
            string actual = string.Empty;
            foreach (IColumn c in table.Columns)
            {
                if (c.IsInPrimaryKey)
                {
                    actual += "model." + c.Name + " = (int)entity." + c.Name + ";" + Environment.NewLine;
                }
                else if (c.Name.ToLower() == "rowversion")
                {
                    actual += "model." + c.Name.ToLower() + " = entity." + c.Name + ".AsBase64String();" + Environment.NewLine;
                }
                else
                {
                    actual += "model." + c.Name + " = entity." + c.Name;
                    if (c.LanguageType.ToLower() != "string")
                    {
                        if (c.IsNullable)
                        {
                            actual += ".HasValue ? (" + c.LanguageType + ")entity." + c.Name + " : default(" + c.LanguageType + ")";
                        }
                    }
                    actual += ";" + Environment.NewLine;
                }
            }

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        public void dataannotationswriter_test()
        {
            // Arrange
            IColumns columns = new CategoryColumns();
            columns.Add(new IdentityColumn());
            columns.Add(new DateTimeColumn());
            columns.Add(new CategoryNameColumn());
            columns.Add(new RowversionColumn());

            ITable table = new CategoryTable(columns, null);

            RequestContext context = new RequestContext();
            context.Zeus = new TempZeusContext();

            // Act
            ICodeWriter writer = new DataAnnotationsWriter(context, table);
            writer.Write();
            string actual = writer.Read;

            Console.WriteLine(actual);
        }
Пример #4
0
        public void display_output_using_output_dot_text()
        {
            // Arrange
            IColumns columns = new CategoryColumns();
            ITable table = new CategoryTable(columns, null);

            // Act
            foreach (IColumn column in table.Columns)
            {
                Console.WriteLine(column.Name + " - Type: " + column.LanguageType + " - IsPrimaryKey: " + column.IsInPrimaryKey + " - IsNullable: " + column.IsNullable);
            }

            // Assert
        }
Пример #5
0
        public void loop_through_all_columns_in_CategoryTable()
        {
            // Arrange
            IColumns columns = new CategoryColumns();
            ITable table = new CategoryTable(columns, null);

            // Act
            foreach (IColumn column in table.Columns)
            {
                Console.WriteLine(column.Name + " - Type: " + column.LanguageType + " - IsPrimaryKey: " + column.IsInPrimaryKey + " - IsNullable: " + column.IsNullable);
            }
        }
Пример #6
0
        public void create_mapper_property_mapping_for_identity_column()
        {
            // Arrange
            IColumns columns = new CategoryColumns();
            ITable table = new CategoryTable(columns, null);
            string expected = "model.Id = (int)entity.Id;";

            // Act
            string actual = string.Empty;
            foreach (IColumn c in table.Columns)
            {
                if (c.IsInPrimaryKey)
                {
                    actual = "model." + c.Name + " = (int)entity." + c.Name + ";";
                }
            }

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #7
0
        public void create_mapper_property_for_string_column()
        {
            // Arrange
            IColumns columns = new CategoryColumns();
            ITable table = new CategoryTable(columns, null);
            string expected = "model.CategoryName = entity.CategoryName";

            // Act
            string actual = string.Empty;
            foreach (IColumn c in table.Columns)
            {
                if (c.LanguageType == "string")
                {
                    actual = "model." + c.Name + " = entity." + c.Name;
                }
            }

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public void create_mapper_property_for_rowversion_column()
        {
            // Arrange
            IColumns columns = new CategoryColumns();
            ITable table = new CategoryTable(columns, null);
            string expected = "model.rowversion = entity.Rowversion.AsBase64String();";

            // Act
            string actual = string.Empty;
            foreach (IColumn c in table.Columns)
            {
                if (c.Name.ToLower() == "rowversion")
                {
                    actual = "model." + c.Name.ToLower() + " = entity." + c.Name + ".AsBase64String();";
                }
            }

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #9
0
        public void create_mapper_property_for_nullable_int_column()
        {
            // Arrange
            IColumns columns = new CategoryColumns();
            columns.Add(new ViewCountIntNullableColumn());

            ITable table = new CategoryTable(columns, null);
            string expected = "model.ViewCount = entity.ViewCount.HasValue ? (int)entity.ViewCount : default(int);";

            // Act
            string actual = string.Empty;
            foreach (IColumn c in table.Columns)
            {
                actual = "model." + c.Name + " = entity." + c.Name;
                if (c.LanguageType.ToLower() != "string")
                {
                    if (c.IsNullable)
                    {
                        actual += ".HasValue ? (" + c.LanguageType + ")entity." + c.Name + " : default(" + c.LanguageType + ")";
                    }
                }
                actual += ";";
            }

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #10
0
        public void create_mapper_property_for_nullable_datetime_column()
        {
            // Arrange
            IColumns columns = new CategoryColumns();
            columns.Add(new DateTimeNullableColumn());

            ITable table = new CategoryTable(columns, null);
            string expected = "model.DateCreated = entity.DateCreated.HasValue ? (DateTime)entity.DateCreated : default(DateTime)";

            // Act
            string actual = string.Empty;
            foreach (IColumn c in table.Columns)
            {
                if (c.LanguageType.ToLower() != "string")
                {
                    if (c.IsNullable)
                    {
                        actual = "model." + c.Name + " = entity." + c.Name + ".HasValue ? (DateTime)entity.DateCreated : default(DateTime)";
                    }
                }
            }

            // Assert
            Assert.AreEqual(expected, actual);
        }