public FileStreamResult Get([FromQuery] int?beforeThisYear, int?afterThisYear, int?authorId,
                                    bool?isBestSeller, int docType = 1)
        {
            if (string.IsNullOrEmpty(Request.QueryString.Value))
            {
                throw new ArgumentNullException("QueryParams", "You should provide at least one query parameter");
            }
            var dictionary = Request.QueryString.Value.Replace("?", "").Split('&')
                             .ToDictionary(x => x.Split('=')[0], x => x.Split('=')[1]).Where(s => !string.IsNullOrEmpty(s.Value));

            if (!dictionary.Any())
            {
                throw new ArgumentNullException("QueryParams", "You should provide at least one query parameter");
            }
            ;
            var ls = _bookService.Get(beforeThisYear, afterThisYear, authorId, isBestSeller);

            switch (docType)
            {
            case (int)DocumentType.Word:
                ICreatorService wordReportCreator = new WordReportCreator();
                return(wordReportCreator.CreateReport(ls));

            case (int)DocumentType.Pdf:
                ICreatorService pdfReportCreator = new PdfReportCreator();
                return(pdfReportCreator.CreateReport(ls));

            default:
                throw new InvalidOperationException("Select a valid document type for creating report");
            }
        }
Example #2
0
        public void WordReportCreator_CreateReport_SendNull_NullReferenceException()
        {
            var wordReportCreator = new WordReportCreator();

            Assert.Throws <NullReferenceException>(() => wordReportCreator.CreateReport(null));
        }
Example #3
0
        public void WordReportCreator_CreateReport_SendListOfBooks_FileStreamResult()
        {
            var wordReportCreator = new WordReportCreator();

            Assert.IsType <FileStreamResult>(wordReportCreator.CreateReport(GetMockBookList()));
        }