public void Test_SearchSituationWhenSituationEXISTInDatabaseAndSituationContainsAlphanumericCharacters_IsValidPropertyReturnsFalse() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); IValidateUserInput _validate = new ValidateUserInput(); ILogger _logger = new MockTruckCheckUpLogger(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validate); //Populate table, so we can test whether there is data available _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act var result = _situationService.EvaluateSituationDescriptionBeforeSearching(new SituationViewModel() { Id = "1", Description = "InProgress88", Status = true, ExistInDB = true, IsValid = true }); //Assert Assert.AreEqual(false, result.IsValid); }
public void Test_UpdateSituationWhenSituationEnteredExistInDatabaseAndDoesNOTContainsOnlyLetters_SituationDescriptionNOTUpdated() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); IValidateUserInput _validate = new ValidateUserInput(); ILogger _logger = new MockTruckCheckUpLogger(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validate); //Populate table, so we can test whether there is data available _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act _situationService.EvaluateSituationDescriptionBeforeUpdating(new SituationViewModel() { Id = "1", Description = "Open88", Status = true, ExistInDB = true, IsValid = true }); var result = _situationService.RetrieveSituationById("1"); //Assert Assert.AreEqual("InProgress", result.Description); }
public void Test_SearchSituationWhenSituationIsEnteredInLowerCaseLettersAndSituationEXISTInDatabase_RetrieveSituationRequested() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); IValidateUserInput _validate = new ValidateUserInput(); ILogger _logger = new MockTruckCheckUpLogger(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validate); //Populate table, so we can test whether there is data available _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act var result = _situationService.EvaluateSituationDescriptionBeforeSearching(new SituationViewModel() { Id = "1", Description = "inprogress", Status = true, ExistInDB = true, IsValid = true }); //Assert Assert.AreEqual("InProgress", result.Description); }
public static void UpdateCustomer() { Console.Write("Please enter customerID :"); var customerID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); using (var db = new RentCDb()) { while (!db.Customers.Any(c => c.CostumerID == customerID)) { Console.WriteLine("Please enter an existing customer"); customerID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); } Customer customer = db.Customers.Find(customerID); DisplayCustomer(customer); Options: Console.WriteLine("Which field do you want to update?"); Console.WriteLine("1. Name"); Console.WriteLine("2. BirthDate"); var ans = Console.ReadLine(); switch (ans) { case "1": Console.Write("Enter Cusomer Name: "); customer.Name = Console.ReadLine(); break; case "2": Console.Write("Enter customer Birth Date: "); customer.BirthDate = ValidateUserInput.ValidateInputDate(Console.ReadLine()); break; default: Console.WriteLine("This is not a valid option!"); goto Options; } Console.WriteLine("New Reservation Data:"); DisplayCustomer(customer); Console.WriteLine("Would you like to modify something else? \n" + "If yes, type YES if no type NO to go back to main menu"); ans = Console.ReadLine(); if (ans == "NO") { MenuPage.SelectOption(); } else if (ans == "YES") { goto Options; } db.SaveChanges(); Console.WriteLine("Customer saved:"); DisplayCustomer(customer); Console.ReadLine(); MenuPage.SelectOption(); } }
public void Test_DeleteSituationDescriptionWhenSituationExist_SituationDescriptionDeletedFromDatabase() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); //Populate table, so we can test whether service is adding records. _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act _situationService.DeleteSituation("2"); var result = _situationService.RetrieveAllSituations(); //Assert Assert.AreEqual(1, result.Count); }
public void Test_ListOfSituations_ReturnsListOfSituationsInDatabase() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act var result = situationController.ListOfSituations() as JsonResult; //Assert dynamic resultData = result.Data; Assert.AreEqual(2, resultData.Count); Assert.AreEqual("2", resultData[0].Id); }
public static void AddCustomer() { Console.Write("Enter Cusomer Name: "); var customerName = Console.ReadLine(); Console.Write("Enter customer Birth Date: "); var customerBirthDate = ValidateUserInput.ValidateInputDate(Console.ReadLine()); Customer customer = new Customer { Name = customerName, BirthDate = customerBirthDate }; using (var db = new RentCDb()) { db.Customers.Add(customer); db.SaveChanges(); } Console.WriteLine("Customer saved:"); DisplayCustomer(customer); Console.ReadLine(); MenuPage.SelectOption(); }
public void Test_DeleteSituationDescriptionByIdWhenSituationExist_SituationDescriptionDeleted() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); //Add some records to populate the Mock table _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act situationController.Delete("2"); //Search for Id deleted to validate deletion var result = situationController.GetSituationById("2"); dynamic resultData = result.Data; //Assert Assert.AreEqual(null, resultData.Description); }
Task IAuthenticationFilter.AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken) { var authHead = context.Request.Headers.Authorization; if (authHead != null) { BOLUserInfo user = ValidateUserInput.GetUser(authHead.Scheme, authHead.Parameter); if (user != null) { var claims = new List <Claim>() { new Claim(ClaimTypes.Name, user.UserName), new Claim(ClaimTypes.Role, user.GetUserRole()) }; var id = new ClaimsIdentity(claims, "Token"); context.Principal = new ClaimsPrincipal(new[] { id }); } else { context.ErrorResult = new UnauthorizedResult( new AuthenticationHeaderValue[0], context.Request); } } return(Task.FromResult(0)); }
private void UpdateProjectTitle(object param) { if (string.Equals(_project.Header, ProjectTitle.Trim())) { return; } if (!ValidateUserInput.IsNullOrWhiteSpace(ProjectTitle)) { ProjectTitle = _project.Header; return; } _projectPath = $".{Path.DirectorySeparatorChar}Projects{Path.DirectorySeparatorChar}{ProjectTitle}{Path.DirectorySeparatorChar}"; try { Directory.Move(_project.Path, _projectPath.Substring(2)); } catch { ProjectTitle = _project.Header; MessageBox.Show("That project already exist"); return; } _project.Header = ProjectTitle; _project.Path = _projectPath; DataBase.UpdateProject((Project)_project); }
public void Test_UpdateSituationDescriptionWhenSituationIsValidAndDoesNOTExistInDatabase_SituationDescriptionUpdated() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); //Add some records to populate the Mock table _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act situationController.Update(new SituationViewModel() { Id = "2", Description = "Opened", Status = true, IsValid = true, ExistInDB = true }); var result = situationController.GetSituationById("2") as JsonResult; dynamic resultData = result.Data; //Assert Assert.AreEqual("Opened", resultData.Description); }
public void AddComment() { if (!ValidateUserInput.IsNullOrWhiteSpace(CommentContent)) { return; } if (_editableComment != null) { var index = Notes.IndexOf(_editableComment); _editableComment.Content = CommentContent; _editableComment.Header = CommentHeader; Notes.Insert(index, _editableComment); Notes.RemoveAt(index + 1); DataBase.UpdateComment(_editableComment); _editableComment = null; } else { var comment = new Comment { SubmitionDate = DateTime.Now, Content = CommentContent, Header = CommentHeader }; DataBase.InsertComment(comment, _project.ID); Notes.Add(comment); } CommentContent = string.Empty; ShowAddNotePanel(); }
public void Test_AddSituationDescriptionInLowerCaseLettersWhenSituationEXISTInDatabaseAndContainsOnlyLetters_SituationNotAddedToDatabase() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); //Populate table, so we can test whether service is adding records. _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act //Add a third record to test _situationService.EvaluateSituationDescriptionBeforeAdding(new SituationViewModel() { Id = "3", Description = "open", Status = true, ExistInDB = false, IsValid = true }); var result = _situationService.RetrieveAllSituations(); //Assert Assert.AreEqual(2, result.Count); }
public void Test_AddSituationDescriptionWhenSituationContainsOnlyLettersAndDoesNotExistInDatabase_SituationAdded() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); //Add _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act var result = situationController.Add(new SituationViewModel() { Id = "", Description = "Open", Status = true, ExistInDB = true, IsValid = true }) as JsonResult; //Assert dynamic resultData = result.Data; Assert.AreEqual(true, resultData.IsValid); }
public void Test_SearchLowerCaseLettersSituationDescriptionWhenSituationIsValidAndExistInDatabase_ExistInDBPropertyReturnsTrue() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); //Add some records to populate the Mock table _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act var result = situationController.SearchSituationDescription(new SituationViewModel() { Id = "", Description = "open", Status = true, IsValid = true, ExistInDB = true }) as JsonResult; //Assert dynamic resultData = result.Data; Assert.AreEqual(true, resultData.ExistInDB); }
public void Test_UpdateSituationDescriptionWhenSituationIsNull_IsValidPropertyReturnsFalse() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); //Add some records to populate the Mock table _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act var result = situationController.Update(new SituationViewModel() { Id = "2", Description = "", Status = true, IsValid = true, ExistInDB = true }); dynamic resultData = result.Data; //Assert Assert.AreEqual(false, resultData.IsValid); }
private void UpdateProjectDescription(object param) { if (!ValidateUserInput.IsNullOrWhiteSpace(Description)) { Description = _project.Content; return; } _project.Content = Description; DataBase.UpdateProject((Project)_project); }
/// <summary> /// Validate a user, also used for retrive username /// </summary> /// <param name="validateUserInput"></param> /// <returns></returns> public async Task <UiUser> ValidateUser(ValidateUserInput validateUserInput) { var user = await this.applicationDbContext.ApplicationUsers.FirstOrDefaultAsync( x => validateUserInput.LastName.Equals(x.LastName, StringComparison.OrdinalIgnoreCase) && validateUserInput.PhoneNumber.Equals(x.PhoneNumber, StringComparison.OrdinalIgnoreCase)); var uiUser = new UiUser { Username = user.Username ?? string.Empty }; return(uiUser); }
public void Test_RetrieveAllSituationsFromDatabase_ZeroSituationsRetrieved() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); //Act var result = _situationService.RetrieveAllSituations(); //Assert Assert.AreEqual(0, result.Count); }
void onAcceptPressed() { ValidateInputEventArgs args = new ValidateInputEventArgs(UserInput); ValidateUserInput?.Invoke(this, args); if (args.ValidationSucceeded) { UserInputAccepted?.Invoke(this, EventArgs.Empty); } else { UserInputRejected?.Invoke(this, EventArgs.Empty); } }
public void Test_Index_IndexActionReturnsIndexView() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act ViewResult result = situationController.Index() as ViewResult; //Assert Assert.IsNotNull(result); }
public void Test_ListOfSituations_ReturnsZeroSituationsInDatabase() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); var situationController = new SituationManagementController(_situationService); //Act var result = situationController.ListOfSituations() as JsonResult; //Assert dynamic resultData = result.Data; Assert.AreEqual(0, resultData.Count); }
static Reservation GetReservation() { Console.WriteLine("Please enter a reservationID"); var reservationID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); using (var db = new RentCDb()) { while (!db.Reservations.Any(r => r.ReservationID == reservationID)) { Console.WriteLine("Please enter a valid reservationID"); reservationID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); } var reservation = db.Reservations.Find(reservationID); ReservationManagement.DisplayReservationInfo(reservation); return(reservation); } }
public async Task <UiUser> ValidateUser([FromBody] ValidateUserInput validateUserInput) { if (!ModelState.IsValid) { return(new UiUser()); } try { return(await this.userService.ValidateUser(validateUserInput)); } catch (Exception exception) { Debug.Write($"An error occured: {exception.Message}"); return(new UiUser()); } }
public void Test_RetrieveAllSituationsFromDatabase_SituationListViewModelObjectReturned() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); bool expected = true; bool actual = false; //Act var result = _situationService.RetrieveAllSituations(); if (result is List <SituationListViewModel> ) { actual = true; } //Assert Assert.AreEqual(expected, actual); }
public void Test_RetrieveSituationRecordByIdWhenSearchingForNonExistentId_ReturnsNullSituationViewModelObject() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); ILogger _logger = new MockTruckCheckUpLogger(); IValidateUserInput _validateUserInput = new ValidateUserInput(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validateUserInput); //Populate table, so we can test whether the method is returning the right record _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act var result = _situationService.RetrieveSituationById("3"); //Assert Assert.AreEqual(null, result.Description); }
public void Test_RetrieveAllSituationsFromDatabase_AllSituationsRetrieved() { //Arrange IRepository <Situation> _situationContext = new MockTruckCheckUpContext <Situation>(); IValidateUserInput _validate = new ValidateUserInput(); ILogger _logger = new MockTruckCheckUpLogger(); ISituationService _situationService = new SituationService(_situationContext, _logger, _validate); //Populate table, so we can test whether there is data available _situationContext.Insert(new Situation() { Id = "1", CreationDate = DateTimeOffset.Now, Description = "InProgress", Status = true }); _situationContext.Insert(new Situation() { Id = "2", CreationDate = DateTimeOffset.Now, Description = "Open", Status = true }); //Act var result = _situationService.RetrieveAllSituations(); //Assert Assert.AreEqual(2, result.Count); }
public void GivenInvalidInput_ReturnsFalse(string invalidInput) { Assert.False(ValidateUserInput.Coordinates(invalidInput)); }
public void GivenValidInput_ReturnsTrue(string validInput) { Assert.True(ValidateUserInput.Coordinates(validInput)); }
public static void DisplayScreen() { Reservation reservation = new Reservation(); Console.Write("Car Plate:"); var carPlate = Console.ReadLine(); var carID = ReservationManagement.ValidateCar(carPlate); reservation.CarID = carID; Console.Write("Client ID:"); var clientID = ValidateUserInput.ValidateInputInt(Console.ReadLine()); reservation.CostumerID = ReservationManagement.ValidateClient(clientID); Console.Write("Start Date(mm.dd.yyyy):"); var startDate = ValidateUserInput.ValidateInputDate(Console.ReadLine()); Console.Write("End Date(mm.dd.yyyy):"); var endDate = ValidateUserInput.ValidateInputDate(Console.ReadLine()); reservation.StartDate = ReservationManagement.ValidateDates(startDate, endDate).Item1; reservation.EndDate = ReservationManagement.ValidateDates(startDate, endDate).Item2; Console.Write("Location:"); var location = Console.ReadLine(); reservation.LocationID = ReservationManagement.ValidateCarLocation(carID, location); List <Nullable <DateTime> > carReserved = ReservationManagement.IsCarAvailabe(carID, startDate, endDate); if (carReserved.Count() > 0) { Console.WriteLine("Car is not available on: " + carReserved); ReservationManagement.DisplayReservationInfo(reservation); } using (var db = new RentCDb()) { Car car = db.Cars.Find(reservation.CarID); var price = car.PricePerDay * (decimal)((endDate - startDate).TotalDays); decimal totalPrice; Console.WriteLine("The car is available for " + car.PricePerDay + "/day"); Console.Write("Do you have a cupone code?\nIf yes enter it, if no type NO: "); var ans = Console.ReadLine(); if (ans.ToUpper() == "NO") { totalPrice = price; } else { var customerCupon = Console.ReadLine(); var cupon = db.Coupons.FirstOrDefault(c => c.CouponCode == customerCupon); if (cupon != null) { Console.WriteLine("Discount: " + cupon.Discount + ": " + cupon.Description); totalPrice = price - (cupon.Discount * price); } totalPrice = price; } Console.WriteLine("Total price: " + totalPrice); Console.WriteLine("Save the reservation? Type YES to save \nNO to go back to main menu: "); ans = Console.ReadLine(); if (ans == "NO") { MenuPage.SelectOption(); } else { reservation.ReservStatsID = 1; db.Reservations.Add(reservation); db.SaveChanges(); } } }