public void ValidateDomainServicesTaskRunsSuccessfully() { ValidateDomainServicesTask task = CodeGenHelper.CreateValidateDomainServicesTask("VDST1"); Assert.IsTrue(task.Execute(), "Validation should have completed without error"); }
public void CodeGenComplexTypes_ValidInvokeMethodSignature_Succeeds() { Type[] domainServices = new Type[] { typeof(ComplexTypes_TestService_ComplexMethodSignatures), }; string[] codeContains = new string[] { // named updates on the entity "public void CustomUpdateHomeAddress(Address newAddress)", "public void UpdateHomeAddress(Address newAddress)", // named updates on the domain context "public void CustomUpdateHomeAddress(ComplexType_Parent parent, Address newAddress)", "public void UpdateHomeAddress(ComplexType_Parent parent, Address newAddress)", // invokes "public InvokeOperation AppendMoreAddresses(IEnumerable<Address> addresses, Action<InvokeOperation> callback, object userState)", "public InvokeOperation AppendMoreAddresses(IEnumerable<Address> addresses)", "public InvokeOperation Bar(IEnumerable<Address> addresses, Action<InvokeOperation> callback, object userState)", "public InvokeOperation Bar(IEnumerable<Address> addresses)", "public InvokeOperation<IEnumerable<Address>> Foo(ContactInfo contact, Action<InvokeOperation<IEnumerable<Address>>> callback, object userState)", "public InvokeOperation<IEnumerable<Address>> Foo(ContactInfo contact)", "public InvokeOperation<IEnumerable<Phone>> GetAllPhoneNumbers(ContactInfo contact, Action<InvokeOperation<IEnumerable<Phone>>> callback, object userState)", "public InvokeOperation<IEnumerable<Phone>> GetAllPhoneNumbers(ContactInfo contact)", }; CodeGenHelper.BaseSuccessTest(domainServices, codeContains, null); }
public void CodeGen_SharedEntity_EntityShapingWithEvenInheritance_Succeeds() { Type[] domainServices = new Type[] { typeof(SharedScenarios_InheritanceShaping_ExposeXDomainService), typeof(SharedScenarios_InheritanceShaping_ExposeX2DomainService), }; // Generated classes and enumerables for X and Z exist // Z inherits from X directly string[] codeContains = new string[] { "public partial class SharedScenarios_InheritanceShaping_X : Entity", "public sealed partial class SharedScenarios_InheritanceShaping_Z : SharedScenarios_InheritanceShaping_X", "public EntitySet<SharedScenarios_InheritanceShaping_X> SharedScenarios_InheritanceShaping_Xes", }; // Z's entity set does not exist // Y does not exist string[] codeNotContains = new string[] { "EntitySet<SharedScenarios_InheritanceShaping_Z>", "SharedScenarios_InheritanceShaping_Y", }; CodeGenHelper.BaseSuccessTest(domainServices, codeContains, codeNotContains); }
public void SharedSourceFiles_Methods() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths("SFT", out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); List <string> sourceFiles = CodeGenHelper.ClientClassLibSourceFiles(clientProjectPath); ConsoleLogger logger = new ConsoleLogger(); FilenameMap filenameMap = new FilenameMap(); using (SourceFileLocationService locationService = new SourceFileLocationService(new[] { new PdbSourceFileProviderFactory(/*symbolSearchPath*/ null, logger) }, filenameMap)) { SharedSourceFiles ssf = new SharedSourceFiles(locationService, filenameMap, sourceFiles); int[] fileIds = ssf.GetSharedFileIds(CodeMemberKey.CreateMethodKey(typeof(TestValidator).GetMethod("IsValid"))); Assert.IsNotNull(fileIds, "Expected TestValidator.IsValid to have non-null file ID's because it is shared"); Assert.AreEqual(1, fileIds.Length, "Expected TestValidator.IsValid to be found in exactly one file"); Assert.IsTrue(filenameMap[fileIds[0]].Contains("TestValidator.linked.cs"), "Expected TestValidator.IsValid to be in TestValidator.linked.cs"); fileIds = ssf.GetSharedFileIds(CodeMemberKey.CreateMethodKey(typeof(TestEntity).GetMethod("ServerAndClientMethod"))); Assert.IsNotNull(fileIds, "Expected TestEntity.ServerAndClientMethod to have non-null file ID's because it is shared"); Assert.AreEqual(1, fileIds.Length, "Expected TestEntity.ServerAndClientMethod to be found in exactly one file"); Assert.IsTrue(filenameMap[fileIds[0]].Contains("TestEntity.linked.cs"), "Expected TestEntity.ServerAndClientMethod to be in TestEntity.linked.cs"); fileIds = ssf.GetSharedFileIds(CodeMemberKey.CreateMethodKey(typeof(TestEntity).GetMethod("ServerMethod"))); Assert.IsNull(fileIds, "Expected TestEntity.ServerMethod to have null file ids"); fileIds = ssf.GetSharedFileIds(CodeMemberKey.CreateMethodKey(typeof(TestValidatorServer).GetMethod("IsValid"))); Assert.IsNull(fileIds, "Expected TestValidatorServer.IsValid to have null file ids"); } }
public void CodeGenComplexTypes_ComplexTypes_Have_DataMember_And_Display() { // Case 1: Only entity exposes complex type property Type[] domainServices = new Type[] { typeof(CodeGenComplexTypes_Attributes_OnEntity), }; string[] codeContains = new string[] { @"[DataMember()] [Display(AutoGenerateField=false)] public CodeGenComplexTypes_Attributes_ComplexType ComplexType", @"[DataMember()] [Display(AutoGenerateField=false)] public IEnumerable<CodeGenComplexTypes_Attributes_ComplexType> ComplexTypes", }; CodeGenHelper.BaseSuccessTest(domainServices, codeContains, null); // Case 2: Only complex type exposes complex type property domainServices = new Type[] { typeof(CodeGenComplexTypes_Attributes_OnComplexType), }; CodeGenHelper.BaseSuccessTest(domainServices, codeContains, null); }
public void SharedAssembliesManaged_Methods() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths("", out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); List <string> assemblies = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true); ConsoleLogger logger = new ConsoleLogger(); using (var sa = CreatedSharedAssembliesService(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger)) { var sharedMethodLocation = GetSharedMethodLocation(sa, typeof(TestValidator), "IsValid", new[] { typeof(TestEntity), typeof(ValidationContext) }); Assert.IsNotNull(sharedMethodLocation, "Expected TestValidator.IsValid to be shared"); Assert.IsTrue(sharedMethodLocation.Contains("ClientClassLib"), "Expected to find method in client class lib"); sharedMethodLocation = GetSharedMethodLocation(sa, typeof(TestEntity), "ServerAndClientMethod", Type.EmptyTypes); Assert.IsNotNull(sharedMethodLocation, "Expected TestEntity.ServerAndClientMethod to be shared"); Assert.IsTrue(sharedMethodLocation.Contains("ClientClassLib"), "Expected to find method in client class lib"); sharedMethodLocation = GetSharedMethodLocation(sa, typeof(TestValidator), "ServertMethod", Type.EmptyTypes); Assert.IsNull(sharedMethodLocation, "Expected TestValidator.ServerMethod not to be shared"); } TestHelper.AssertNoErrorsOrWarnings(logger); }
/// <summary> /// Creates a new CreateOpenRiaClientFilesTask instance to use to generate code /// </summary> /// <param name="relativeTestDir"></param> /// <param name="includeClientOutputAssembly">if <c>true</c> include clients own output assembly in analysis</param> /// <returns>A new task instance that can be invoked to do code gen</returns> public static CreateOpenRiaClientFilesTask CreateOpenRiaClientFilesTaskInstance_CopyClientProjectToOutput(string serverProjectPath, string clientProjectPath, bool includeClientOutputAssembly) { CreateOpenRiaClientFilesTask task = new CreateOpenRiaClientFilesTask(); MockBuildEngine mockBuildEngine = new MockBuildEngine(); task.BuildEngine = mockBuildEngine; task.Language = "C#"; task.ServerProjectPath = serverProjectPath; task.ServerAssemblies = new TaskItem[] { new TaskItem(CodeGenHelper.ServerClassLibOutputAssembly(task.ServerProjectPath)) }; task.ServerReferenceAssemblies = MsBuildHelper.AsTaskItems(CodeGenHelper.ServerClassLibReferences(task.ServerProjectPath)).ToArray(); task.ClientFrameworkPath = CodeGenHelper.GetClientRuntimeDirectory(); // Generate the code to our deployment directory string tempFolder = CodeGenHelper.GenerateTempFolder(); task.OutputPath = Path.Combine(tempFolder, "FileWrites"); task.GeneratedCodePath = Path.Combine(tempFolder, "Generated_Code"); string clientProjectFileName = Path.GetFileName(clientProjectPath); string clientProjectDestPath = Path.Combine(tempFolder, clientProjectFileName); File.Copy(clientProjectPath, clientProjectDestPath); task.ClientProjectPath = clientProjectDestPath; task.ClientReferenceAssemblies = MsBuildHelper.AsTaskItems(CodeGenHelper.ClientClassLibReferences(clientProjectPath, includeClientOutputAssembly)).ToArray(); task.ClientSourceFiles = MsBuildHelper.AsTaskItems(CodeGenHelper.ClientClassLibSourceFiles(clientProjectPath)).ToArray(); return(task); }
public void CodeGen_SharedEntity_EntityShapingWithComposition_Succeeds() { Type[] domainServices = new Type[] { typeof(SharedScenarios_CompositionShaping_ExposeBDomainService1), typeof(SharedScenarios_CompositionShaping_ExposeBDomainService2), }; // Generated class and property getter for B exists string[] codeContains = new string[] { "public sealed partial class SharedScenarios_LeafEntityB : Entity", "public SharedScenarios_LeafEntityB B", }; // Generated enumerable for B does not exist // A does not exist string[] codeNotContains = new string[] { "public EntitySet<SharedScenarios_LeafEntityB> SharedScenarios_LeafEntityBs", "SharedScenarios_LeafEntityA", }; CodeGenHelper.BaseSuccessTest(domainServices, codeContains, codeNotContains); }
public void SharedAssembliesManaged_Types() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths("", out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); List <string> assemblies = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true); ConsoleLogger logger = new ConsoleLogger(); using (var sa = CreatedSharedAssembliesService(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger)) { string sharedTypeLocation = GetSharedTypeLocation(sa, typeof(TestEntity)); Assert.IsNotNull(sharedTypeLocation, "Expected TestEntity type to be shared"); Assert.IsTrue(sharedTypeLocation.Contains("ClientClassLib"), "Expected to find type in client class lib"); sharedTypeLocation = GetSharedTypeLocation(sa, typeof(TestValidator)); Assert.IsNotNull(sharedTypeLocation, "Expected TestValidator type to be shared"); Assert.IsTrue(sharedTypeLocation.Contains("ClientClassLib"), "Expected to find type in client class lib"); sharedTypeLocation = GetSharedTypeLocation(sa, typeof(DomainService)); Assert.IsNull(sharedTypeLocation, "Expected DomainService type not to be shared"); sharedTypeLocation = GetSharedTypeLocation(sa, typeof(TestValidatorServer)); Assert.IsNull(sharedTypeLocation, "Expected TestValidatorServer type not to be shared"); } TestHelper.AssertNoErrorsOrWarnings(logger); }
public void SharedAssemblies_Types() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths(string.Empty, out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); List <string> assemblies = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true); ConsoleLogger logger = new ConsoleLogger(); SharedAssemblies sa = new SharedAssemblies(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger); Type sharedType = sa.GetSharedType(typeof(TestEntity).AssemblyQualifiedName); Assert.IsNotNull(sharedType, "Expected TestEntity type to be shared"); Assert.IsTrue(sharedType.Assembly.Location.Contains("ClientClassLib"), "Expected to find type in client class lib"); sharedType = sa.GetSharedType(typeof(TestValidator).AssemblyQualifiedName); Assert.IsNotNull(sharedType, "Expected TestValidator type to be shared"); Assert.IsTrue(sharedType.Assembly.Location.Contains("ClientClassLib"), "Expected to find type in client class lib"); sharedType = sa.GetSharedType(typeof(DomainService).AssemblyQualifiedName); Assert.IsNull(sharedType, "Expected DomainService type not to be shared"); sharedType = sa.GetSharedType(typeof(TestValidatorServer).AssemblyQualifiedName); Assert.IsNull(sharedType, "Expected TestValidatorServer type not to be shared"); TestHelper.AssertNoErrorsOrWarnings(logger); }
public void SharedAssemblies_Methods() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths(string.Empty, out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); List <string> assemblies = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true); ConsoleLogger logger = new ConsoleLogger(); SharedAssemblies sa = new SharedAssemblies(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger); MethodBase sharedMethod = sa.GetSharedMethod(typeof(TestValidator).AssemblyQualifiedName, "IsValid", new string[] { typeof(TestEntity).AssemblyQualifiedName, typeof(ValidationContext).AssemblyQualifiedName }); Assert.IsNotNull(sharedMethod, "Expected TestValidator.IsValid to be shared"); Assert.IsTrue(sharedMethod.DeclaringType.Assembly.Location.Contains("ClientClassLib"), "Expected to find method in client class lib"); sharedMethod = sa.GetSharedMethod(typeof(TestEntity).AssemblyQualifiedName, "ServerAndClientMethod", Array.Empty <string>()); Assert.IsNotNull(sharedMethod, "Expected TestEntity.ServerAndClientMethod to be shared"); Assert.IsTrue(sharedMethod.DeclaringType.Assembly.Location.Contains("ClientClassLib"), "Expected to find method in client class lib"); sharedMethod = sa.GetSharedMethod(typeof(TestValidator).AssemblyQualifiedName, "ServertMethod", Array.Empty <string>()); Assert.IsNull(sharedMethod, "Expected TestValidator.ServerMethod not to be shared"); TestHelper.AssertNoErrorsOrWarnings(logger); }
public void CodeGen_SharedEntity_TwoNamedUpdateMethods_Succeeds() { Type[] domainServices = new Type[] { typeof(SharedScenarios_NamedUpdate_ExposeNamedUpdate1DomainService), typeof(SharedScenarios_NamedUpdate_ExposeNamedUpdate2DomainService), }; // Named update methods, other methods and guard properties exist for both methods string[] codeContains = new string[] { "base.InvokeAction(\"ChangeA1\", intProp);", "base.InvokeAction(\"ChangeA2\", boolProp);", "OnChangeA1Invoking", "OnChangeA2Invoking", "OnChangeA1Invoked", "OnChangeA2Invoked", "IsChangeA1Invoked", "IsChangeA2Invoked", "CanChangeA1", "CanChangeA2", }; CodeGenHelper.BaseSuccessTest(domainServices, codeContains, null); }
public void SharedCodeService_Methods() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths("", out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); ConsoleLogger logger = new ConsoleLogger(); using (SharedCodeService sts = CodeGenHelper.CreateSharedCodeService(clientProjectPath, logger)) { CodeMemberShareKind shareKind = sts.GetMethodShareKind(typeof(TestValidator).AssemblyQualifiedName, "IsValid", new string[] { typeof(TestEntity).AssemblyQualifiedName, typeof(ValidationContext).AssemblyQualifiedName }); Assert.AreEqual(CodeMemberShareKind.SharedByReference, shareKind, "Expected TestValidator.IsValid to be shared by reference"); shareKind = sts.GetMethodShareKind(typeof(TestEntity).AssemblyQualifiedName, "ServerAndClientMethod", Array.Empty <string>()); Assert.AreEqual(CodeMemberShareKind.SharedByReference, shareKind, "Expected TestValidator.ServerAndClientMethod to be shared by reference"); shareKind = sts.GetMethodShareKind(typeof(TestEntity).AssemblyQualifiedName, "ServerMethod", Array.Empty <string>()); Assert.AreEqual(CodeMemberShareKind.NotShared, shareKind, "Expected TestValidator.ServerMethod not to be shared"); shareKind = sts.GetMethodShareKind(typeof(TestValidatorServer).AssemblyQualifiedName, "IsValid", new string[] { typeof(TestEntity).AssemblyQualifiedName, typeof(ValidationContext).AssemblyQualifiedName }); Assert.AreEqual(CodeMemberShareKind.NotShared, shareKind, "Expected TestValidator.IsValid not to be shared"); TestHelper.AssertNoErrorsOrWarnings(logger); } }
public void CodeGen_SharedEntity_EntityShapingByThreeDomainServices_Succeeds() { Type[] domainServices = new Type[] { typeof(SharedScenarios_EntityShaping_ExposeADomainService), typeof(SharedScenarios_EntityShaping_ExposeBDomainService), typeof(SharedScenarios_EntityShaping_ExposeCDomainService), }; // Generated property getter, classes, and enumerables for A, B and C exists string[] codeContains = new string[] { "public sealed partial class SharedScenarios_LeafEntityA : Entity", "public sealed partial class SharedScenarios_LeafEntityB : Entity", "public sealed partial class SharedScenarios_LeafEntityC : Entity", "public SharedScenarios_LeafEntityA A", "public SharedScenarios_LeafEntityB B", "public SharedScenarios_LeafEntityC C", "public EntitySet<SharedScenarios_LeafEntityA> SharedScenarios_LeafEntityAs", "public EntitySet<SharedScenarios_LeafEntityB> SharedScenarios_LeafEntityBs", "public EntitySet<SharedScenarios_LeafEntityC> SharedScenarios_LeafEntityCs", }; // D does not exist string[] codeNotContains = new string[] { "SharedScenarios_LeafEntityD", }; CodeGenHelper.BaseSuccessTest(domainServices, codeContains, codeNotContains); }
public void CodeGen_SharedEntity_EntityShapingWithIncludeAndExclude_Succeeds() { Type[] domainServices = new Type[] { typeof(SharedScenarios_IncludeExcludeShaping_ExposeBDomainService), typeof(SharedScenarios_IncludeExcludeShaping_ExposeBAndCDomainService), }; // Generated classes for A, B, and C exist // Generated property getter for A and C exists // Generated enumerables for B and C exist string[] codeContains = new string[] { "public sealed partial class SharedScenarios_LeafEntityA : Entity", "public sealed partial class SharedScenarios_LeafEntityB : Entity", "public sealed partial class SharedScenarios_LeafEntityC : Entity", "public SharedScenarios_LeafEntityA A", "public SharedScenarios_LeafEntityC C", "public EntitySet<SharedScenarios_LeafEntityB> SharedScenarios_LeafEntityBs", "public EntitySet<SharedScenarios_LeafEntityC> SharedScenarios_LeafEntityCs", }; // Generated property getter for B does not exist // Generated enumerable fo A does not exist // D does not exist string[] codeNotContains = new string[] { "public SharedScenarios_LeafEntityB B", "public EntitySet<SharedScenarios_LeafEntityA> SharedScenarios_LeafEntityAs", "SharedScenarios_LeafEntityD", }; CodeGenHelper.BaseSuccessTest(domainServices, codeContains, codeNotContains); }
public void SharedAssembliesManaged_Matches_MsCorLib() { Type[] sharedTypes = new Type[] { typeof(Int32), typeof(string), typeof(Decimal), typeof(List <int>), typeof(Dictionary <int, string>) }; Type[] nonSharedTypes = new Type[] { typeof(DomainService), typeof(List <DomainService>), typeof(DomainService[]) // Below is fomr System.IO.Compression.Filesystem which is not referenced by client //typeof(System.Xml.Linq.XElement) }; MethodBase[] sharedMethods = new MethodBase[] { typeof(string).GetMethod("CopyTo"), }; string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths("", out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); List <string> assemblies = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true); ConsoleLogger logger = new ConsoleLogger(); using (var sa = CreatedSharedAssembliesService(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger)) { foreach (Type t in sharedTypes) { var sharedTypeLocation = GetSharedTypeLocation(sa, t); Assert.IsNotNull(sharedTypeLocation, "Expected type " + t.Name + " to be considered shared."); } foreach (MethodBase m in sharedMethods) { Type[] parameterTypes = m.GetParameters().Select(p => p.ParameterType).ToArray(); var sharedMethodLocation = GetSharedMethodLocation(sa, m.DeclaringType, m.Name, parameterTypes); Assert.IsNotNull(sharedMethodLocation, "Expected method " + m.DeclaringType.Name + "." + m.Name + " to be considered shared."); } foreach (Type t in nonSharedTypes) { var sType = GetSharedTypeLocation(sa, t); Assert.IsNull(sType, "Expected type " + t.Name + " to be considered *not* shared."); } } }
public void RiaClientFilesTask_Safe_File_Move() { CleanOpenRiaClientFilesTask task = new CleanOpenRiaClientFilesTask(); MockBuildEngine mockBuildEngine = new MockBuildEngine(); task.BuildEngine = mockBuildEngine; string tempFolder = CodeGenHelper.GenerateTempFolder(); try { // Do a simple move string file1 = Path.Combine(tempFolder, "File1.txt"); string file2 = Path.Combine(tempFolder, "File2.txt"); File.AppendAllText(file1, "stuff"); bool success = task.SafeFileMove(file1, file2); Assert.IsTrue(success, "SafeFileMove reported failure"); Assert.IsTrue(File.Exists(file2), "File2 did not get created"); Assert.IsFalse(File.Exists(file1), "File1 still exists after move"); string content = File.ReadAllText(file2); Assert.AreEqual("stuff", content, "File2 did not get right content"); string errorMessage = String.Empty; // Finally, try a clearly illegal move and catch the error using (FileStream fs = new FileStream(file2, FileMode.Open, FileAccess.Read, FileShare.None)) { try { File.Move(file2, file1); } catch (IOException iox) { errorMessage = iox.Message; } success = task.SafeFileMove(file2, file1); } Assert.IsFalse(success, "Expected illegal move to report failure"); string expectedWarning = string.Format(CultureInfo.CurrentCulture, Resource.Failed_To_Rename_File, file2, file1, errorMessage); TestHelper.AssertContainsWarnings(mockBuildEngine.ConsoleLogger, expectedWarning); } finally { CodeGenHelper.DeleteTempFolder(tempFolder); } }
public void CodeGenComplexTypes_ComplexTypes_Roundtrip_Propagation() { Type[] domainServices = new Type[] { typeof(ComplexCodeGen_RTO), }; string[] codeContains = new string[] { // Entity itself has RTO @"[RoundtripOriginal()] public sealed partial class ComplexCodeGen_RTO_Entity : Entity", // Full members have RTO @"[RoundtripOriginal()] public int FullMember", @"[RoundtripOriginal()] public ComplexCodeGen_RTO_On_Type_And_Members FullTMMember", // TM has RTO on the type itself @"[RoundtripOriginal()] public sealed partial class ComplexCodeGen_RTO_On_Type_And_Members", }; string[] codeNotContains = new string[] { // Entity CT member skips RTO. @"[RoundtripOriginal()] public ComplexCodeGen_RTO_CT_Full_RTO EntityFullMember", // Full does not have type property @"[RoundtripOriginal()] public sealed partial class ComplexCodeGen_RTO_CT_Full_RTO", // TM members do not have RTO @"[RoundtripOriginal()] public int TMMember", @"[RoundtripOriginal()] public ComplexCodeGen_RTO_NoRTO TMNoMember", // None does not have type property @"[RoundtripOriginal()] public sealed partial class ComplexCodeGen_RTO_NoRTO", // None members do not have RTO @"[RoundtripOriginal()] public int NoMember", }; CodeGenHelper.BaseSuccessTest(domainServices, codeContains, codeNotContains); }
/// <summary> /// Creates a new CreateOpenRiaClientFilesTask instance to use to generate code /// using the TestWap project. /// </summary> /// <param name="relativeTestDir"></param> /// <returns>A new task instance that can be invoked to do code gen</returns> public static CreateOpenRiaClientFilesTask CreateOpenRiaClientFilesTaskInstanceForWAP(string relativeTestDir) { string deploymentDir = Path.GetDirectoryName(typeof(CodeGenHelper).Assembly.Location); string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths(relativeTestDir, out projectPath, out outputPath); Assert.IsTrue(File.Exists(projectPath), "Could not locate " + projectPath + " necessary for test."); string serverProjectPath = CodeGenHelper.ServerWapProjectPath(projectPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); return(CodeGenHelper.CreateOpenRiaClientFilesTaskInstance(serverProjectPath, clientProjectPath, false)); }
public void SharedAssembliesManaged_Logs_Message_NonExistent_Assembly() { ConsoleLogger logger = new ConsoleLogger(); string file = "DoesNotExist.dll"; using (var sa = CreatedSharedAssembliesService(new string[] { file }, CodeGenHelper.GetClientAssemblyPaths(), logger)) { var sharedType = GetSharedTypeLocation(sa, typeof(TestEntity)); Assert.IsNull(sharedType, "Should not have detected any shared type."); string message = string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Assembly_Load_Error, file, null); TestHelper.AssertHasInfoThatStartsWith(logger, message); } }
internal static SharedCodeService CreateSharedCodeService(string clientProjectPath, ILoggingService logger) { List <string> sourceFiles = CodeGenHelper.ClientClassLibSourceFiles(clientProjectPath); List <string> assemblies = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true); SharedCodeServiceParameters parameters = new SharedCodeServiceParameters() { SharedSourceFiles = sourceFiles.ToArray(), ClientAssemblies = assemblies.ToArray(), ClientAssemblyPathsNormalized = CodeGenHelper.GetClientAssemblyPaths() }; SharedCodeService sts = new SharedCodeService(parameters, logger); return(sts); }
[Microsoft.VisualStudio.TestTools.UnitTesting.Ignore] // Add this test for all other target frameworks where client is different from server public void SharedAssemblies_Matches_MsCorLib() { Type[] sharedTypes = new Type[] { typeof(Int32), typeof(string), typeof(Decimal), }; Type[] nonSharedTypes = new Type[] { typeof(SerializableAttribute), typeof(System.Xml.Linq.XElement) }; MethodBase[] sharedMethods = new MethodBase[] { typeof(string).GetMethod("CopyTo"), }; string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths(string.Empty, out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); List <string> assemblies = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true); ConsoleLogger logger = new ConsoleLogger(); SharedAssemblies sa = new SharedAssemblies(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger); foreach (Type t in sharedTypes) { Type sharedType = sa.GetSharedType(t.AssemblyQualifiedName); Assert.IsNotNull(sharedType, "Expected type " + t.Name + " to be considered shared."); } foreach (MethodBase m in sharedMethods) { string[] parameterTypes = m.GetParameters().Select <ParameterInfo, string>(p => p.ParameterType.AssemblyQualifiedName).ToArray(); MethodBase sharedMethod = sa.GetSharedMethod(m.DeclaringType.AssemblyQualifiedName, m.Name, parameterTypes); Assert.IsNotNull(sharedMethod, "Expected method " + m.DeclaringType.Name + "." + m.Name + " to be considered shared."); } foreach (Type t in nonSharedTypes) { Type sType = sa.GetSharedType(t.AssemblyQualifiedName); Assert.IsNull(sType, "Expected type " + t.Name + " to be considered *not* shared."); } }
public void CodeGenComplexTypes_ComplexTypes_Are_Shared_By_DomainServices() { Type[] domainServices = new Type[] { typeof(ComplexCodeGen_SharedComplexTypes1), typeof(ComplexCodeGen_SharedComplexTypes2), }; string[] codeContains = new string[] { "public InvokeOperation Invoke1(ComplexCodeGen_SharedComplexType_SharedComplexTypes_CT complexType, Action<InvokeOperation> callback, object userState)", "public InvokeOperation Invoke1(ComplexCodeGen_SharedComplexType_SharedComplexTypes_CT complexType)", "public InvokeOperation Invoke2(ComplexCodeGen_SharedComplexType_SharedComplexTypes_CT complexType, Action<InvokeOperation> callback, object userState)", "public InvokeOperation Invoke2(ComplexCodeGen_SharedComplexType_SharedComplexTypes_CT complexType)", }; // compiling is enough validation that the type does not appear twice CodeGenHelper.BaseSuccessTest(domainServices, codeContains, null); }
public void SharedCodeService_Properties() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths("", out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); ConsoleLogger logger = new ConsoleLogger(); using (SharedCodeService sts = CodeGenHelper.CreateSharedCodeService(clientProjectPath, logger)) { CodeMemberShareKind shareKind = sts.GetPropertyShareKind(typeof(TestEntity).AssemblyQualifiedName, "ServerAndClientValue"); Assert.AreEqual(CodeMemberShareKind.SharedByReference, shareKind, "Expected TestEntity.ServerAndClientValue property to be shared by reference."); shareKind = sts.GetPropertyShareKind(typeof(TestEntity).AssemblyQualifiedName, "TheValue"); Assert.AreEqual(CodeMemberShareKind.NotShared, shareKind, "Expected TestEntity.TheValue property not to be shared in source."); } }
public void SharedCodeService_Ctors() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths("", out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); ConsoleLogger logger = new ConsoleLogger(); using (SharedCodeService sts = CodeGenHelper.CreateSharedCodeService(clientProjectPath, logger)) { ConstructorInfo ctor = typeof(TestValidator).GetConstructor(new Type[] { typeof(string) }); Assert.IsNotNull("Failed to find string ctor on TestValidator"); CodeMemberShareKind shareKind = sts.GetMethodShareKind(typeof(TestValidator).AssemblyQualifiedName, ctor.Name, new string[] { typeof(string).AssemblyQualifiedName }); Assert.AreEqual(CodeMemberShareKind.SharedByReference, shareKind, "Expected TestValidator ctor to be shared by reference"); TestHelper.AssertNoErrorsOrWarnings(logger); } }
public void SharedAssembliesManaged_Properties() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths("", out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); List <string> assemblies = CodeGenHelper.ClientClassLibReferences(clientProjectPath, true); ConsoleLogger logger = new ConsoleLogger(); using (var sa = CreatedSharedAssembliesService(assemblies, CodeGenHelper.GetClientAssemblyPaths(), logger)) { string sharedTypeLocation = GetSharedPropertyLocation(sa, typeof(TestEntity), nameof(TestEntity.ClientAndServerValue)); Assert.IsNotNull(sharedTypeLocation, "Expected TestEntity type to be shared"); Assert.IsTrue(sharedTypeLocation.Contains("ClientClassLib"), "Expected to find type in client class lib"); sharedTypeLocation = GetSharedPropertyLocation(sa, typeof(TestEntity), nameof(TestEntity.ServerAndClientValue)); Assert.IsNotNull(sharedTypeLocation, "Expected TestEntity type to be shared"); Assert.IsTrue(sharedTypeLocation.Contains("ClientClassLib"), "Expected to find type in client class lib"); sharedTypeLocation = GetSharedPropertyLocation(sa, typeof(TestEntity), nameof(TestEntity.TheValue)); Assert.IsNull(sharedTypeLocation, "Expected TestEntity.TheValue type to not be shared"); // We should detect properties from derived types sharedTypeLocation = GetSharedPropertyLocation(sa, "ServerClassLib.TestDomainSharedContext", "ValidationContext"); Assert.IsNotNull(sharedTypeLocation, "Expected to detect properties from base classes (DomainContext.ValidationContext)"); StringAssert.Contains(sharedTypeLocation, "OpenRiaServices.DomainServices.Client"); // We should not detect internal properties sharedTypeLocation = GetSharedPropertyLocation(sa, "OpenRiaServices.DomainServices.Client.Entity", "ValidationErrors"); Assert.IsNotNull(sharedTypeLocation, "Should detect properties in other assemblies"); StringAssert.Contains(sharedTypeLocation, "OpenRiaServices.DomainServices.Client"); sharedTypeLocation = GetSharedPropertyLocation(sa, "OpenRiaServices.DomainServices.Client.Entity", "ParentAssociation"); Assert.IsNull(sharedTypeLocation, "Expected to not detect internal properties"); sharedTypeLocation = GetSharedPropertyLocation(sa, "OpenRiaServices.DomainServices.Client.Entity", "IsMergingState"); Assert.IsNull(sharedTypeLocation, "Expected to not detect protected internal properties"); } TestHelper.AssertNoErrorsOrWarnings(logger); }
public void SharedTypes_CodeGen_Errors_On_Existing_Generated_Entity() { CreateOpenRiaClientFilesTask task = null; try { task = CodeGenHelper.CreateOpenRiaClientFilesTaskInstance("STT", /*includeClientOutputAssembly*/ true); MockBuildEngine mockBuildEngine = task.BuildEngine as MockBuildEngine; bool success = task.Execute(); Assert.IsFalse(success, "Expected build to fail"); string entityMsg = string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_EntityTypesCannotBeShared_Reference, "ServerClassLib.TestEntity"); string complexMsg = string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_ComplexTypesCannotBeShared_Reference, "ServerClassLib.TestComplexType"); TestHelper.AssertContainsErrors(mockBuildEngine.ConsoleLogger, entityMsg, complexMsg); } finally { CodeGenHelper.DeleteTempFolder(task); } }
public void PdbReader_Finds_Types_Files() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths("PDB", out projectPath, out outputPath); string serverProjectPath = CodeGenHelper.ServerClassLibProjectPath(projectPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); ConsoleLogger logger = new ConsoleLogger(); FilenameMap filenameMap = new FilenameMap(); using (SourceFileLocationService locationService = new SourceFileLocationService(new[] { new PdbSourceFileProviderFactory(/*symbolSearchPath*/ null, logger) }, filenameMap)) { List <string> files = new List <string>(locationService.GetFilesForType(typeof(TestEntity))); Assert.AreEqual(4, files.Count); CodeGenHelper.AssertContainsFiles(files, serverProjectPath, new string[] { "TestEntity.cs", "TestEntity.shared.cs", "TestEntity.linked.cs" }); CodeGenHelper.AssertContainsFiles(files, clientProjectPath, new string[] { "TestEntity.reverse.linked.cs" }); } }
public void CodeGenComplexTypes_ComplexTypes_Exclusion_Works() { Type[] domainServices = new Type[] { typeof(ComplexCodeGen_Exclude_ComplexType), }; string[] codeContains = new string[] { "public sealed partial class ComplexCodeGen_Exclude_CT : ComplexObject", "private ComplexCodeGen_Exclude_CT _excludeCT;", "public ComplexCodeGen_Exclude_CT ExcludeCT", }; string[] codeNotContains = new string[] { "ComplexCodeGen_CT_Excluded_Via_Property", }; CodeGenHelper.BaseSuccessTest(domainServices, codeContains, codeNotContains); }
public void SharedCodeService_Types() { string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths("", out projectPath, out outputPath); string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath); ConsoleLogger logger = new ConsoleLogger(); using (SharedCodeService sts = CodeGenHelper.CreateSharedCodeService(clientProjectPath, logger)) { // TestEntity is shared because it is linked CodeMemberShareKind shareKind = sts.GetTypeShareKind(typeof(TestEntity).AssemblyQualifiedName); Assert.AreEqual(CodeMemberShareKind.SharedByReference, shareKind, "Expected TestEntity type to be shared by reference"); // TestValidator is shared because it is linked shareKind = sts.GetTypeShareKind(typeof(TestValidator).AssemblyQualifiedName); Assert.AreEqual(CodeMemberShareKind.SharedByReference, shareKind, "Expected TestValidator type to be shared by reference"); // SharedClass is shared because it is linked shareKind = sts.GetTypeShareKind(typeof(SharedClass).AssemblyQualifiedName); Assert.IsTrue(shareKind == CodeMemberShareKind.SharedBySource, "Expected SharedClass type to be shared in source"); // DomainService exists only in the server and is not shared shareKind = sts.GetTypeShareKind(typeof(DomainService).AssemblyQualifiedName); Assert.IsTrue(shareKind == CodeMemberShareKind.NotShared, "Expected DomainService type not to be shared"); // TestValidatorServer exists only on the server and is not shared shareKind = sts.GetTypeShareKind(typeof(TestValidatorServer).AssemblyQualifiedName); Assert.IsTrue(shareKind == CodeMemberShareKind.NotShared, "Expected TestValidatorServer type not to be shared"); // CodelessType exists on both server and client, but lacks all user code necessary // to determine whether it is shared. Because it compiles into both projects, it should // be considered shared by finding the type in both assemblies shareKind = sts.GetTypeShareKind(typeof(CodelessType).AssemblyQualifiedName); Assert.IsTrue(shareKind == CodeMemberShareKind.SharedByReference, "Expected CodelessType type to be shared in assembly"); } }