Пример #1
0
        public void RefactoredCodeProducesSameResultAsOriginalCode(int age, int weight, int height, double avgHealthPoints)
        {
            // Arrange
            var oldDsfHandler = new OldDsfHandler(new SettingsRepo());

            var actualRequest = new DsfRequest(age, weight, height, avgHealthPoints, "", "", "", "");

            var handler = new CheckBmiRule();

            handler.SetNext(new CheckAgeRule())
            .SetNext(new CheckAvgHealthPointsRule())
            .SetNext(new CalculateDsfFactorRule())
            .SetNext(new CheckAgainstMaxDsfFactorRule())
            .SetNext(new CheckAgainstMinDsfFactorRule());

            // Act
            var expectedDsfValue = oldDsfHandler.GetDecisionSupportFactor(age, weight, height, avgHealthPoints);

            handler.Handle(actualRequest);

            // Assert
            Assert.Equal(expectedDsfValue, actualRequest.DsfFactor);
        }
Пример #2
0
        private static void RunRefactoredImplementation()
        {
            Console.WriteLine("Running refactored implementation");

            var settingsRepo = new SettingsRepo();

            var age                = 36;
            var weight             = 70;
            var height             = 170;
            var avgHealthPoints    = 7.4;
            var minAgeSetting      = settingsRepo.GetSettingAsString("minAge");
            var factorSetting      = settingsRepo.GetSettingAsString("factor");
            var maxDsFactorSetting = settingsRepo.GetSettingAsString("maxDsFactor");
            var minDsFactorSetting = settingsRepo.GetSettingAsString("minDsFactor");

            var request = new DsfRequest(age,
                                         weight,
                                         height,
                                         avgHealthPoints,
                                         minAgeSetting,
                                         factorSetting,
                                         maxDsFactorSetting,
                                         minDsFactorSetting);

            var handler = new CheckBmiRule();

            handler.SetNext(new CheckAgeRule())
            .SetNext(new CheckAvgHealthPointsRule())
            .SetNext(new CalculateDsfFactorRule())
            .SetNext(new CheckAgainstMaxDsfFactorRule())
            .SetNext(new CheckAgainstMinDsfFactorRule());


            handler.Handle(request);

            Console.WriteLine($"Decision support factor: {request.DsfFactor}");
        }