public void InsertTour_WithValidDetailsWithFutureReminder_NotInserted() { TourViewModel tourViewModel = TourMockData.GetTourViewModel(); tourViewModel.ReminderDate = new DateTime(14, 8, 14); mockTourRepository.Setup(tr => tr.Insert(It.IsAny <Tour>())).Verifiable("Unable to insert Tour"); mockUnitOfWork.Setup(tr => tr.Commit()).Returns(new Tour() { Id = NEW_TOUR_ID }); InsertTourRequest request = new InsertTourRequest() { TourViewModel = TourMockData.CreateMockTourWithCustomValues(mockRepository, 0, 2, 1, 2, new DateTime(2015, 1, 31), new List <ReminderType>() { ReminderType.Email }, new DateTime(2014, 12, 31)).Object }; InsertTourResponse response = new InsertTourResponse(); response = tourService.InsertTour(request); mockRepository.VerifyAll(); Assert.AreEqual(null, response.Exception); Assert.AreNotEqual(typeof(ArgumentNullException), response.Exception); }
public HttpResponseMessage PostTour(TourViewModel viewModel) { InsertTourResponse response = tourService.InsertTour(new InsertTourRequest() { TourViewModel = viewModel }); return(Request.BuildResponse(response)); }
public void InsertTour_WithoutContacts_NotInserted() { mockTourRepository.Setup(tr => tr.Insert(It.IsAny <Tour>())).Verifiable("Unable to insert Tour"); InsertTourRequest request = new InsertTourRequest() { TourViewModel = TourMockData.CreateMockTourWithCustomValues(mockRepository, 0, 0, 3, 10, new DateTime()).Object }; InsertTourResponse response = new InsertTourResponse(); response = tourService.InsertTour(request); Assert.AreNotEqual(null, response.Exception); }
public void InsertTour_ReminderTypeSelectedWithoutReminderDate_NotInserted() { mockTourRepository.Setup(tr => tr.Insert(It.IsAny <Tour>())).Verifiable("Unable to insert Tour"); InsertTourRequest request = new InsertTourRequest() { TourViewModel = TourMockData.CreateMockTourWithCustomValues(mockRepository, 0, 2, 3, 10, new DateTime(2014, 4, 1), new List <ReminderType>() { ReminderType.Email }, null).Object }; InsertTourResponse response = new InsertTourResponse(); response = tourService.InsertTour(request); Assert.AreNotEqual(null, response.Exception); }
public void InsertTour_WithCurrentTourTimeWithReminder_NotInserted() //Business Rule: Reminder cannot be set for past and current times. { mockTourRepository.Setup(tr => tr.Insert(It.IsAny <Tour>())).Verifiable("Unable to insert Tour"); InsertTourRequest request = new InsertTourRequest() { TourViewModel = TourMockData.CreateMockTourWithCustomValues(mockRepository, 0, 2, 3, 10, new DateTime(), new List <ReminderType>() { ReminderType.Email }, new DateTime()).Object }; InsertTourResponse response = new InsertTourResponse(); response = tourService.InsertTour(request); Assert.AreNotEqual(null, response.Exception); }
public void InsertTour_WithCurrentTourTimeWithoutReminder_SuccessfullyInserted() { mockTourRepository.Setup(tr => tr.Insert(It.IsAny <Tour>())); mockUnitOfWork.Setup(tr => tr.Commit()).Returns(new Tour() { Id = NEW_TOUR_ID }); InsertTourRequest request = new InsertTourRequest() { TourViewModel = TourMockData.CreateMockTourWithCustomValues(mockRepository, 0, 2, 3, 10, new DateTime()).Object }; InsertTourResponse response = new InsertTourResponse(); response = tourService.InsertTour(request); //Assert.AreEqual(request.TourViewModel.ReminderDate, new DateTime(2015, 4, 1, 12, 0, 0)); Assert.AreEqual(null, response.Exception); Assert.AreNotEqual(typeof(ArgumentNullException), response.Exception); }
public HttpResponseMessage PostTour(TourViewModel viewModel) { InsertTourResponse response = new InsertTourResponse(); viewModel.CreatedBy = viewModel.CreatedBy; viewModel.CreatedOn = DateTime.Now.ToUniversalTime(); var accountAddress = accountService.GetPrimaryAddress(new GetAddressRequest() { AccountId = (viewModel.AccountId.HasValue && viewModel.AccountId.Value > 0)? viewModel.AccountId.Value:1 }); string accountPhoneNumber = accountService.GetPrimaryPhone(new GetPrimaryPhoneRequest() { AccountId = (viewModel.AccountId.HasValue && viewModel.AccountId.Value > 0) ? viewModel.AccountId.Value : 1 }).PrimaryPhone; Account account = accountService.GetAccountMinDetails((viewModel.AccountId.HasValue && viewModel.AccountId.Value > 0) ? viewModel.AccountId.Value : 1); try { response = tourService.InsertTour(new InsertTourRequest() { TourViewModel = viewModel, RequestedBy = viewModel.CreatedBy, AccountId = (viewModel.AccountId.HasValue && viewModel.AccountId.Value > 0) ? viewModel.AccountId.Value : 1, RequestedFrom = RequestOrigin.API, AccountAddress = accountAddress.Address, AccountPhoneNumber = accountPhoneNumber, AccountPrimaryEmail = account.Email.EmailId, AccountDomain = Request.RequestUri.Host }); } catch (Exception ex) { response.Exception = ex; } if (response.Exception != null) { var message = response.Exception.Message.Replace("[|", "").Replace("|]", ""); response.Exception = new UnsupportedOperationException(message); } return(Request.BuildResponse(response)); }
//[TestMethod] public void InsertTour_WithValidDetailsWithoutReminder_SuccessfullyInserted() { TourViewModel tourViewModel = TourMockData.GetTourViewModel(); mockTourRepository.Setup(tr => tr.Insert(It.IsAny <Tour>())).Verifiable("Unable to insert Tour"); mockUnitOfWork.Setup(tr => tr.Commit()).Returns(new Tour() { Id = NEW_TOUR_ID }); InsertTourRequest request = new InsertTourRequest() { TourViewModel = TourMockData.CreateMockTourWithCustomValues(mockRepository, 10, 2, 1, 5, new DateTime()).Object }; InsertTourResponse response = new InsertTourResponse(); //InsertTourResponse response = tourService.InsertTour(new InsertTourRequest() { TourViewModel = tourViewModel }); //response = tourService.InsertTour(request); mockRepository.VerifyAll(); Assert.AreEqual(null, response.Exception); Assert.AreNotEqual(typeof(ArgumentNullException), response.Exception); }