public async Task <IActionResult> GetInvalidMoveinDates(GetInvalidMoveinDatesRequest invalidMoveinDatesRequest) { IActionResult result; _logger.LogInformation($"GetInvalidMoveinDates({nameof(invalidMoveinDatesRequest)}: {invalidMoveinDatesRequest.ToJson()})"); try { if (!ModelState.IsValid) { _logger.LogInformation($"Model invalid: {invalidMoveinDatesRequest}"); return(BadRequest(ModelState)); } var dates = new GetInvalidMoveinDatesResponse() { InvalidMoveinDates = _moveInLogic.GetInvalidMoveinDates(invalidMoveinDatesRequest), }; result = Ok(dates); } catch (Exception ex) { _logger.LogError(ex, $"Unable to get invalid movein dates for DateFrom: {invalidMoveinDatesRequest.DateFrom} to DateTo: {invalidMoveinDatesRequest.DateTo}", ex.Message); result = ex.ToActionResult(); } return(result); }
public void GetInvalidMoveinDates_Valid_Request_Returns_Valid_Response() { // Arrange var dateList = new List <DateTimeOffset>(); for (int i = 0; i < 5; i++) { dateList.Add(DateTime.Now.AddDays(i)); } MoveInLogicMock.Setup(m => m.GetInvalidMoveinDates(It.IsAny <GetInvalidMoveinDatesRequest>())).Returns(dateList); var controller = GetController(); var request = new GetInvalidMoveinDatesRequest { DateFrom = DateTime.Now, DateTo = DateTime.Now.AddMonths(3), }; // Act var response = controller.GetInvalidMoveinDates(request); // Assert var result = ((OkObjectResult)response.Result).Value as GetInvalidMoveinDatesResponse; result.ShouldNotBeNull(); result.InvalidMoveinDates.ShouldNotBeNull(); result.InvalidMoveinDates.Count.ShouldBe(5); }
public void GetInvalidMoveinDates_Returns_GetInvalidMoveinDatesResponse_Given_Valid_Input() { //Arrange var sampleResponse = JsonConvert.DeserializeObject <McfResponse <GetHolidaysResponse> >(GetHolidaysResponse.GetSampleData()); _mcfClientMock.Setup(mcm => mcm.GetInvalidMoveinDates(It.IsAny <GetInvalidMoveinDatesRequest>())) .Returns(sampleResponse); var target = new MoveInLogic( _loggerMock.Object, _mcfClientMock.Object, _addressApi.Object, _accountApi.Object, _deviceApiMock.Object, _customerMock.Object); //Act var request = new GetInvalidMoveinDatesRequest { DateFrom = DateTime.Now, DateTo = DateTime.Now.AddMonths(1), }; var actual = target.GetInvalidMoveinDates(request); //Assert actual.ShouldNotBeNull(); actual.Count.ShouldBe(6); }
/// <inheritdoc/> public List <DateTimeOffset> GetInvalidMoveinDates(GetInvalidMoveinDatesRequest invalidMoveinDatesRequest) { List <DateTimeOffset> dates = null; var mcfResponse = _mcfClient.GetInvalidMoveinDates(invalidMoveinDatesRequest); if (mcfResponse != null) { // Note verified with Vikas/Bimba that HolidaysResultList will always return a list with one element. dates = new List <DateTimeOffset>(); foreach (Holiday holiday in mcfResponse.Result.HolidaysResultList[0].HolidaysNav.Holidays) { dates.Add(holiday.Date); } } return(dates); }