コード例 #1
0
        public HttpResponseMessage GetAll()
        {
            var handler  = new GetAllHandler();
            var response = handler.Handle(0);

            if (handler.Errors == null || handler.Errors.Count < 1)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, response.ReportComponentDtos));
            }
            return(Request.CreateResponse(HttpStatusCode.BadRequest, handler.Errors));
        }
コード例 #2
0
        public void GetAllHandler_ValidatesData()
        {
            //Arrange
            var repository = new Mock <IReportComponentRepository>(MockBehavior.Strict);

            IEnumerable <ReportComponent> list = new List <ReportComponent>()
            {
                new ReportComponent
                {
                    Data = new ComponentData
                    {
                        Dimensions = new List <Dimension> {
                            new Dimension {
                                DimensionId = 1
                            }
                        },
                        Metrics = new List <Metric> {
                            new Metric {
                                MetricId = 1
                            }
                        },
                        Filters = new List <Filter> {
                            new Filter {
                                FilterId = 1
                            }
                        }
                    },
                    Title = "Test",
                    Id    = 1,
                    Type  = 1
                },
                new ReportComponent
                {
                    Data = new ComponentData
                    {
                        Dimensions = new List <Dimension> {
                            new Dimension {
                                DimensionId = 2
                            }
                        },
                        Metrics = new List <Metric> {
                            new Metric {
                                MetricId = 2
                            }
                        },
                        Filters = new List <Filter> {
                            new Filter {
                                FilterId = 2
                            }
                        }
                    },
                    Title = "Test",
                    Id    = 2,
                    Type  = 2
                }
            };

            repository.Setup(x => x.GetAll()).Returns(list);

            var handler = new GetAllHandler(repository.Object);

            //Act
            var result = handler.Handle(0);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ReportComponentDtos[0]);
            Assert.IsNotNull(result.ReportComponentDtos[1]);
        }