public decimal PayBill(DateTime paymentTime, BasePlate[] plates = null) { CalculationStrategy calculationStrategy = this.calculationStrategySelector.GetCalculationStrategy(this.clock.Now, plates); ICalculationService billCalculatorService = this.calculationStrategySelector.GetBillCalculatorStrategy(calculationStrategy); return(billCalculatorService.CalculateTotalPrice(plates)); }
public void Test1() { var spec = new WorkingExperience(TimeSpan.FromDays(365)); var rule = new Rule(1, "x", spec); rule.SetCalculation(CalculationStrategy.DecreasePointsTo(10)); }
public void Caluclate_ReturnsTheDifference_GivenInputGreaterThan0AndLessThan10() { CalculationStrategy calculationStrategy = new CalculationStrategy(10); var answer = calculationStrategy.Calculate(5); Assert.AreEqual(5, answer); }
private async Task Resolve(CalculationStrategy calculationStrategy) { var filters = _filters.ToList(); async Task ResolveFilterAtIndex(int ignoredIndex) { var currentFilter = filters[ignoredIndex]; var selectableItems = _queryable.AsQueryable(); if (currentFilter.NeedsToBeResolved) { await currentFilter.SetAvailableEntities(selectableItems); } if (calculationStrategy == CalculationStrategy.Full) { var filtersToExecute = filters.Where((filterSelector, indexToFilter) => indexToFilter != ignoredIndex); selectableItems = filtersToExecute.Aggregate(selectableItems, (current, filterSelector) => filterSelector.ApplyFilter(current)); await currentFilter.SetSelectableEntities(selectableItems); } currentFilter.NeedsToBeResolved = false; } for (var i = 0; i < filters.Count; i++) { await ResolveFilterAtIndex(i); } }
public PrimitiveCalculator() { this.additionStrategy = new AdditionStrategy(); this.subtractionStrategy = new SubtractionStrategy(); this.multiplicationStrategy = new MultiplicationStrategy(); this.divisionStrategy = new DivisionStrategy(); this.calculationStrategy = this.additionStrategy; }
private void RecalculateGear() { if (SceneElement == null) { return; } CalculationStrategy.Calculate(this); Rebuild(); }
internal async Task <IEnumerable <DomainResolver <TSource> > > Domains(CalculationStrategy calculationStrategy) { if (!_filters.Any(f => f.NeedsToBeResolved)) { return(_filters.Select(filter => filter.Domain())); } await Resolve(calculationStrategy); return(_filters.Select(filter => filter.Domain())); }
public void MenuShouldBeUsedWhenThereIsSoupAndTimeIsNotWithinRange_Saturday_JustBeforeEnd_Test() { // Arrange DateTime elevenAm = new DateTime(2021, 5, 1, 16, 59, 59); BasePlate[] plates = new BasePlate[] { soupPlate, greyPlate, greyPlate, greenPlate, greenPlate, bluePlate }; CalculationStrategy expectedCalculationStrategy = CalculationStrategy.RegularStrategy; // Act CalculationStrategy chosenCalculationStrategy = this.strategySelector.GetCalculationStrategy(elevenAm, plates); //Assert Assert.Equal(expectedCalculationStrategy, chosenCalculationStrategy); }
public void MenuShouldNotBeUsedWhenThereIsNoSoupAndTimeIsWithinRange_MoreThan4Plates_Test() { // Arrange DateTime elevenAm = new DateTime(2021, 5, 1, 11, 0, 0); BasePlate[] plates = new BasePlate[] { greyPlate, greyPlate, greyPlate, greenPlate, greenPlate, bluePlate }; CalculationStrategy expectedCalculationStrategy = CalculationStrategy.RegularStrategy; // Act CalculationStrategy chosenCalculationStrategy = this.strategySelector.GetCalculationStrategy(elevenAm, plates); //Assert Assert.Equal(expectedCalculationStrategy, chosenCalculationStrategy); }
public void MenuShouldBeUsedWhenThereIsSoupAndTimeIsWithinRange_Monday_AtStart_Test() { // Arrange DateTime elevenAm = new DateTime(2021, 5, 3, 11, 0, 0); BasePlate[] plates = new BasePlate[] { soupPlate, greyPlate, greyPlate, greenPlate, greenPlate, bluePlate }; CalculationStrategy expectedCalculationStrategy = CalculationStrategy.MenuStrategy; // Act CalculationStrategy chosenCalculationStrategy = this.strategySelector.GetCalculationStrategy(elevenAm, plates); //Assert Assert.Equal(expectedCalculationStrategy, chosenCalculationStrategy); }
public void CalculationStrategyShouldReturnCorrectCalculator() { //Arrange CalculationStrategy menuStrategy = CalculationStrategy.MenuStrategy; CalculationStrategy regularStrategy = CalculationStrategy.RegularStrategy; //Act ICalculationService menuBillCalculatorService = this.strategySelector.GetBillCalculatorStrategy(menuStrategy); ICalculationService regularBillCalculatorService = this.strategySelector.GetBillCalculatorStrategy(regularStrategy); bool isMenuType = menuBillCalculatorService is IMenuCalculationService; bool isRegularType = regularBillCalculatorService is IRegularCalculationService; //Assert Assert.True(isMenuType); Assert.True(isRegularType); }
static void Main(string[] args) { IProduct product = new Book("The Little Prince", 12345, new Money(20.25M)); //var tax = new TaxPriceModifier(.20M); //var discount = new Discount().WithDiscount(.15M); ///var specialDiscount = new SpecialUPCDiscount().WithDiscount(.07M).WithUPC(12345); IPriceCalculation priceCalculation = new CalculationStrategy(); //var priceModifiers = new PriceModifiersBuilder().WithTax(tax).WithDiscount(discount).WithDiscount(specialDiscount); // result = priceCalculation.GetPriceResultForProduct(product, priceModifiers); Console.ReadLine(); }
public void ChangeStrategy(char @operator) { switch (@operator) { case '+': this.calculationStrategy = this.additionStrategy; break; case '-': this.calculationStrategy = this.subtractionStrategy; break; case '*': this.calculationStrategy = this.multiplicationStrategy; break; case '/': this.calculationStrategy = this.divisionStrategy; break; } }
public async Task <IEnumerable <DomainResolver <TSource> > > Domains(CalculationStrategy calculationStrategy) { return(await _contextOptions.Domains(calculationStrategy)); }
/// <summary> /// Build the spur gear shaped <see cref="Polygon" />. /// </summary> /// <returns>Returns the spur gear shaped <see cref="Polygon" /> as <see cref="SceneElement" />.</returns> protected override SpurGear CreateGeometry() { return(CalculationStrategy.CreateSpurGear()); }
/// <summary> /// Returns the instance of the IBillCalculatorService to be used for the calculation of the bill /// </summary> /// <param name="paymentDateTime"></param> /// <param name="plates"></param> /// <returns></returns> public ICalculationService GetBillCalculatorStrategy(CalculationStrategy calculationStrategy) { return(this.strategySelector[calculationStrategy]); }
public void Caluclate_ThrowsException_GivenInputIsLessThan0() { CalculationStrategy calculationStrategy = new CalculationStrategy(10); var answer = calculationStrategy.Calculate(-1); }
public void Caluclate_ThrowsException_GivenInputIsGreaterThanTarget() { CalculationStrategy calculationStrategy = new CalculationStrategy(10); var answer = calculationStrategy.Calculate(21); }