Пример #1
0
        public void AbstractFactoryTest()
        {
            // The client code can work with any concrete factory class.
            const int firstExpectedResult = 2;

            ClientMethod(new ConcreteFactory1());
            _productA.AddingFunction(1).Should().Be(firstExpectedResult);
            _productB.UsefulFunctionB().Should().Be(Text.ResultB1);
            _productB.AnotherUsefulFunctionB(_productA).Should()
            .Be(Text.WithTheResultFromTheFirstFunction(firstExpectedResult));

            const int secondExpectedResult = 3;

            ClientMethod(new ConcreteFactory2());
            _productA.AddingFunction(1).Should().Be(secondExpectedResult);
            _productB.UsefulFunctionB().Should().Be(Text.ResultB2);
            _productB.AnotherUsefulFunctionB(_productA).Should()
            .Be(Text.WithTheResultFromTheSecondFunction(secondExpectedResult));
        }
Пример #2
0
        // The variant, Product B1, is only able to work correctly with the
        // variant, Product A1. Nevertheless, it accepts any instance of
        // AbstractProductA as an argument.
        public string AnotherUsefulFunctionB(IAbstractProductA collaborator)
        {
            var result = collaborator.AddingFunction(1);

            return(Text.WithTheResultFromTheFirstFunction(result));
        }