public void CreatePublishedAssemblyTest()
        {
            // Arrange
            var mockLogManager          = new Mock <ILogManager>();
            var mockRuleSetRepository   = new Mock <IRuleSetRepository>();
            var mockRuleSetTranslator   = new Mock <IRuleSetTranslator>();
            var mockRuleAssemblyService = new Mock <IRuleSetAssemblyService>();
            var testRuleSet             = CreateTestRuleSet();

            mockRuleSetTranslator.Setup(x => x.Translate(It.IsAny <IRuleSet>(), true))
            .Returns(It.IsAny <string>());
            mockRuleAssemblyService.Setup(x => x.CreateAssembly(It.IsAny <IRuleSet>()))
            .Returns(It.IsAny <byte[]>());

            // Act
            var sut = new RuleApplicationService(
                mockLogManager.Object, mockRuleSetRepository.Object, mockRuleSetTranslator.Object, mockRuleAssemblyService.Object);

            var response = sut.CreateAssembly(testRuleSet, true);

            // Assert
            response.IsSuccessful.Should().BeTrue();
            response.Errors.Count.Should().Be(0);

            mockRuleSetTranslator.Verify(x => x.Translate(It.IsAny <IRuleSet>(), true));
            mockRuleAssemblyService.Verify(x => x.CreateAssembly(It.IsAny <IRuleSet>()));
        }
        public async void DeleteErrorTest()
        {
            // Arrange
            var mockLogManager          = new Mock <ILogManager>();
            var mockRuleSetRepository   = new Mock <IRuleSetRepository>();
            var mockRuleSet             = new Mock <IRuleSet>();
            var mockRuleSetTranslator   = new Mock <IRuleSetTranslator>();
            var mockRuleAssemblyService = new Mock <IRuleSetAssemblyService>();

            // Setup mock methods/properties
            mockRuleSet.Setup(c => c.Id).Returns(It.IsAny <int>());
            mockRuleSetRepository.Setup(x => x.DeleteAsync(It.IsAny <int>()))
            .Throws(new Exception());

            // Act
            var sut = new RuleApplicationService(
                mockLogManager.Object, mockRuleSetRepository.Object, mockRuleSetTranslator.Object, mockRuleAssemblyService.Object);
            var response = await sut.DeleteAsync(It.IsAny <int>());

            // Assert
            response.IsSuccessful.Should().BeFalse();
            response.Errors.Count.Should().BeGreaterThan(0);
            response.Message.Should().NotBeNullOrEmpty();

            // Verify the application service is calling the correct repository method.
            mockRuleSetRepository.Verify(x => x.DeleteAsync(It.IsAny <int>()));

            // Verify the application service is logging the error.
            mockLogManager.Verify(x => x.LogError(It.IsAny <Exception>(), It.IsAny <string>()));
        }
Exemple #3
0
        public void CreatePublishedAssemblyTest()
        {
            // Arrange
            var mockLogManager        = new Mock <ILogManager>();
            var mockRuleSetRepository = new Mock <IRuleSetRepository>();
            var mockRuleTerminalApplicationService = new Mock <IRuleGrammarTerminalApplicationService>();

            mockRuleTerminalApplicationService.Setup(x => x.GetAllAsync())
            .Returns(Task.FromResult(GetMockRuleTerminals()));

            var businessRuleParser =
                new BusinessRuleParser(mockLogManager.Object, mockRuleTerminalApplicationService.Object);

            var rulesetTranslator   = new RuleSetTranslator(businessRuleParser);
            var ruleAssemblyService = new RuleSetAssemblyService(mockLogManager.Object);


            var testRuleSet = CreateTestRuleSet();

            // Act
            var sut = new RuleApplicationService(
                mockLogManager.Object, mockRuleSetRepository.Object, rulesetTranslator, ruleAssemblyService);

            var response = sut.CreateAssembly(testRuleSet, true);

            // Assert
            response.IsSuccessful.Should().BeTrue();
            response.Errors.Count.Should().Be(0);
            response.Content.GeneratedAssembly.Length.Should().BeGreaterThan(0);
        }
        public async void SaveTest()
        {
            // Arrange
            var mockLogManager          = new Mock <ILogManager>();
            var mockRuleSetRepository   = new Mock <IRuleSetRepository>();
            var mockRuleSetTranslator   = new Mock <IRuleSetTranslator>();
            var mockRuleAssemblyService = new Mock <IRuleSetAssemblyService>();
            var mockRuleSet             = new Mock <IRuleSet>();

            // Setup mock methods/properties
            mockRuleSetRepository.Setup(x => x.SaveAsync(It.IsNotNull <IRuleSet>()))
            .Returns(Task.FromResult(new SaveResponse <IRuleSet> {
                Message = "Successful."
            }));

            // Act
            var sut = new RuleApplicationService(
                mockLogManager.Object, mockRuleSetRepository.Object, mockRuleSetTranslator.Object, mockRuleAssemblyService.Object);
            var response = await sut.SaveAsync(mockRuleSet.Object);

            // Assert
            response.IsSuccessful.Should().BeTrue();
            response.Errors.Count.Should().Be(0);
            response.Message.Should().NotBeNullOrEmpty();

            // Verify the application service is calling the correct repository method.
            mockRuleSetRepository.Verify(x => x.SaveAsync(It.IsAny <IRuleSet>()));
        }
        public ReportWindow(RuleApplicationService ras, SelectionManager sm)
        {
            _ruleApplicationService = ras;
            _selectionManager       = sm;
            InitializeComponent();

            //https://www.codeproject.com/articles/738504/winrt-how-to-communicate-with-webview-javascript-f
            webControl.ScriptNotify += WebControl_ScriptNotify;
        }
Exemple #6
0
        private void RefreshTemplateEngine(object obj)
        {
            var selectedDef = SelectionManager.SelectedItem;

            SelectionManager.SelectedItem = null;

            RuleApplicationService.ResetTemplateEngine(true);

            SelectionManager.SelectedItem = selectedDef;
        }
        public async void CreateTest()
        {
            // Arrange
            var mockLogManager          = new Mock <ILogManager>();
            var mockRuleSetRepository   = new Mock <IRuleSetRepository>();
            var mockRuleSetTranslator   = new Mock <IRuleSetTranslator>();
            var mockRuleAssemblyService = new Mock <IRuleSetAssemblyService>();

            // Act
            var sut = new RuleApplicationService(
                mockLogManager.Object, mockRuleSetRepository.Object, mockRuleSetTranslator.Object, mockRuleAssemblyService.Object);
            var createResponse = await sut.CreateAsync();

            // Assert
            createResponse.IsSuccessful.Should().BeTrue();
            createResponse.Content.Should().NotBeNull();
        }
        public void ExecuteRuleTest()
        {
            // Arrange
            var mockLogManager         = new Mock <ILogManager>();
            var mockRuleSetRepository  = new Mock <IRuleSetRepository>();
            var mockRuleSetTranslator  = new Mock <IRuleSetTranslator>();
            var ruleSetAssemblyService = new RuleSetAssemblyService(mockLogManager.Object);

            var sut = new RuleApplicationService(
                mockLogManager.Object, mockRuleSetRepository.Object, mockRuleSetTranslator.Object, ruleSetAssemblyService);

            // Act
            var ruleSet = new RuleSet
            {
                Name  = "TestRule",
                Code  = $@"
                using System;

                namespace {Constants.RuleNamespace}
                {{
                    public class TestRule
                    {{
                        public int TestExecute()
                        {{
                            return 1;
                        }}
                    }}
                }}",
                Rules = new List <IRule>
                {
                    new Rule {
                        Name = "TestExecute"
                    }
                }
            };
            var result = (int)sut.ExecuteRule(ruleSet, "TestExecute");

            // Assert
            result.Should().Be(1);
        }
Exemple #9
0
        internal void RestartApplicationWithConfirm()
        {
            var restart = MessageBoxFactory.ShowYesNo("Requested operation has been completed. irAuthor must be restarted before your changes can take effect. Would you like to restart irAuthor now?", "Restart needed", MessageBoxFactoryImage.Question, ExtensionBrowserView);

            if (!restart)
            {
                return;
            }

            // If a ruleapp is loaded, give them the opportunity to save it or cancel.
            if (RuleApplicationService.RuleApplicationDef != null)
            {
                restart = RuleApplicationService.Close();
            }

            if (!restart)
            {
                return;
            }

            Process.Start(Application.ResourceAssembly.Location);

            IrAuthorShell.Exit();
        }