Exemplo n.º 1
0
        public override void DialogCommand()
        {
            var visualStudioService = ApplicationController.ResolveType(typeof(IVisualStudioService)) as IVisualStudioService;

            if (visualStudioService == null)
            {
                throw new NullReferenceException("visualStudioService");
            }

            var selectedItems = visualStudioService.GetSelectedFileNamesQualified();

            if (selectedItems.Count() != 1)
            {
                ApplicationController.UserMessage("Only one file may be selected to refresh");
                return;
            }

            //refresh cache in case customisation changes have been made
            var xrmService = ApplicationController.ResolveType(typeof(XrmRecordService)) as XrmRecordService;

            if (xrmService == null)
            {
                throw new NullReferenceException("xrmService");
            }
            xrmService.ClearCache();

            if (selectedItems.Count() != 1)
            {
                ApplicationController.UserMessage("Only one file may be selected to refresh");
                return;
            }
            FileInfo fileInfo = new FileInfo(selectedItems.First());

            var request = new CSharpRequest()
            {
                Folder                = new Folder(fileInfo.DirectoryName),
                FileName              = fileInfo.Name,
                Namespace             = "Schema",
                Actions               = true,
                Entities              = true,
                Fields                = true,
                FieldOptions          = true,
                Relationships         = true,
                SharedOptions         = true,
                IncludeAllRecordTypes = true
            };

            var uri = new UriQuery();

            uri.AddObject(nameof(CSharpDialog.Request), request);
            uri.AddObject(nameof(CSharpDialog.SkipObjectEntry), true);
            ApplicationController.RequestNavigate("Main", typeof(CSharpDialog), uri);
        }
        public void CodeGenerationCSharpModuleTes()
        {
            Assert.IsFalse(FileUtility.GetFiles(TestingFolder).Any());

            //create test application with module loaded
            var testApplication = CreateAndLoadTestApplication <CSharpModule>();

            var request = new CSharpRequest()
            {
                IncludeAllRecordTypes = true,
                Entities      = true,
                Fields        = true,
                FieldOptions  = true,
                Relationships = true,
                SharedOptions = true,
                Actions       = true,
                FileName      = "Schema",
                Folder        = new Folder(TestingFolder),
                Namespace     = "Schema"
            };

            var response = testApplication.NavigateAndProcessDialog <CSharpModule, CSharpDialog, CSharpResponse>(request);

            Assert.IsFalse(response.HasError);
            VerifyCompiles(response.CSharpCode);
            Assert.IsTrue(FileUtility.GetFiles(TestingFolder).Any());

            FileUtility.DeleteFiles(TestingFolder);

            //do one other test for generate only one specific type
            request = new CSharpRequest()
            {
                IncludeAllRecordTypes = false,
                Entities      = true,
                Fields        = true,
                FieldOptions  = true,
                Relationships = true,
                SharedOptions = true,
                FileName      = "Schema",
                Folder        = new Folder(TestingFolder),
                Namespace     = "Schema",
                RecordTypes   = new[] { new RecordTypeSetting(Entities.account, Entities.account) }
            };

            response = testApplication.NavigateAndProcessDialog <CSharpModule, CSharpDialog, CSharpResponse>(request);
            Assert.IsFalse(response.HasError);
            VerifyCompiles(response.CSharpCode);
            Assert.IsTrue(FileUtility.GetFiles(TestingFolder).Any());
        }