コード例 #1
0
        public async Task <Result <CalcAreaResponseData> > Handle(CalcAreaRequest request, CancellationToken cancellationToken)
        {
            Figure dbFigure = await _queryFactory.RetrieveFigure(request.FigureId);

            if (dbFigure == null)
            {
                return(Result <CalcAreaResponseData> .MakeFailMessage("figure not found"));
            }

            Result <Type> descType = _descriptionProvider.GetDescriptionType(dbFigure.Type);

            if (descType.Fail)
            {
                return(Result <CalcAreaResponseData> .MakeFailMessage("figure not found"));
            }

            if (!(JsonConvert.DeserializeObject(dbFigure.Description, descType.Data)
                  is IFigureDescription description))
            {
                return(Result <CalcAreaResponseData> .MakeFailMessage("figure not found"));
            }

            Result <double> result = _figureCalculator.Calculate(description);

            if (result.Success)
            {
                return(Result <CalcAreaResponseData> .MakeSucces(new CalcAreaResponseData { Area = result.Data }));
            }
            else
            {
                return(Result <CalcAreaResponseData> .MakeFail(result.Errors));
            }
        }
コード例 #2
0
        public void StorageReturnNull_ReturnFail()
        {
            var storageMock = new Mock <ProxyFigureStorage>();

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

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

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

            Assert.AreEqual(result.Fail, true);
        }
コード例 #3
0
        public void ValidatorReturnSuccess_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);

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

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

            Assert.AreEqual(result.Success, true);
        }