コード例 #1
0
        public void TestAddCargoBorderViewModel()
        {
            var viewmodel = new AddCargoBorderViewModel(cargoService, variableService, cargoBorderService);

            int previousCargoBorderCounter = cargoBorderService.All().Count;

            viewmodel.SelectedCargo            = cargoService.Find(1);
            viewmodel.SelectedVariable         = "Temperatuur";
            viewmodel.CurrentCargoBorder.Value = logService.All().Count;

            try
            {
                viewmodel.AddBorder(null);
            }
            catch (NullReferenceException)
            {
                // Navigation error
            }

            int expectedCargoBorderCounter = previousCargoBorderCounter + 1;

            Assert.IsNotNull(viewmodel.SelectedCargo);
            Assert.IsNotNull(viewmodel.CurrentCargoBorder);
            Assert.IsTrue(viewmodel.VariableList.Contains(viewmodel.SelectedVariable));
            Assert.IsTrue(expectedCargoBorderCounter == cargoBorderService.All().Count);
        }
コード例 #2
0
        public void AddBorder(object obj)
        {
            if (SelectedVariable != null)
            {
                List <Variable> variables = variableService.All();
                CurrentCargoBorder.Variable = variables.FirstOrDefault(v => v.Description == SelectedVariable);

                var cargoBorders = cargoBorderService.All();

                if (cargoBorders.Count > 0)
                {
                    var lastCargoBorderId = cargoBorders.Max(c => c.Cargo_border_id);
                    CurrentCargoBorder.Cargo_border_id = lastCargoBorderId + 1;
                }
                else
                {
                    CurrentCargoBorder.Cargo_border_id = 1;
                }

                SelectedCargo.Borders.Add(CurrentCargoBorder);
                cargoService.Update(SelectedCargo);
                new NavService().NavigateTo("Cargos");
            }
        }