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.");
        }
Пример #2
0
 public MathController(IMathOperationFactory factory)
 {
     _factory = factory;
 }
Пример #3
0
 public MainWindow(IMathOperationFactory operationFactory)
 {
     InitializeComponent();
 }