Beispiel #1
0
        public void Name_Is_Unique(IWCTestData testData)
        {
            var objectSpace       = testData.Application.CreateObjectSpace();
            var templatedTypeInfo = objectSpace.Create <IPersistentTemplatedTypeInfo>();

            templatedTypeInfo.Name = "name";
            var persistentClassInfo = objectSpace.Create <IPersistentClassInfo>();

            persistentClassInfo.Name = "name";

            objectSpace.CommitChanges();
            var usedProperties = nameof(persistentClassInfo.Name);


            Validator.RuleSet.StateOf <RuleObjectExists>(persistentClassInfo, usedProperties)
            .Should()
            .Be(ValidationState.Valid);

            var classInfo = objectSpace.Create <IPersistentClassInfo>();

            classInfo.Name = "name";

            Validator.RuleSet.StateOf <RuleObjectExists>(classInfo, usedProperties)
            .Should()
            .Be(ValidationState.Invalid);
        }
        public void Assmebly_File(IWCTestData testData, Compiler compiler, IPersistentAssemblyInfo assemblyInfo)
        {
            var code = assemblyInfo.GenerateCode();

            var compilerResult = compiler.Compile(code, assemblyInfo.Name);

            compilerResult.AssemblyDefinition.Should().NotBeNull();
        }
Beispiel #3
0
        public void Name_Is_Unique_For_a_Class(IWCTestData testData)
        {
            var objectSpace = testData.Application.CreateObjectSpace();

            NameIsUniqueForAClass <IPersistentCoreTypeMemberInfo>(objectSpace);
            NameIsUniqueForAClass <IPersistentCollectionMemberInfo>(objectSpace);
            NameIsUniqueForAClass <IPersistentReferenceMemberInfo>(objectSpace);
        }
Beispiel #4
0
        public void Automatically_the_Many_part_of_the_association_from_the_one(IWCTestData testData, IPersistentReferenceMemberInfo memberInfo, Compiler compiler)
        {
            throw new NotImplementedException();
//            var assemblyDefinition = CreateAndCheckAssociation(memberInfo, compiler,true);
//
//            var persistentAssociatedMemberInfo = memberInfo.GetAssociation();
//            persistentAssociatedMemberInfo.Should().BeOfType<IPersistentCollectionMemberInfo>();
//            CheckAssociation(persistentAssociatedMemberInfo,assemblyDefinition);
        }
        public void Assembly_Should_Validate_if_file_not_exists(IWCTestData testData,
                                                                IPersistentClassInfo persistentClassInfo, IAssemblyManager assemblyManager)
        {
            persistentClassInfo.PersistentAssemblyInfo.Name += Guid.NewGuid().ToString("N");

            var persistentAssemblyInfos = assemblyManager.ValidateAssemblyInfos();

            persistentAssemblyInfos.Length.Should().Be(1);
        }
        public void Assembly_Should_not_be_Validated_if_already_loaded(IWCTestData testData,
                                                                       IPersistentClassInfo persistentClassInfo, IAssemblyManager assemblyManager)
        {
            persistentClassInfo.PersistentAssemblyInfo.Name += Guid.NewGuid().ToString("n");
            (assemblyManager.LoadAssemblies().ToArray().FirstOrDefault() != null).Should().BeTrue();

            var loadAssemblies = assemblyManager.LoadAssemblies();

            loadAssemblies.Count.Should().Be(0);
        }
        public void Assembly_Should_not_Validate_if_version_equal_to_file_version(IWCTestData testData,
                                                                                  IPersistentClassInfo persistentClassInfo, IAssemblyManager assemblyManager)
        {
            persistentClassInfo.PersistentAssemblyInfo.Revision++;
            persistentClassInfo.PersistentAssemblyInfo.Name += Guid.NewGuid().ToString("n");
            assemblyManager.LoadAssemblies();

            var validAssemblyInfos = assemblyManager.ValidateAssemblyInfos();

            validAssemblyInfos.Length.Should().Be(0);
        }
Beispiel #8
0
        public void Reference_member(IWCTestData testData, IPersistentReferenceMemberInfo memberInfo, Compiler compiler)
        {
            var assemblyInfo = memberInfo.Owner.PersistentAssemblyInfo;
            var code         = assemblyInfo.GenerateCode();

            var compilerResult = compiler.Compile(code, assemblyInfo.Name);

            var propertyDefinitions = compilerResult.AssemblyDefinition.MainModule.Types.SelectMany(definition => definition.Properties);
            var propertyDefinition  = propertyDefinitions.FirstOrDefault(definition => definition.Name == memberInfo.Name);

            propertyDefinition.Should().NotBeNull();
            propertyDefinition?.PropertyType.Name.Should().Be(memberInfo.ReferenceClassInfo.Name);
        }
        public void Aclass(IWCTestData testData, Compiler compiler, IPersistentClassInfo persistentClassInfo)
        {
            var code = persistentClassInfo.GenerateCode();

            var compilerResult = compiler.Compile(code, persistentClassInfo.Name);


            var moduleDefinition = compilerResult.AssemblyDefinition.MainModule;

            moduleDefinition.Types.Any(definition => definition.Name == persistentClassInfo.Name)
            .Should()
            .BeTrue();
        }
Beispiel #10
0
        public void Many_to_many_association(IWCTestData testData, IPersistentCollectionMemberInfo collectionMemberInfo,
                                             IPersistentReferenceMemberInfo referenceMemberInfo, Compiler compiler)
        {
            referenceMemberInfo.CreateAssociation("test");
            collectionMemberInfo.CreateAssociation("test");
            var persistentAssemblyInfo = referenceMemberInfo.Owner.PersistentAssemblyInfo;
            var code = persistentAssemblyInfo.GenerateCode();

            var assemblyDefinition = compiler.Compile(code, persistentAssemblyInfo.Name).AssemblyDefinition;


            CheckAssociation(referenceMemberInfo, assemblyDefinition);
            CheckAssociation(collectionMemberInfo, assemblyDefinition);
        }
Beispiel #11
0
        public void Collection_member(IWCTestData testData, IPersistentCollectionMemberInfo memberInfo, Compiler compiler)
        {
            var assemblyInfo = memberInfo.Owner.PersistentAssemblyInfo;
            var code         = assemblyInfo.GenerateCode();

            var compilerResult = compiler.Compile(code, assemblyInfo.Name);

            var propertyDefinitions = compilerResult.AssemblyDefinition.MainModule.Types.SelectMany(definition => definition.Properties);
            var propertyDefinition  = propertyDefinitions.FirstOrDefault(definition => definition.Name == memberInfo.Name);

            propertyDefinition.Should().NotBeNull();
            propertyDefinition?.PropertyType.ToString().Should().Contain(typeof(XPCollection).FullName);
            propertyDefinition?.PropertyType.ToString().Should().Contain(memberInfo.CollectionClassInfo.Name);
        }
        public void Name_Is_Required(IWCTestData testData)
        {
            var persistentAssemblyInfo = testData.Application.CreateObjectSpace().Create <IPersistentAssemblyInfo>();
            var usedProperties         = nameof(persistentAssemblyInfo.Name);

            Validator.RuleSet.StateOf <RuleRequiredField>(persistentAssemblyInfo, usedProperties)
            .Should()
            .Be(ValidationState.Invalid);

            persistentAssemblyInfo.Name = "name";

            Validator.RuleSet.StateOf <RuleRequiredField>(persistentAssemblyInfo, usedProperties)
            .Should()
            .Be(ValidationState.Valid);
        }
Beispiel #13
0
        private static void NameIsRequired <T>(IWCTestData testData) where T : IPersistentMemberInfo
        {
            var coreTypeMemberInfo = testData.Application.CreateObjectSpace().Create <T>();
            var usedProperties     = nameof(coreTypeMemberInfo.Name);


            Validator.RuleSet.StateOf <RuleRequiredField>(coreTypeMemberInfo, usedProperties)
            .Should()
            .Be(ValidationState.Invalid);
            coreTypeMemberInfo.Name = "name";

            Validator.RuleSet.StateOf <RuleRequiredField>(coreTypeMemberInfo, usedProperties)
            .Should()
            .Be(ValidationState.Valid);
        }
        public void Assemblies_Should_be_loaded_in_memory_if_validation_succeed(IWCTestData testData,
                                                                                IPersistentClassInfo persistentClassInfo, IAssemblyManager assemblyManager)
        {
            persistentClassInfo.PersistentAssemblyInfo.Name += Guid.NewGuid().ToString("N");

            var assemblies = assemblyManager.LoadAssemblies().ToArray();

            assemblies.Length.Should().Be(1);

            var assembly = assemblies.First();

            Path.GetFileNameWithoutExtension(assembly.Location)
            .Should()
            .Be(persistentClassInfo.PersistentAssemblyInfo.Name);
            AppDomain.CurrentDomain.GetAssemblies().Should().Contain(assembly);
        }
        public void Assemblies_that_do_not_need_validation_should_load_in_memory(IWCTestData testData,
                                                                                 IPersistentClassInfo persistentClassInfo, IAssemblyManager assemblyManager, Compiler compiler)
        {
            var persistentAssemblyInfo = persistentClassInfo.PersistentAssemblyInfo;

            compiler.Compile(persistentAssemblyInfo.GenerateCode(), persistentAssemblyInfo.Name);

            var assemblies = assemblyManager.LoadAssemblies().ToArray();

            assemblies.Length.Should().Be(1);

            var assembly = assemblies.First();

            Path.GetFileNameWithoutExtension(assembly.Location)
            .Should()
            .Be(persistentClassInfo.PersistentAssemblyInfo.Name);
            AppDomain.CurrentDomain.GetAssemblies().Should().Contain(assembly);
        }
Beispiel #16
0
        public void Parent_MapInheritance_required_When_Merging(IWCTestData testData)
        {
            var objectSpace = testData.Application.CreateObjectSpace();
            var classInfo   = objectSpace.Create <IPersistentClassInfo>();

            classInfo.MergedObjectFullName = GetType().FullName;
            classInfo.BaseType             = null;

            var message = RuleClassInfoMerge.ErrorMessage;

            Validator.RuleSet.StateOf(classInfo, message).Should().Be(ValidationState.Invalid);

            var mapInheritanceAttribute = objectSpace.CreateObject <PersistentMapInheritanceAttribute>();

            classInfo.TypeAttributes.Add(mapInheritanceAttribute);
            Validator.RuleSet.StateOf(classInfo, message).Should().Be(ValidationState.Valid);


            mapInheritanceAttribute.MapInheritanceType = MapInheritanceType.OwnTable;
            Validator.RuleSet.StateOf(classInfo, message).Should().Be(ValidationState.Invalid);
        }
        public void Name_Is_Unique(IWCTestData testData)
        {
            var objectSpace            = testData.Application.CreateObjectSpace();
            var persistentAssemblyInfo = objectSpace.Create <IPersistentAssemblyInfo>();

            persistentAssemblyInfo.Name = "name";
            var assemblyInfo = objectSpace.Create <IPersistentAssemblyInfo>();

            objectSpace.CommitChanges();
            var usedProperties = nameof(persistentAssemblyInfo.Name);


            Validator.RuleSet.StateOf <RuleUniqueValue>(persistentAssemblyInfo, usedProperties)
            .Should()
            .Be(ValidationState.Valid);

            assemblyInfo.Name = "name";

            Validator.RuleSet.StateOf <RuleUniqueValue>(persistentAssemblyInfo, usedProperties)
            .Should()
            .Be(ValidationState.Invalid);
        }
Beispiel #18
0
        public void BaseClass_Required_When_Merging_ToExisting_Type(IWCTestData testData)
        {
            var objectSpace         = testData.Application.CreateObjectSpace();
            var persistentClassInfo = objectSpace.CreateObject <PersistentClassInfo>();

            persistentClassInfo.MergedObjectType = GetType();
            persistentClassInfo.BaseType         = null;
            var basetype      = nameof(persistentClassInfo.BaseType);
            var baseclassinfo = nameof(persistentClassInfo.BaseClassInfo);
            var ruleSet       = Validator.RuleSet;

            ruleSet.StateOf <RuleRequiredField>(persistentClassInfo, basetype).Should().Be(ValidationState.Invalid);
            ruleSet.StateOf <RuleRequiredField>(persistentClassInfo, baseclassinfo).Should().Be(ValidationState.Invalid);

            persistentClassInfo.BaseType = GetType();
            ruleSet.StateOf <RuleRequiredField>(persistentClassInfo, basetype).Should().Be(ValidationState.Valid);
            ruleSet.StateOf <RuleRequiredField>(persistentClassInfo, baseclassinfo).Should().Be(ValidationState.Skipped);

            persistentClassInfo.BaseType      = null;
            persistentClassInfo.BaseClassInfo = objectSpace.CreateObject <PersistentClassInfo>();
            ruleSet.StateOf <RuleRequiredField>(persistentClassInfo, basetype).Should().Be(ValidationState.Skipped);
            ruleSet.StateOf <RuleRequiredField>(persistentClassInfo, baseclassinfo).Should().Be(ValidationState.Valid);
        }
Beispiel #19
0
 public void Name_Is_Required(IWCTestData testData)
 {
     NameIsRequired <IPersistentCoreTypeMemberInfo>(testData);
     NameIsRequired <IPersistentReferenceMemberInfo>(testData);
     NameIsRequired <IPersistentCollectionMemberInfo>(testData);
 }
Beispiel #20
0
 public void ManyToOne_association(IWCTestData testData, IPersistentCollectionMemberInfo memberInfo, Compiler compiler)
 {
     CreateAndCheckAssociation(memberInfo, compiler);
 }
Beispiel #21
0
 public void OneToMany_association(IWCTestData testData, IPersistentReferenceMemberInfo memberInfo, Compiler compiler)
 {
     CreateAndCheckAssociation(memberInfo, compiler);
 }
        public void Validation_Failures_Should_be_saved_in_the_Persistent_Assembly_info(IWCTestData testData,
                                                                                        IPersistentClassInfo persistentClassInfo, IAssemblyManager assemblyManager)
        {
            persistentClassInfo.CodeTemplateInfo.TemplateInfo.TemplateCode = "invalid";

            assemblyManager.ValidateAssemblyInfos();

            persistentClassInfo.PersistentAssemblyInfo.Errors.Should()
            .Contain("A namespace cannot directly contain members such as fields or methods");
        }
        public void Only_Persistent_Assemblies_That_Will_be_Compiled_Should_Be_Validated(IWCTestData testData,
                                                                                         IList <IPersistentAssemblyInfo> persistentAssemblyInfos,
                                                                                         IAssemblyManager assemblyManager)
        {
            persistentAssemblyInfos.First().DoNotCompile = true;

            var validatorResults = assemblyManager.ValidateAssemblyInfos();

            validatorResults.Length.Should().Be(2);
        }
        public void Assembly_Should_Validate_if_version_different_to_file_version(int revision, IWCTestData testData,
                                                                                  IPersistentAssemblyInfo assemblyInfo, IAssemblyManager assemblyManager)
        {
            assemblyInfo.Name    += Guid.NewGuid().ToString("n");
            assemblyInfo.Revision = 1;
            assemblyManager.CodeValidator.Compiler.Compile(assemblyInfo.GenerateCode(), assemblyInfo.Name, new byte[0]);

            assemblyInfo.Revision = revision;
            var validAssemblyInfos = assemblyManager.ValidateAssemblyInfos();

            validAssemblyInfos.Length.Should().Be(1);
        }