コード例 #1
0
        public void Get_ps傳入_ZipID傳入11_RoadCode傳入000010_回傳南港區八德路路四段()
        {
            // arrange

            #region "expected parameter"

            var expected = new List<RoadDto>
            {
                new RoadDto
                {
                    CityCode = "0000",
                    Lat = 25.049019018922177,
                    Lng = 121.58821307391959,
                    RoadCode = "000328",
                    RoadEName = "Sec. 6, Zhongxiao E. Rd.",
                    RoadName = "忠孝東路六段",
                    UseFlag = "Y",
                    ZipCode = "115",
                    ZipID = 11
                }
            };

            #endregion "expected parameter"

            #region "roads parameter"

            var roads = new List<RoadModel>
            {
                new RoadModel
                {
                    CityCode = "0000",
                    Lat = 25.049019018922177,
                    Lng = 121.58821307391959,
                    RoadCode = "000328",
                    RoadEName = "Sec. 6, Zhongxiao E. Rd.",
                    RoadName = "忠孝東路六段",
                    UseFlag = "Y",
                    ZipCode = "115",
                    ZipID = 11
                }
            };

            #endregion "roads parameter"

            IRoadRepository repository = Substitute.For<IRoadRepository>();
            repository.Get(Arg.Any<RoadParameterModel>()).Returns(roads);

            var sut = new RoadService();
            sut.RoadRepository = repository;

            // act
            var actual = sut.Get(new RoadParameter() { ZipID = 11, RoadCode = "000010" });

            // assert
            expected.ToExpectedObject().ShouldEqual(actual);
        }
コード例 #2
0
        public HttpResponseMessage Get([FromUri]  RoadParameter parameter)
        {
            //驗證參數的正確性
            var validator = new RoadParameterValidator();
            var results = validator.Validate(parameter);
            var errors = results.Errors;

            if (errors.Any() == true)
            {
                string errorMessage = errors.Select(x => x.ErrorMessage).Aggregate((current, next) => current + ", " + next);
                throw new System.InvalidOperationException(errorMessage);
            }

            var service = new RoadService();
            var roads = service.Get(parameter);

            return this.GenerateSuccessResponse(parameter, roads);
        }