public void CalculateErrorTypeData_Fail()
        {
            var processor = new ProxyFigureProcessors();

            processor.Init(new CircleValidator(), new CircleCalculator());

            Assert.Throws <InvalidCastException>(() => processor.Calculate(new TriangleDescription()));
        }
        public void Calculate_Success()
        {
            var processor = new ProxyFigureProcessors();

            processor.Init(new CircleValidator(), new CircleCalculator());

            double result = processor.Calculate(new CircleDescription {
                Radius = 1
            });

            Assert.That(Math.PI, Is.EqualTo(result).Within(DoubleHelpers.Tolerance));
        }
        public void ValidateNoValidData_Fail()
        {
            var processor = new ProxyFigureProcessors();

            processor.Init(new CircleValidator(), new CircleCalculator());

            ValidationResult result = processor.Validate(new CircleDescription {
                Radius = 0
            });

            Assert.False(result.IsValid);
        }
        public void ValidDescription_ReturnSuccess()
        {
            var processor = new ProxyFigureProcessors();

            processor.Init(new CircleValidator(), new CircleCalculator());

            var storageMock = new Mock <ProxyFigureStorage>();

            storageMock
            .Setup(x => x.GetProxyFigureProcessor(It.IsAny <IFigureDescription>()))
            .Returns(processor);

            var validator = new ProxyFigureValidator(storageMock.Object);

            Result <Empty> result = validator.Validate(new CircleDescription {
                Radius = 1
            });

            Assert.AreEqual(result.Success, true);
        }
        public void ValidatorReturnFail_ReturnFail()
        {
            var processor = new ProxyFigureProcessors();

            processor.Init(new CircleValidator(), new CircleCalculator());

            var storageMock = new Mock <ProxyFigureStorage>();

            storageMock
            .Setup(x => x.GetProxyFigureProcessor(It.IsAny <IFigureDescription>()))
            .Returns(processor);

            var validator = new ProxyFigureValidator(storageMock.Object);

            var calculator = new ProxyFigureCalculator(storageMock.Object, validator);

            Result <double> result = calculator.Calculate(new CircleDescription {
                Radius = 0
            });

            Assert.AreEqual(result.Fail, true);
        }
        public void PassNullCalculatorOnInit_Throw()
        {
            var processor = new ProxyFigureProcessors();

            Assert.Throws <ArgumentNullException>(() => processor.Init(new CircleValidator(), null));
        }