public IHttpActionResult CalculateQuantitySquareRoom(PaintRequestModelSquareRoom paintInfo) { try { var squareRoom = new SquareRoom { Height = paintInfo.Height, Width = paintInfo.Width, Length = paintInfo.Length }; var coverageInfo = _paintService.CalculateCoverage(squareRoom, paintInfo.PaintId); var quantityInfo = new PaintQuantityResponseModel { PaintInfo = paintInfo, Area = coverageInfo.Area, Volume = coverageInfo.Volume, TinsRequired = coverageInfo.TinsRequired, CoverageM2PerTin = coverageInfo.CoverageM2PerTin }; return(Ok(quantityInfo)); } catch (ArgumentException ae) { return(NotFound()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void Setup() { _paintInfo = new List <IPaintInfo> { new PaintInfo { PaintId = 1, PaintName = "Magnolia", CoverageM2PerTin = 10.00 }, new PaintInfo { PaintId = 2, PaintName = "White", CoverageM2PerTin = 12.00 } }; _coverageInfo = new PaintCoverageInfo { Area = 10, CoverageM2PerTin = 1, Volume = 9, TinsRequired = 2 }; _mockPaintService = new Mock <IPaintService>(); _mockPaintService.Setup(m => m.GetPaints()).Returns(_paintInfo); _mockPaintService.Setup(m => m.CalculateCoverage(It.IsAny <IRoom>(), It.IsAny <int>())) .Returns(_coverageInfo); _paintController = new PaintController(_mockPaintService.Object); _mockFaultyPaintService = new Mock <IPaintService>(); _mockFaultyPaintService.Setup(m => m.GetPaints()).Throws <Exception>(); _mockFaultyPaintService.Setup(m => m.CalculateCoverage(It.IsAny <IRoom>(), _paintId)).Throws <Exception>(); _mockFaultyPaintService.Setup(m => m.CalculateCoverage(It.IsAny <IRoom>(), _missingPaintId)).Throws <ArgumentException>(); _faultyPaintController = new PaintController(_mockFaultyPaintService.Object); _paintRequestModel = new PaintRequestModelSquareRoom() { Height = 0, Length = 0, Width = 0, PaintId = _paintId }; _missingPaintRequestModel = new PaintRequestModelSquareRoom() { Height = 0, Length = 0, Width = 0, PaintId = _missingPaintId }; }