public void TestMainWindowModel_PrimeFactors_NonNegativeInteger() { var mockModel = new Mock <IMainWindowModel>(); mockModel.SetupProperty(model => model.Algorithms, new ObservableCollection <AlgorithmItemModel>() { new AlgorithmItemModel(new PrimeFactorsAlgorithm()) }); mockModel.SetupProperty(model => model.SelectedAlgorithm, mockModel.Object.Algorithms[0]); mockModel.SetupProperty(model => model.Input, "Incorrect Input Format"); var viewModel = new MainWindowViewModel(mockModel.Object); Utils.CalculationResult expectedResult = new Utils.CalculationResult(false, Utils.Message_NonNegativeInteger); Utils.CalculationResult actualResult = viewModel.RunCalculation(); Assert.AreEqual(expectedResult, actualResult); }
public void TestMainWindowModel_AddsFifty_Pass() { var mockModel = new Mock <IMainWindowModel>(); mockModel.SetupProperty(model => model.Algorithms, new ObservableCollection <AlgorithmItemModel>() { new AlgorithmItemModel(new AddFiftyAlgorithm()) }); mockModel.SetupProperty(model => model.SelectedAlgorithm, mockModel.Object.Algorithms[0]); mockModel.SetupProperty(model => model.Input, "123"); var viewModel = new MainWindowViewModel(mockModel.Object); Utils.CalculationResult expectedResult = new Utils.CalculationResult(true, "173"); Utils.CalculationResult actualResult = viewModel.RunCalculation(); Assert.AreEqual(expectedResult, actualResult); }
public async void CalculateAction() { try { if (ValidateCalculationStart()) { DisplayCalculationStarted(); await Task.Run(() => { //Some algorithms will complete too quickly for the user to see. //We want to make sure the user knows the Calculate button has been clicked and that the input is being worked on. //Adding a short thread sleep so the UI can update with processing messages before the results are displayed. System.Threading.Thread.Sleep(250); //Run the Calculate method from the selected Algorithm Utils.CalculationResult calculationResult = RunCalculation(); if (calculationResult._Valid) { _MainWindowModel.Output = calculationResult._Result; SendStatusUpdate(Utils.Status_Ready); } else { ShowErrorMessage(calculationResult._Result); } }); } } catch (Exception ex) { ShowErrorMessage(ex.Message); } CalculateActionComplete(); }