public void CreateDataInput_BoundingBoxInputViewModelGiven_IsValue_ShouldCreateInput() { const string processName = "testProcess"; const int expectedDimensionCount = 2; var vm = new BoundingBoxInputViewModel(new MapServiceMock(), new ContextMock(), new DialogServiceMock()) { ProcessName = processName, RectangleViewModel = new RectangleViewModel(new Tuple <double, double>(1.0, 2.0), new Tuple <double, double>(3.0, 4.0)) }; var input = _requestFactory.CreateDataInput(vm); input.Identifier.Should().Be(processName); input.Data.Should().BeOfType <BoundingBoxValue>(); if (input.Data is BoundingBoxValue bbv) { bbv.DimensionCount.Should().Be(expectedDimensionCount); bbv.LowerCornerPoints.Should().BeEquivalentTo(1.0, 2.0); bbv.UpperCornerPoints.Should().BeEquivalentTo(3.0, 4.0); } }
public DataInputViewModel CreateDataInputViewModel(Input input) { if (input == null) { throw new ArgumentNullException(nameof(input)); } var formatVms = input.Data.Formats.GroupBy(f => f.MimeType).Select(f => { var schemas = f.Where(fs => !string.IsNullOrEmpty(fs.Schema)).Select(fs => fs.Schema).ToList(); var encodings = f.Where(fe => !string.IsNullOrEmpty(fe.Encoding)).Select(fe => fe.Encoding).ToList(); var formatVm = new FormatViewModel { MimeType = f.Key, Schemas = new ObservableCollection <string>(schemas), SelectedSchema = schemas.FirstOrDefault(), Encodings = new ObservableCollection <string>(encodings), SelectedEncoding = encodings.FirstOrDefault() }; return(formatVm); }).ToList(); var isOptional = input.MinimumOccurrences == 0; DataInputViewModel vm; if (input.Data is LiteralData ld) { vm = new LiteralInputViewModel(); } else if (input.Data is BoundingBoxData bbd) { vm = new BoundingBoxInputViewModel(_mapService, _context, _dialogService); } else if (input.Data is ComplexData cd) { vm = new ComplexDataViewModel(_dialogService); } else { vm = new DataInputViewModel(); } vm.IsOptional = isOptional; vm.ProcessName = input.Identifier; vm.Formats = new ObservableCollection <FormatViewModel>(formatVms); var defaultFormat = input.Data.Formats.FirstOrDefault(f => f.IsDefault); if (defaultFormat != null) { var selectedVm = formatVms.FirstOrDefault(v => v.MimeType.Equals(defaultFormat.MimeType, StringComparison.InvariantCultureIgnoreCase)); if (selectedVm != null) { selectedVm.SelectedSchema = defaultFormat.Schema; selectedVm.SelectedEncoding = defaultFormat.Encoding; vm.SelectedFormat = selectedVm; } } else { vm.SelectedFormat = vm.Formats.FirstOrDefault(); } return(vm); }