private static ICalculateStrategy GetStrategy(Item item) { ICalculateStrategy calculateStrategy = null; switch (item.Name) { case "Aged Brie": calculateStrategy = new AgedBrieCalculateStrategy(); break; case "Sulfuras, Hand of Ragnaros": calculateStrategy = new SulfurasCalculateStrategy(); break; case "Backstage passes to a TAFKAL80ETC concert": calculateStrategy = new BackstagePassesCalculateStrategy(); break; case "Conjured Mana Cake": calculateStrategy = new ConjuredCalculateStrategy(); break; default: calculateStrategy = new NormalCalculateStrategy(); break; } return(calculateStrategy); }
public void ReturnMustBeZeroFromTotalExpress() { Mock <IItem> mock = new Mock <IItem>(); ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.TOTALEXPRESS); ItemResult itemResult = availableStrategy.Calculate(mock.Object); Assert.True(itemResult.Total == 0); }
public void ReturnMustBeZeroFromJadLog() { Mock <IItem> mock = new Mock <IItem>(); ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.JADLOG); ItemResult itemResult = availableStrategy.Calculate(mock.Object); Assert.True(itemResult.Total == 0); }
public async Task Consume(ConsumeContext <CalculateAccountingPoint> context) { if (await _ercContext.Invoices.AnyAsync(i => i.DsoConsumptionId == context.Message.Id)) { return; } var ac = await _ercContext.AccountingPoints .Include(ac => ac.BranchOffice.CurrentPeriod) .Include(a => a.Exemptions) .ThenInclude(e => e.Category) .Include(a => a.TariffsHistory) .ThenInclude(t => t.Tariff) .FirstOrDefaultAsync(a => a.Eic == context.Message.Eic); if (ac is null) { throw new ArgumentOutOfRangeException("Accounting point not found in the database!"); } ICalculateStrategy calculateStrategy = ac.Commodity == Commodity.NaturalGas ? _serviceProvider.GetRequiredService <GasCalculateStrategy>() : throw new NotImplementedException(); var fromDate = context.Message.FromDate ?? ac.BranchOffice.CurrentPeriod.StartDate; var toDate = context.Message.ToDate ?? ac.BranchOffice.CurrentPeriod.EndDate.AddDays(1); var tariff = ac.TariffsHistory.OrderByDescending(t => t.StartDate).FirstOrDefault(t => t.StartDate <= fromDate).Tariff; var usageT1 = new Usage { PresentMeterReading = context.Message.PresentMeterReadingT1, PreviousMeterReading = context.Message.PreviousMeterReadingT1, Units = context.Message.UsageT1, }; var usageT2 = context.Message.UsageT2.HasValue ? new Usage { PresentMeterReading = context.Message.PresentMeterReadingT2, PreviousMeterReading = context.Message.PreviousMeterReadingT2, Units = context.Message.UsageT2.Value, } : null; var usageT3 = context.Message.UsageT3.HasValue ? new Usage { PresentMeterReading = context.Message.PresentMeterReadingT3, PreviousMeterReading = context.Message.PreviousMeterReadingT3, Units = context.Message.UsageT3.Value, } : null; var newInvoice = new Invoice(context.Message.Id, ac.BranchOffice.CurrentPeriodId, ac.Debt, fromDate, toDate, context.Message.MeterNumber, tariff, (ZoneRecord)context.Message.ZoneRecord, usageT1, usageT2, usageT3, type: ac.BranchOffice.CurrentPeriod.StartDate == fromDate ? InvoiceType.Common : InvoiceType.Recalculation); newInvoice.Calculate(calculateStrategy); ac.AddInvoice(newInvoice); await _ercContext.SaveChangesAsync(); }
public void MustReturnTaxFromTotalExpress() { Mock <IItem> mock = new Mock <IItem>(); IItem item = mock.Object; ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.TOTALEXPRESS); ItemResult itemResult = availableStrategy.Calculate(item); Assert.Equal(0.15, itemResult.TransportTax); }
public void MustReturnTaxFromFedex() { Mock <IItem> mock = new Mock <IItem>(); IItem item = mock.Object; ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.FEDEX); ItemResult itemResult = availableStrategy.Calculate(item); Assert.Equal(0.65, itemResult.TransportTax); }
public void MustReturnTaxFromCorreios() { Mock <IItem> mock = new Mock <IItem>(); IItem item = mock.Object; ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.CORREIOS); ItemResult itemResult = availableStrategy.Calculate(item); Assert.Equal(0.80, itemResult.TransportTax); }
private static void InstanciateObjects() { _faceUnlock = new FaceUnlock(); _fingerPrintUnlock = new FingerprintUnlock(); _chromeBrowser = new ChromeBrowser(); _torBrowser = new TorBrowser(); _addition = new AdditionCalculator(); _division = new DivisionCalculator(); }
public void SetCalculateStrategy(ICalculateStrategy Stategy) { this.Stategy = Stategy; foreach (UCWatchPanelCenter UCCenter in WatchPanelCenters) { UCCenter.SetCalculateStrategy(Stategy); } UCCenterTotal.SetCalculateStrategy(Stategy); }
public void ReturnMustBeGreaterThanZeroFromTotalExpress() { Mock <IItem> mock = new Mock <IItem>(); mock.SetupProperty(item => item.Quantity, 5); mock.SetupProperty(item => item.Price, 125.5); ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.TOTALEXPRESS); ItemResult itemResult = availableStrategy.Calculate(mock.Object); Assert.True(itemResult.Total > 0); }
static bool DoCalculate(ICalculateStrategy Strategy, ICalculator Calc) { if (!Strategy.StartCalculating()) return false; while (Strategy.ReadAndExecuteNextAction()) { Console.WriteLine("\nТекущее значение: {0}\n", Calc.CurrentValue); } return true; }
public CalculateFreight(ICalculateStrategy strategy) { _strategy = strategy; }
public void SetCalculateStrategy(ICalculateStrategy Stategy) { this.Stategy = Stategy; }
public void ChangeStrategy(char @operator) { this.currentStrategy = this.strategies.FirstOrDefault(strat => strat.Operator == @operator); }
public void SetStrategy(ICalculateStrategy calculateStrategy) { _calculateStrategy = calculateStrategy; }
public ProductValueCalculator(ICalculateStrategy strategy) { this.strategy = strategy; }
private void InitializeStrategy() { this.currentStrategy = this.strategies.FirstOrDefault(strat => strat.Operator == '+'); }
public CalculateClient(ICalculateStrategy strategy) { calculateStrategy = strategy; }
internal PhoneModel(IUnlockStategy unlockPhone, IBrowseWebStrategy browseWeb, ICalculateStrategy calculate) { _unlockPhone = unlockPhone; _browseWeb = browseWeb; _calculate = calculate; }