Esempio n. 1
0
        public void ValidatorReturnsFalseForInvalidToDateFormat()
        {
            ListETRAMeetingsRequest request = GetValidListETRAMeetingsRequest();

            request.ToDate = "01-01-2020";
            _listETRAMeetingsRequestValidator.ShouldHaveValidationErrorFor(r => r.ToDate, request.ToDate);
        }
Esempio n. 2
0
        public void CanGetListOfETRAMeetingsByDateRange()
        {
            ListETRAMeetingsRequest request = new ListETRAMeetingsRequest()
            {
                FromDate = "2019-04-01", ToDate = "2019-04-30"
            };

            List <ETRAMeeting> response = new List <ETRAMeeting>()
            {
                new ETRAMeeting()
                {
                    Name = "TEST ETRA meeting"
                }
            };

            _eTRAMeetingsGateway.Setup(_ => _.GetETRAMeetingsByDateRange(request.FromDate, request.ToDate)).Returns(response);

            var results = _eTRAMeetingsUseCase.Execute(request);

            Assert.NotNull(results);
            Assert.True(results is ListETRAMeetingsResponse);
            Assert.True(results.ETRAMeetings.First() is ETRAMeeting);
            Assert.True(results.Request is ListETRAMeetingsRequest);

            Assert.Equal(response.FirstOrDefault().Name, results.ETRAMeetings.FirstOrDefault().Name);
        }
Esempio n. 3
0
        public void ValidatorReturnsFalseForEmptyToDate()
        {
            ListETRAMeetingsRequest request = GetValidListETRAMeetingsRequest();

            request.ToDate = "";
            _listETRAMeetingsRequestValidator.ShouldHaveValidationErrorFor(r => r.ToDate, request.ToDate);
        }
Esempio n. 4
0
        public void ValidatorReturnsFalseForMissingFromDate()
        {
            ListETRAMeetingsRequest request = GetValidListETRAMeetingsRequest();

            request.FromDate = null;
            _listETRAMeetingsRequestValidator.ShouldHaveValidationErrorFor(r => r.FromDate, request.FromDate);
        }
Esempio n. 5
0
        public void ValidatorReturnsTrueForFromDateBeingBeforeToDate()
        {
            ListETRAMeetingsRequest request = GetValidListETRAMeetingsRequest();
            var validationResult            = _listETRAMeetingsRequestValidator.Validate(request);

            Assert.True(validationResult.IsValid);
        }
Esempio n. 6
0
        public void ValidatorReturnsFalseForFromDateBeingAfterToDate()
        {
            ListETRAMeetingsRequest request = GetValidListETRAMeetingsRequest();

            request.FromDate = "2019-04-30";
            request.ToDate   = "2019-04-01";
            var validationResult = _listETRAMeetingsRequestValidator.Validate(request);

            Assert.False(validationResult.IsValid);
            Assert.Equal("fromDate cannot be after toDate", validationResult.Errors[0].ErrorMessage);
        }
Esempio n. 7
0
        public void ExecuteReturnsResponseUsingsGatewayResults()
        {
            ListETRAMeetingsRequest request = new ListETRAMeetingsRequest()
            {
                FromDate = "2019-04-01", ToDate = "2019-04-30"
            };

            List <ETRAMeeting> response = new List <ETRAMeeting>()
            {
                new ETRAMeeting()
                {
                    Name = "TEST ETRA meeting"
                }
            };

            _eTRAMeetingsGateway.Setup(_ => _.GetETRAMeetingsByDateRange(request.FromDate, request.ToDate)).Returns(response);

            var gwResponse = _eTRAMeetingsUseCase.Execute(request);

            _eTRAMeetingsGateway.Verify(gw => gw.GetETRAMeetingsByDateRange(request.FromDate, request.ToDate));
        }
Esempio n. 8
0
        public IActionResult GetETRAMeetingsByDateRange([FromQuery] ListETRAMeetingsRequest request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState.Values.SelectMany(x => x?.Errors?.Select(y => y?.ErrorMessage))));
                }

                var meetings = _listETRAMeetings.Execute(request);

                return(Ok(meetings));
            }
            catch (Exception ex) when(ex is MaTReportingApiBaseException)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"{ex.GetType().Name.ToString()} : {ex.Message}"));
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Esempio n. 9
0
        public ListETRAMeetingsResponse Execute(ListETRAMeetingsRequest request)
        {
            var result = _eTRAMeetingsGateway.GetETRAMeetingsByDateRange(request.FromDate, request.ToDate);

            return(new ListETRAMeetingsResponse(result, request, DateTime.Now, result.Count, result.Sum(x => x.NoOfActions)));
        }
Esempio n. 10
0
        public void ValidatorReturnsTrueForValidToDateFormat()
        {
            ListETRAMeetingsRequest request = GetValidListETRAMeetingsRequest();

            _listETRAMeetingsRequestValidator.ShouldNotHaveValidationErrorFor(r => r.ToDate, request.ToDate);
        }