Esempio n. 1
0
        private void CalculateBreakEven()
        {
            if (!CanCalculate())
            {
                return;
            }

            try
            {
                var calculator = new StockCalculator
                {
                    OriginalPrice  = Convert.ToDecimal(StockPrice.Text),
                    NumberOfShares = Convert.ToInt32(NumberOfShares.Text),
                    BrokerageFees  = Convert.ToDecimal(TradeFee.Text)
                };

                var finalAmount = calculator.CalculateBreakEvenPrice();

                LblBreakEvenPrice.Content = $"Break Even Price: ${finalAmount}";
            }
            catch (Exception exception)
            {
                //Do Something
            }
        }
Esempio n. 2
0
        public void CalculateBreakEvenPrice_ReturnsProperValue(decimal originalPrice, decimal fee, int numberOfShares, decimal expected)
        {
            var factory = new StockCalculator
            {
                OriginalPrice  = originalPrice,
                BrokerageFees  = fee,
                NumberOfShares = numberOfShares
            };

            var result = factory.CalculateBreakEvenPrice();

            Assert.Equal(expected, result);
        }
        public void TestCalculateYears0()
        {
            var data = new StockData
            {
                Price      = 200,
                Percentage = 3,
                Quantity   = 17,
                Years      = 0
            };
            var result = StockCalculator.Calculate(data);

            Assert.AreEqual(1, result.Count);
        }
Esempio n. 4
0
        public void CalculateProfit_ReturnsProperValue(decimal originalPrice, decimal currentPrice, decimal fee, int numberOfShares,
                                                       decimal expectedTotal, decimal expetedPerShare)
        {
            var factory = new StockCalculator
            {
                CurrentPrice   = currentPrice,
                NumberOfShares = numberOfShares,
                BrokerageFees  = fee,
                OriginalPrice  = originalPrice
            };

            var result = factory.CalculateProfit();

            Assert.Equal(expectedTotal, result.TotalProfit);
            Assert.Equal(expetedPerShare, result.ProfitPerShare);
        }
        public void TestCalculatePercentage0()
        {
            var data = new StockData
            {
                Price      = 0,
                Percentage = 3,
                Quantity   = 17,
                Years      = 7
            };
            var result = StockCalculator.Calculate(data);

            Assert.AreEqual(data.Years + 1, result.Count);
            foreach (var value in result)
            {
                Assert.AreEqual(result[0], value);
            }
        }
        public void TestCalculatePriceOrQuantity0()
        {
            var data = new StockData
            {
                Price      = 0,
                Percentage = 3,
                Quantity   = 17,
                Years      = 7
            };
            var result = StockCalculator.Calculate(data);

            CheckValues(data, result);
            data.Price    = 200;
            data.Quantity = 0;
            result        = StockCalculator.Calculate(data);
            CheckValues(data, result);
        }
Esempio n. 7
0
        private void CalculateProfits()
        {
            if (!CanCalculateProfit())
            {
                return;
            }

            var calculator = new StockCalculator
            {
                CurrentPrice   = Convert.ToDecimal(CurrentPrice.Text),
                NumberOfShares = Convert.ToInt32(NumberOfSharesOwned.Text),
                OriginalPrice  = Convert.ToDecimal(PricePaid.Text),
                BrokerageFees  = Convert.ToDecimal(BrokerageFee.Text)
            };

            var result = calculator.CalculateProfit();

            LblProfit.Content = $"Total Profit: ${result.TotalProfit:.##}{Environment.NewLine}Profit Per Share: ${result.ProfitPerShare:.##}";
        }
        public void TestCalculateByRegularWay()
        {
            var data = new StockData
            {
                Price      = 200,
                Percentage = 3,
                Quantity   = 17,
                Years      = 6
            };

            var result = StockCalculator.Calculate(data);

            Assert.AreEqual(data.Years + 1, result.Count);
            Assert.AreEqual(data.Price * data.Quantity, result[0]);
            for (int i = 1; i < result.Count; i++)
            {
                Assert.AreEqual(result[i - 1] + result[i - 1] * (decimal)data.Percentage / 100, result[i]);
            }
        }
        //TODO: there are missed tests for double convertion to decimal
        public void TestCalculateByPriceMaxValue()
        {
            var data = new StockData
            {
                Price      = decimal.MaxValue,
                Percentage = 3,
                Quantity   = 17,
                Years      = 6
            };

            try
            {
                StockCalculator.Calculate(data);
                Assert.Fail("An exception with OverflowException type is ecpexted.");
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(OverflowException));
            }
        }
Esempio n. 10
0
        public HttpResponseMessage Calculate(StockDetails details)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(System.Net.HttpStatusCode.BadRequest, ModelState));
            }
            //custom validation for price
            if (details.Price < 0)
            {
                ModelState.AddModelError("Price", string.Format("The value {0} is not valid for the field Price", details.Price));
                return(Request.CreateErrorResponse(System.Net.HttpStatusCode.BadRequest,
                                                   ModelState));
            }
            //Need to encode string before save in repository
            details.Name = HttpUtility.HtmlEncode(details.Name);

            var result     = StockCalculator.Calculate(new StockData(details));
            var repository = new StockHttpApplicationRepository(HttpContext.Current.Application);

            repository.Add(new StockCalculationResult(details, result));
            return(Request.CreateResponse(System.Net.HttpStatusCode.OK, result));
        }
Esempio n. 11
0
        /* public static Presenters Presenters
         * {
         *   get { return presenters; }
         * }*/

        static Program()
        {
            var exePath = Path.GetDirectoryName(Application.ExecutablePath);
            var path    = Path.Combine(exePath, "AppSettings.json");
            var json    = File.ReadAllText(path);

            GlobalObjects.Config = JsonConvert.DeserializeObject <JObject>(json);

            AuditContext auditContext = null;

            try
            {
                auditContext = new AuditContext((string)GlobalObjects.Config["ConnectionStrings"]["Audit"]);
            }
            catch {}
            GlobalObjects.AuditRepository = new AuditRepository(auditContext);
            GlobalObjects.AuditContext    = auditContext;

            var environment = DbTypes.CasEnvironment = new CasEnvironment();

            environment.AuditRepository = GlobalObjects.AuditRepository;
            environment.ApiProvider     = new ApiProvider((string)GlobalObjects.Config["ConnectionStrings"]["ScatTest"]);

            var nonRoutineJobDataAccess      = new NonRoutineJobDataAccess(environment.Loader, environment.Keeper);
            var itemsRelationsDataAccess     = new ItemsRelationsDataAccess(environment);
            var filesDataAccess              = new FilesDataAccess(environment.NewLoader);
            var workPackageRecordsDataAccess = new WorkPackageRecordsDataAccess(environment);


            var storeService              = new StoreCore(environment);
            var aircraftService           = new AircraftsCore(environment.Loader, environment.NewKeeper, environment.NewLoader);
            var compontntService          = new ComponentCore(environment, environment.Loader, environment.NewLoader, environment.NewKeeper, aircraftService, itemsRelationsDataAccess);
            var averageUtilizationService = new AverageUtilizationCore(aircraftService, storeService, compontntService);
            var directiveService          = new DirectiveCore(environment.NewKeeper, environment.NewLoader, environment.Keeper, environment.Loader, itemsRelationsDataAccess);
            var aircraftFlightService     = new AircraftFlightCore(environment, environment.Loader, environment.NewLoader, directiveService, environment.Manipulator, compontntService, environment.NewKeeper, aircraftService);
            var flightTrackService        = new FlightTrackCore(environment.NewLoader, environment.Loader, environment);
            var calculator                 = new Calculator(environment, compontntService, aircraftFlightService, aircraftService);
            var mtopCalculator             = new MTOPCalculator(calculator, aircraftService, averageUtilizationService);
            var planOpsCalculator          = new PlanOpsCalculator(environment.NewLoader, environment.NewKeeper, aircraftService, flightTrackService);
            var performanceCalculator      = new PerformanceCalculator(calculator, averageUtilizationService, mtopCalculator);
            var packageService             = new PackagesCore(environment, environment.NewKeeper, environment.Loader, aircraftService, compontntService);
            var purchaseService            = new PurchaseCore(environment, environment.NewLoader, environment.Loader, packageService, environment.NewKeeper, performanceCalculator);
            var calcStockService           = new StockCalculator(environment, environment.NewLoader, compontntService);
            var documentService            = new DocumentCore(environment, environment.NewLoader, environment.Loader, aircraftService, environment.NewKeeper, compontntService);
            var maintenanceService         = new MaintenanceCore(environment, environment.NewLoader, environment.NewKeeper, itemsRelationsDataAccess, aircraftService);
            var maintenanceCheckCalculator = new MaintenanceCheckCalculator(calculator, averageUtilizationService, performanceCalculator);
            var analystService             = new AnalystCore(compontntService, maintenanceService, directiveService, maintenanceCheckCalculator, performanceCalculator);
            var discrepanciesService       = new DiscrepanciesCore(environment.Loader, environment.NewLoader, directiveService, aircraftFlightService);
            var kitsService                = new KitsCore(environment, environment.Loader, environment.NewKeeper, compontntService, nonRoutineJobDataAccess);
            var smsService                 = new SMSCore(environment.Manipulator);
            var personelService            = new PersonnelCore(environment);
            var transferRecordCore         = new TransferRecordCore(environment.NewLoader, environment.NewKeeper, compontntService, aircraftService, calculator, storeService, filesDataAccess);
            var bindedItemsService         = new BindedItemsCore(compontntService, directiveService, maintenanceService);
            var performanceService         = new PerformanceCore(environment.NewKeeper, environment.Keeper, calculator, bindedItemsService);
            var workPackageService         = new WorkPackageCore(environment, environment.NewLoader, maintenanceService, environment.NewKeeper, calculator, compontntService, aircraftService, nonRoutineJobDataAccess, directiveService, filesDataAccess, performanceCalculator, performanceService, bindedItemsService, workPackageRecordsDataAccess, mtopCalculator, averageUtilizationService);
            var nonRoutineJobService       = new NonRoutineJobCore(environment, workPackageService, nonRoutineJobDataAccess, environment.NewLoader);
            var auditService               = new AuditCore(environment, environment.Loader, environment.NewLoader, environment.NewKeeper, calculator, performanceCalculator, performanceService);

            DbTypes.AircraftsCore = aircraftService;

            GlobalObjects.CasEnvironment             = environment;
            GlobalObjects.PackageCore                = packageService;
            GlobalObjects.PurchaseCore               = purchaseService;
            GlobalObjects.ComponentCore              = compontntService;
            GlobalObjects.AnalystCore                = analystService;
            GlobalObjects.StockCalculator            = calcStockService;
            GlobalObjects.DocumentCore               = documentService;
            GlobalObjects.AuditCore                  = auditService;
            GlobalObjects.MaintenanceCore            = maintenanceService;
            GlobalObjects.WorkPackageCore            = workPackageService;
            GlobalObjects.NonRoutineJobCore          = nonRoutineJobService;
            GlobalObjects.DirectiveCore              = directiveService;
            GlobalObjects.AircraftFlightsCore        = aircraftFlightService;
            GlobalObjects.DiscrepanciesCore          = discrepanciesService;
            GlobalObjects.KitsCore                   = kitsService;
            GlobalObjects.SmsCore                    = smsService;
            GlobalObjects.PersonnelCore              = personelService;
            GlobalObjects.TransferRecordCore         = transferRecordCore;
            GlobalObjects.AircraftsCore              = aircraftService;
            GlobalObjects.ItemsRelationsDataAccess   = itemsRelationsDataAccess;
            GlobalObjects.StoreCore                  = storeService;
            GlobalObjects.BindedItemsCore            = bindedItemsService;
            GlobalObjects.AverageUtilizationCore     = averageUtilizationService;
            GlobalObjects.MaintenanceCheckCalculator = maintenanceCheckCalculator;
            GlobalObjects.MTOPCalculator             = mtopCalculator;
            GlobalObjects.PerformanceCalculator      = performanceCalculator;
            GlobalObjects.PlanOpsCalculator          = planOpsCalculator;
            GlobalObjects.PerformanceCore            = performanceService;
            GlobalObjects.FlightTrackCore            = flightTrackService;

            environment.SetAircraftCore(aircraftService);
            environment.Calculator = calculator;
            environment.Manipulator.PurchaseService    = GlobalObjects.PurchaseCore;
            environment.Manipulator.MaintenanceCore    = GlobalObjects.MaintenanceCore;
            environment.Manipulator.WorkPackageCore    = GlobalObjects.WorkPackageCore;
            environment.Manipulator.AircraftFlightCore = GlobalObjects.AircraftFlightsCore;
            environment.Manipulator.ComponentCore      = GlobalObjects.ComponentCore;
            environment.Manipulator.AircraftsCore      = GlobalObjects.AircraftsCore;
            environment.Manipulator.BindedItemCore     = GlobalObjects.BindedItemsCore;

            InitLoadingVariants();
            InitializePresenters();
        }