public void Output_AddItem_DeveGerarDomainExceptionQuandoAdicionarUmItemEOMesmoJaExistir()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            OutputItem item1 = OutputItemFaker.GenerateFaker(output).Generate();

            output.AddItem(item1);

            // Act
            Action act = () => output.AddItem(item1);

            // Assert
            act.Should().Throw <DomainException>();
        }
        public void Output_RemoveItem_DeveRemoverCorretamenteQuandoItemExistir()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            IList <OutputItem> itemsMock = OutputItemFaker.GenerateFaker(output).Generate(2);

            output.AddItem(itemsMock.First());
            output.AddItem(itemsMock.Last());

            // Act
            output.RemoveItem(itemsMock.First());

            // Assert
            output.Items.Should().HaveCount(1);
            output.Items.Should().NotContain(x => x.Id == itemsMock.First().Id);
        }
        public async Task AddItemAsync(Output output, OutputItem item)
        {
            output.AddItem(item);

            _repository.Update(output);

            if (await _repository.UnitOfWork.CommitAsync())
            {
                await _bus.PublishDomainEvent(new OutputItemAdded(item.Id));
            }
        }
        public void Output_CalculateTotalValue_DeveSomarCorretamenteValorTotal()
        {
            // Arange && Act
            Output output = OutputFaker.GenerateFaker().Generate();

            IList <OutputItem> itemsMock = OutputItemFaker.GenerateFaker(output).Generate(10);

            foreach (OutputItem itemMock in itemsMock)
            {
                output.AddItem(itemMock);
            }

            // Assert
            output.TotalValue.Should().Be(itemsMock.Sum(x => x.CalculteValue()));
        }
        public void Output_RemoveItem_DeveGerarDomainExceptionQuandoRemoverUmItemInexistente()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            IList <OutputItem> itemsMock = OutputItemFaker.GenerateFaker(output).Generate(2);

            output.AddItem(itemsMock.First());

            // Act
            Action act = () => output.RemoveItem(itemsMock.Last());

            // Assert
            act.Should().Throw <DomainException>();
        }
        public void Output_UpdateItem_DeveAtualizarCorretamenteUmItemQuandoOMesmoExistir()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            OutputItem outputItem = OutputItemFaker.GenerateFaker(output).Generate();

            output.AddItem(outputItem);

            // Act
            output.UpdateItem(outputItem);

            // Assert
            output.Items.Should().HaveCount(1);
        }
        public void Output_AddItem_DeveAdicionarOsItensCorretamenteQuandoValidos()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            // Act
            IList <OutputItem> itemsMock = OutputItemFaker.GenerateFaker(output).Generate(10);

            foreach (OutputItem itemMock in itemsMock)
            {
                output.AddItem(itemMock);
            }

            // Assert
            output.Items.Should().HaveCount(10);
        }
        public void PerformRunScript()
        {
            PageViewModel page = Editor.SelectedItem;

            if (page == null || page.Type == Models.PageType.Output)
            {
                return;
            }

            PerformSaveAll();

            string code = BuildScript(page.Filename);

            if (code != page.Content.Text)
            {
                string tempfile = GetTempFile();
                string tempname = String.Format("{0} - Results View", page.Header);

                File.Write(tempfile, code);

                PageViewModel newpage = new PageViewModel(this, tempname, tempfile)
                {
                    IsReadOnly = true
                };
                newpage.Content.Text = code;

                Editor.Items.Add(newpage);

                page = newpage;
            }

            if (page != null)
            {
                Interop.InGameScript script = new Interop.InGameScript(code);

                string filename = page.Filename;

                Output.Clear();

                if (script.CompileErrors.Count > 0)
                {
                    foreach (string error in script.CompileErrors)
                    {
                        string message = error;

                        Match full = _ErrorRegex.Match(error);
                        if (full.Groups.Count > 1)
                        {
                            int diff = Gilgame.SEWorkbench.Interop.InGameScript.HeaderSize;
                            int line = Convert.ToInt32(full.Groups[2].Value) - diff;
                            int col  = Convert.ToInt32(full.Groups[3].Value);

                            string errno = full.Groups[4].Value;

                            string errmsg = full.Groups[5].Value;

                            Models.OutputItem item = new Models.OutputItem()
                            {
                                Line     = line,
                                Column   = col,
                                Error    = errno,
                                Message  = errmsg,
                                Filename = filename
                            };
                            Output.AddItem(item);
                        }
                        else
                        {
                            Match match = _LineColRegex.Match(error);
                            if (match.Groups.Count > 1)
                            {
                                int line = Convert.ToInt32(match.Groups[2].Value) - 9;
                                int col  = Convert.ToInt32(match.Groups[3].Value);

                                message = message.Replace(match.Groups[0].Value, "");

                                Output.AddItem(new Models.OutputItem()
                                {
                                    Line = line, Column = col, Message = message, Filename = filename
                                });
                            }
                            else
                            {
                                Output.AddItem(new Models.OutputItem()
                                {
                                    Message = message, Filename = filename
                                });
                            }
                        }
                    }
                }
                else
                {
                    Services.MessageBox.ShowMessage("The program compiled without any errors.");
                }

                RaiseScriptRunning();
            }
        }