public void ShouldHaveInitializedReadOnlyFields() { var assembly = Assembly.GetAssembly(typeof(MainWindow)); var mainWindowTypeInfo = assembly.DefinedTypes.First(t => t.AsType() == typeof(MainWindow)); FieldInfo factoryFieldInfo = mainWindowTypeInfo.DeclaredFields.FirstOrDefault(f => f.FieldType == typeof(IMathOperationFactory)); Assert.That(factoryFieldInfo, Is.Not.Null, "Cannot find a field (class variable) of type 'IMathOperationFactory'."); Assert.That(factoryFieldInfo.IsPrivate, Is.True, $"The field {factoryFieldInfo.Name} should be private."); Assert.That(factoryFieldInfo.IsInitOnly, Is.True, $"The field {factoryFieldInfo.Name} should be readonly."); IMathOperationFactory factoryValue = (IMathOperationFactory)factoryFieldInfo.GetValue(_window); Assert.That(factoryValue, Is.Not.Null, $"The field {factoryFieldInfo.Name} should be initialized in the constructor."); FieldInfo workerFieldInfo = mainWindowTypeInfo.DeclaredFields.FirstOrDefault(f => f.FieldType == typeof(CalculationWorker)); Assert.That(workerFieldInfo, Is.Not.Null, "Cannot find a field (class variable) of type 'CalculationWorker'."); Assert.That(workerFieldInfo.IsPrivate, Is.True, $"The field {workerFieldInfo.Name} should be private."); Assert.That(workerFieldInfo.IsInitOnly, Is.True, $"The field {workerFieldInfo.Name} should be readonly."); CalculationWorker calculationWorkerValue = (CalculationWorker)workerFieldInfo.GetValue(_window); Assert.That(calculationWorkerValue, Is.Not.Null, $"The field {workerFieldInfo.Name} should be initialized in the constructor."); }
public void BeforeEachTest() { _mathOperationFactoryMock = new Mock <IMathOperationFactory>(); _mathOperationFactoryMock.Setup(factory => factory.CreateCubicOperation()).Returns(n => 1); _mathOperationFactoryMock.Setup(factory => factory.CreateNthPrimeOperation()).Returns(n => - 1); _window = new MainWindow(_mathOperationFactoryMock.Object); _window.Show(); _inputTextBox = _window.GetPrivateFieldValueByName <TextBox>("inputTextBox"); _startButton = _window.GetPrivateFieldValueByName <Button>("startButton"); _cubicRadioButton = _window.GetPrivateFieldValueByName <RadioButton>("cubicRadioButton"); _nthPrimeRadioButton = _window.GetPrivateFieldValueByName <RadioButton>("nthPrimeRadioButton"); _calculationProgressBar = _window.GetPrivateFieldValueByName <ProgressBar>("calculationProgressBar"); _outputTextBlock = _window.GetPrivateFieldValueByName <TextBlock>("outputTextBlock"); try { _calculationWorker = _window.GetPrivateFieldValue <CalculationWorker>(); } catch (Exception) { _calculationWorker = null; } _receivedEventArgs = new List <CalculationEventArgs>(); _progressValueChangedCount = 0; }
public CalculationCreateForm(CalculationMain sender) { InitializeComponent(); _sender = sender; this.Focus(); _worker = new CalculationWorker(); CreateSteps(); _currentStep = _steps.FirstOrDefault(x => x.Prev == null); InitCurrentStep(); }
private void BtnCalcClick(object sender, EventArgs e) { btnCalc.Text = "остановить"; var dealFileNames = namesDealFiles.CheckedItems.Cast <string>().ToArray(); statisticMaker = new StatisticMaker(dealFileNames.Select(x => Path.Combine(PathToDealFolder, x)), QuoteFolderName) { DepoCurrency = (string)DepoCurrency.SelectedItem }; CalculationWorker.RunWorkerAsync("MarkupCalculationThread"); }
public void BeforeEachTest() { _worker = new CalculationWorker(); _receivedEventArgs = new List <CalculationEventArgs>(); }