Пример #1
0
        public void Test_CreateClassDef_AddOnePropDef()
        {
            //---------------Set up test pack-------------------
            string assemblyName = "A" + RandomValueGenerator.GetRandomString();
            string className    = "C" + RandomValueGenerator.GetRandomString();
            string propertyName = "P" + RandomValueGenerator.GetRandomString();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var      classDefBuilder = new ClassDefBuilder();
            ClassDef classDef        = classDefBuilder.WithAssemblyName(assemblyName).WithClassName(className)
                                       .AddPropDef(new PropDefBuilder()
                                                   .WithPropertyName(propertyName));

            //---------------Test Result -----------------------
            Assert.AreEqual(assemblyName, classDef.AssemblyName);
            Assert.AreEqual(className, classDef.ClassName);
            Assert.IsNotNull(classDef.PropDefcol);
            Assert.AreEqual(1, classDef.PropDefcol.Count());
            Assert.IsNotNull(classDef.PropDefcol[propertyName]);
            Assert.IsNull(classDef.PrimaryKeyDef);
            Assert.IsNull(classDef.KeysCol);
            Assert.IsNull(classDef.RelationshipDefCol);
            Assert.AreEqual(0, classDef.UIDefCol.Count());
        }
        public void Test_CreateClassDef_WithAssemblyClassName()
        {
            //---------------Set up test pack-------------------
            string assemblyName = "A" + RandomValueGenerator.GetRandomString();
            string className = "C" + RandomValueGenerator.GetRandomString();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            ClassDef classDef = new ClassDefBuilder()
                    .WithAssemblyName(assemblyName)
                    .WithClassName(className);
            //---------------Test Result -----------------------
            Assert.AreEqual(assemblyName, classDef.AssemblyName);
            Assert.AreEqual(className, classDef.ClassName);
            Assert.IsNull(classDef.PropDefcol);
            Assert.IsNull(classDef.PrimaryKeyDef);
            Assert.IsNull(classDef.KeysCol);
            Assert.IsNull(classDef.RelationshipDefCol);
            Assert.AreEqual(0, classDef.UIDefCol.Count());
        }
        public void Test_Build_WhenCreatingSingleRelationship_ShouldSetRelationshipDefProps()
        {
            //---------------Set up test pack-------------------
            var classDef = new ClassDefBuilder<Car>()
                .WithPrimaryKey(c => c.VehicleID)
                .WithProperties()
                    .Property(car => car.Make).EndProperty()
                .EndProperties()
                .WithRelationships()
                    .WithSingleRelationship(c => c.SteeringWheel)
                        .WithRelProp("VehicleID", "CarID")
                    .EndSingleRelationship()
                .EndRelationships();

            //---------------Assert Precondition----------------
            //---------------Test Result -----------------------
            IClassDef builtClassDef = classDef.Build();

            var singleRelationshipDef = builtClassDef.GetRelationship("SteeringWheel");
            Assert.AreEqual("SteeringWheel", singleRelationshipDef.RelationshipName);
            Assert.IsTrue(singleRelationshipDef.KeepReferenceToRelatedObject);
            Assert.AreEqual(DeleteParentAction.DoNothing, singleRelationshipDef.DeleteParentAction);
            Assert.AreEqual("Car", singleRelationshipDef.OwningClassName);
            Assert.AreEqual("TestProject.BO", singleRelationshipDef.RelatedObjectAssemblyName);
            Assert.AreEqual("SteeringWheel", singleRelationshipDef.RelatedObjectClassName);
            Assert.AreEqual(1, singleRelationshipDef.RelKeyDef.Count);
            Assert.AreEqual(InsertParentAction.InsertRelationship, singleRelationshipDef.InsertParentAction);
            Assert.AreEqual(RelationshipType.Association, singleRelationshipDef.RelationshipType);
        }