Пример #1
0
 public PizzaOrderStrategy(List <IProduct> products, IngredientMap ingredientMap, SizeMap sizeMap, IOrderStrategy nextStrategy)
 {
     _products      = products;
     _ingredientMap = ingredientMap;
     _sizeMap       = sizeMap;
     _nextStrategy  = nextStrategy;
 }
Пример #2
0
        public void SetUp()
        {
            _axisMap  = new FakeAxisMap();
            _colorMap = new FakeColorMap();
            _sizeMap  = new FakeSizeMap();
            _labelMap = new FakeLabelMap();

            _column       = new ColumnBuilder().Build();
            _colorPalette = new ColorPaletteBuilder().Build();

            _mockAxisMapFactory = new Mock <IAxisMapFactory>();
            _mockAxisMapFactory.Setup(p => p.Create(_column, 0d, 1d, SortOrder.Ascending))
            .Returns(_axisMap);

            _mockColorMapFactory = new Mock <IColorMapFactory>();
            _mockColorMapFactory.Setup(p => p.Create(_column, _colorPalette, SortOrder.Ascending))
            .Returns(_colorMap);

            _mockSizeMapFactory = new Mock <ISizeMapFactory>();
            _mockSizeMapFactory.Setup(p => p.Create(_column, 0d, 1d, SortOrder.Ascending))
            .Returns(_sizeMap);

            _mockLabelMapFactory = new Mock <ILabelMapFactory>();
            _mockLabelMapFactory.Setup(p => p.Create(_column))
            .Returns(_labelMap);

            _factory = new MapFactory(
                _mockAxisMapFactory.Object,
                _mockColorMapFactory.Object,
                _mockSizeMapFactory.Object,
                _mockLabelMapFactory.Object);
        }
Пример #3
0
        public IEnumerable <SizeLegendItemDto> Create(Type type, SizeMap map, List <object> values, double lowerSize, double upperSize)
        {
            if (type == typeof(Boolean))
            {
                return(_booleanFactory.Create(map, values.Cast <bool?>().ToList(), lowerSize, upperSize));
            }

            if (type == typeof(DateTime))
            {
                return(_dateTimeFactory.Create(map, values.Cast <DateTime?>().ToList(), lowerSize, upperSize));
            }

            if (type == typeof(Double))
            {
                return(_floatFactory.Create(map, values.Cast <double?>().ToList(), lowerSize, upperSize));
            }

            if (type == typeof(Int32))
            {
                return(_integerFactory.Create(map, values.Cast <int?>().ToList(), lowerSize, upperSize));
            }

            if (type == typeof(String))
            {
                return(_stringFactory.Create(map, values.Cast <string>().ToList(), lowerSize, upperSize));
            }

            throw new ArgumentException("Could not create color legend items because data type was not recognized");
        }
        public void TestCreateShouldReturnDescendingSizeLegendItems()
        {
            _sizeMap = new FakeSizeMap(SortOrder.Descending);
            var results = _factory.Create(_sizeMap, _values, _lowerSize, _upperSize);

            AssertResult(results.First(), _lowerSize, "True");
            AssertResult(results.Last(), _upperSize, "False");
        }
        public void SetUp()
        {
            _sizeMap   = new FakeSizeMap();
            _values    = new List <bool?>();
            _lowerSize = 0d;
            _upperSize = 1d;

            _factory = new BooleanSizeLegendFactory();
        }
Пример #6
0
        public void GivenAlternativeSizeName_WhenAskingToMap_ThenItShouldReturnCorrectSize()
        {
            // arrange
            const string name    = "Mini";
            SizeMap      sizeMap = new SizeMap();

            // act
            IProductSize actual = sizeMap.DomainSize(name);

            // assert
            actual.GetType().Name.Should().Be(nameof(MiniPizzaSize));
        }
Пример #7
0
        private void CreateUpdateCanvas()
        {
            _isOnBigGUI = MainWindow.I.IsBigGUISelected;

            int          nBarterHexColumn = Convert.ToInt32(_arrayDBValues[(int)EDBBarterHexesTableColumns.eNX]);
            int          nBarterHexRow    = Convert.ToInt32(_arrayDBValues[(int)EDBBarterHexesTableColumns.eNY]);
            SizeMap      sizeMap          = Maps.Maps.SizeGameMap;
            BitmapSource mark             = null;
            Point?       markPosition     = null;

            // Just a sanity check to see if the barter spot exists on map
            if (nBarterHexColumn <= sizeMap.Columns && nBarterHexRow <= sizeMap.Rows)
            {
                //HexHilight image will mark the spot
                mark = Images.Images.GetImageToDraw("HexHilight", "0_images", _isOnBigGUI, false);

                markPosition = Maps.Maps.GetGameMapImagePixelCoordinate(nBarterHexColumn, nBarterHexRow, _isOnBigGUI);
            }

            //Fetch the map with the barterhex marked on it
            DrawingImage finalMapWithBarterhexMarked = Maps.Maps.GetGameMapImageWithDrawnImageAtPoint(_isOnBigGUI, Maps.Maps.EDayTime.eDay, true, mark, markPosition);

            //We need this to try to center the scroll view on the barter hex
            SizeTile sizeTile = _isOnBigGUI ? HexTypes.HexTypes.SizeBigTile : HexTypes.HexTypes.SizeSmallTile;

            Dispatcher.BeginInvoke(new Action(() =>
            {
                ContainerBarterHexesCanvas.Source = finalMapWithBarterhexMarked;
                ContainerBarterHexesCanvas.Width  = finalMapWithBarterhexMarked.Width;
                ContainerBarterHexesCanvas.Height = finalMapWithBarterhexMarked.Height;
                //I will do this here instead of on RunWorkerCompleted because I need the grid to reserve it's space on GUI
                if (DataGridBarterHexes.ItemsSource == null)
                {
                    DataGridBarterHexes.ItemsSource = _dataGridItems;
                    DataGridBarterHexes.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    Size visualSize = DataGridBarterHexes.DesiredSize;
                    DataGridBarterHexes.Arrange(new Rect(new Point(0, 0), visualSize));
                    DataGridBarterHexes.UpdateLayout();
                }
                // let's try to center the scroll view on the barter hex
                if (markPosition.HasValue)
                {
                    double scrollWidth  = ContainerBarterHexesScroll.ViewportWidth;
                    double scrollHeight = ContainerBarterHexesScroll.ViewportHeight;

                    double offsetX = markPosition.Value.X + sizeTile.Width * 0.5 - scrollWidth * 0.5;
                    double offsetY = markPosition.Value.Y + sizeTile.Height * 0.5 - scrollHeight * 0.5;

                    ContainerBarterHexesScroll.ScrollToVerticalOffset(offsetY);
                    ContainerBarterHexesScroll.ScrollToHorizontalOffset(offsetX);
                }
            }));
        }
Пример #8
0
        public void GivenNonExistentSizeName_WhenAskingToMap_ThenItShouldThrow()
        {
            // arrange
            const string name    = "Dammit, Bobby!";
            SizeMap      sizeMap = new SizeMap();

            // act
            Action action = () => sizeMap.DomainSize(name);

            // assert
            action.Should().Throw <Exception>();
        }
Пример #9
0
        public void GivenLargeSizeName_WhenAskingToMap_ThenItShouldReturnCorrectSize()
        {
            // arrange
            const string name    = "Large";
            SizeMap      sizeMap = new SizeMap();

            // act
            IProductSize mappedSize = sizeMap.DomainSize(name);

            // assert
            ((decimal)mappedSize.Price()).Should().Be(18.0m);
        }
        private IEnumerable<SizeLegendItemDto> CreateContinuousSizeLegendItems(SizeMap map, double lowerSize, double upperSize)
        {
            var unit = (upperSize - lowerSize) / 2;

            for (var i = 0; i < ContinuousItems; i++)
            {
                var itemDto = new SizeLegendItemDto()
                {
                    Size = lowerSize + (i * unit),
                    Label = GetLabelName((int?) map.MapInverse(i * unit))
                };

                yield return itemDto;
            }
        }
        private IEnumerable <SizeLegendItemDto> CreateContinuousSizeLegendItems(SizeMap map, double lowerSize, double upperSize)
        {
            var unit = (upperSize - lowerSize) / 2;

            for (var i = 0; i < ContinuousItems; i++)
            {
                var itemDto = new SizeLegendItemDto()
                {
                    Size  = lowerSize + (unit * i),
                    Label = (string)map.MapInverse(i * 0.5d)
                };

                yield return(itemDto);
            }
        }
        private IEnumerable<SizeLegendItemDto> CreateDiscreteSizeLegendItems(SizeMap map, List<int> values)
        {
            if (map.SortOrder == SortOrder.Descending)
                values.Reverse();

            for (var i = 0; i < values.Count(); i++)
            {
                var itemDto = new SizeLegendItemDto()
                {
                    Size = map.Map(values[i]).GetValueOrDefault(),
                    Label = GetLabelName(values[i])
                };

                yield return itemDto;
            }
        }
        public IEnumerable<SizeLegendItemDto> Create(SizeMap map, List<int?> values, double lowerSize, double upperSize)
        {
            if (values.Any(p => p.HasValue == false))
                yield return CreateNullSizeLegendItem();

            var nonNullValues = values
                .Where(p => p.HasValue)
                .Cast<int>()
                .ToList();

            var results = (values.Count() <= MaxDiscreteValues)
                ? CreateDiscreteSizeLegendItems(map, nonNullValues)
                : CreateContinuousSizeLegendItems(map, lowerSize, upperSize);

            foreach (var result in results)
                yield return result;
        }
Пример #14
0
        private IEnumerable <SizeLegendItemDto> CreateDiscreteSizeLegendItems(SizeMap map, List <DateTime> values)
        {
            if (map.SortOrder == SortOrder.Descending)
            {
                values.Reverse();
            }

            for (var i = 0; i < values.Count(); i++)
            {
                var itemDto = new SizeLegendItemDto()
                {
                    Size  = map.Map(values[i]).GetValueOrDefault(),
                    Label = values[i].ToShortDateString()
                };

                yield return(itemDto);
            }
        }
        public void SetUp()
        {
            _colorMap  = new FakeSizeMap();
            _values    = new List <object>();
            _lowerSize = 0d;
            _upperSize = 1d;

            _mockBooleanFactory  = new Mock <IBooleanSizeLegendFactory>();
            _mockDateTimeFactory = new Mock <IDateTimeSizeLegendFactory>();
            _mockFloatFactory    = new Mock <IFloatSizeLegendFactory>();
            _mockIntegerFactory  = new Mock <IIntegerSizeLegendFactory>();
            _mockStringFactory   = new Mock <IStringSizeLegendFactory>();

            _factory = new SizeLegendFactory(
                _mockBooleanFactory.Object,
                _mockDateTimeFactory.Object,
                _mockFloatFactory.Object,
                _mockIntegerFactory.Object,
                _mockStringFactory.Object);
        }
        public IEnumerable <SizeLegendItemDto> Create(SizeMap map, List <bool?> values, double lowerSize, double upperSize)
        {
            if (values.Contains(null))
            {
                yield return(CreateNullSizeLegendItem());
            }

            if (map.SortOrder == SortOrder.Ascending)
            {
                yield return(CreateSizeLegendItem("False", lowerSize));

                yield return(CreateSizeLegendItem("True", upperSize));
            }
            else
            {
                yield return(CreateSizeLegendItem("True", lowerSize));

                yield return(CreateSizeLegendItem("False", upperSize));
            }
        }
Пример #17
0
        public void SetUp()
        {
            _values = new List <string> {
                "test"
            };
            _column = new ColumnBuilder()
                      .WithId(1)
                      .WithDataType(typeof(String))
                      .WithValue(_values)
                      .Build();
            _layout = new ScatterPlotLayoutBuilder()
                      .WithSizeColumn(_column)
                      .WithLowerSize(0d)
                      .WithUpperSize(1d)
                      .Build();
            _scatterPlot = new ScatterPlotBuilder()
                           .WithLayout(_layout)
                           .Build();
            _map     = new FakeSizeMap();
            _itemDto = new SizeLegendItemDto();

            _mockViewRepository = new Mock <IViewRepository>();
            _mockViewRepository.Setup(p => p.Get <ScatterPlot>())
            .Returns(_scatterPlot);

            _mockMapFactory = new Mock <IMapFactory>();
            _mockMapFactory.Setup(p => p.CreateSizeMap(_column, _layout.LowerSize, _layout.UpperSize, SortOrder.Ascending))
            .Returns(_map);

            _mockItemFactory = new Mock <ISizeLegendFactory>();
            _mockItemFactory.Setup(p =>
                                   p.Create(_column.DataType, _map, It.IsAny <List <object> >(), _layout.LowerSize, _layout.UpperSize))
            .Returns(new List <SizeLegendItemDto> {
                _itemDto
            });

            _handler = new GetSizeLegendItemsQueryHandler(
                _mockViewRepository.Object,
                _mockMapFactory.Object,
                _mockItemFactory.Object);
        }
        public IEnumerable <SizeLegendItemDto> Create(SizeMap map, List <string> values, double lowerSize, double upperSize)
        {
            if (values.Any(p => p == null))
            {
                yield return(CreateNullSizeLegendItem());
            }

            var distinctValues = values
                                 .Distinct()
                                 .ToList();

            var nonNullValues = distinctValues
                                .Where(p => p != null)
                                .ToList();

            var results = (distinctValues.Count() <= MaxDiscreteValues)
                ? CreateDiscreteSizeLegendItems(map, nonNullValues)
                : CreateContinuousSizeLegendItems(map, lowerSize, upperSize);

            foreach (var result in results)
            {
                yield return(result);
            }
        }