public async Task testPostLoginSuccessWhenLoginFromHomeDriverRole() { LoginViewModel model = new LoginViewModel(); model.Email = Constants.DEFAULT_EMAIL; model.Password = Constants.DEFAULT_PASSWORD; var controller = ControllerSupplier.getAccountController(); await populateDatabaseWithUser(controller); var userManager = controller.getUserManager(); var user = await userManager.FindByIdAsync(Constants.USER_ID); var code = await userManager.GenerateEmailConfirmationTokenAsync(user); await userManager.ConfirmEmailAsync(user, code); await userManager.AddToRoleAsync(user, AppRole.DRIVER); var result = await controller.Login(model, "Login") as RedirectToActionResult; Assert.NotNull(result); Assert.Equal(result.ControllerName, "DriverDashboard"); Assert.Equal(result.ActionName, "Index"); }
public async Task testDeleteClient() { var controller = ControllerSupplier.getClientsController().Result; //set Shipper to controller var context = controller.getDbContext(); var company = new Company(); var user = context.ApplicationUsers.First <ApplicationUser>(); Client client = getClient(); client.Address.City = Constants.DEFAULT_CITY; company.Clients.Add(client); context.Companies.Add(company); await context.SaveChangesAsync(); Assert.Equal(context.Clients.Count <Client>(), 1); Assert.Equal(context.Addresses.Count <Address>(), 1); controller.setCompany(company); await controller.DeleteConfirmed(client.ID); Assert.Equal(company.Clients.Count, 0); Assert.Equal(context.Clients.Count <Client>(), 0); Assert.Equal(context.Addresses.Count <Address>(), 0); }
public async Task testCreateDeliveryValidModel() { var controller = await ControllerSupplier.getShipperDeliveriesController(); //set Shipper to controller Company company = await createCompany(controller); controller.setCompany(company); var dbContext = controller.getDbContext(); Client client = ShipperDetailsHelper.getClient(); company.Clients.Add(client); await dbContext.SaveChangesAsync(); DeliveryDetails deliveryDetails = new DeliveryDetails(); deliveryDetails.ClientID = client.ID; // deliveryDetails.PickUpAddress = ShipperDetailsHelper.getDeliveryPickUpAddress(); var createResult = await controller.Create(deliveryDetails); var result = (ViewResult)controller.Index().Result; Assert.NotNull(result.Model); Assert.Equal(dbContext.Deliveries.Count(), 1); Delivery delivery = dbContext.Deliveries.ToList().First <Delivery>(); Assert.Equal(delivery.Client, client); Assert.Equal(delivery.DeliveryStatus.Status, Status.New); // Assert.Equal(delivery.PickUpAddress, deliveryDetails.PickUpAddress); }
public async Task testEditVehicle() { var controller = await ControllerSupplier.getVehiclesController(); //set Driver to controller var context = controller.getDbContext(); var driverEntity = new DeliveryService.Models.Entities.Driver(); var user = context.ApplicationUsers.First <ApplicationUser>(); // driverEntity.User = user; context.Drivers.Add(driverEntity); Vehicle vehicle = new Vehicle(); vehicle.RegistrationNumber = "123456"; driverEntity.Vehicles.Add(vehicle); await context.SaveChangesAsync(); controller.setDriver(driverEntity); var result = (ViewResult)controller.Index().Result; Assert.NotNull(result.Model); Assert.Equal(result.Model, driverEntity.Vehicles); var vehicleViewModel = new Vehicle(); vehicleViewModel.ID = vehicle.ID; vehicleViewModel.RegistrationNumber = "1234567"; await controller.Edit(vehicle.ID, vehicleViewModel); Assert.Equal(driverEntity.Vehicles.Count, 1); Assert.Equal(driverEntity.Vehicles.ToList <Vehicle>().First().RegistrationNumber, "1234567"); }
public async Task testGetIndexPageAndCreateClient() { var controller = await ControllerSupplier.getClientsController(); controller.setGoogleMaps(getMockGoogleMaps()); //set Shipper to controller Company company = await createCompany(controller); controller.setCompany(company); var result = (ViewResult)controller.Index().Result; Assert.NotNull(result.Model); Assert.Equal(result.Model, company.Clients); Client newClient = getClient(); var createResult = await controller.Create(newClient); result = (ViewResult)controller.Index().Result; Assert.NotNull(result.Model); Assert.Equal(company.Clients.Count, 1); Client client = company.Clients.First <Client>(); Assert.Equal(result.Model, company.Clients); Assert.NotNull(client.Address); Assert.Equal(client.Address.City, Constants.DEFAULT_CITY); Assert.Equal(client.Address.LineOne, Constants.DEFAULT_ADDRESS_LINE_ONE); Assert.Equal(client.Address.PostCode, Constants.DEFAULT_POSTCODE); }
public async Task testPostLoginIncorrectPassword() { LoginViewModel model = new LoginViewModel(); model.Email = Constants.DEFAULT_EMAIL; model.Password = "******"; var controller = ControllerSupplier.getAccountController(); await populateDatabaseWithUser(controller); var userManager = controller.getUserManager(); var user = await userManager.FindByIdAsync(Constants.USER_ID); var code = await userManager.GenerateEmailConfirmationTokenAsync(user); await userManager.ConfirmEmailAsync(user, code); var result = (ViewResult)await controller.Login(model); Assert.NotEmpty(controller.ViewData.ModelState.Keys); var allErrors = controller.ModelState.Values.SelectMany(v => v.Errors); Assert.Equal(allErrors.First().ErrorMessage, "Invalid login attempt."); Assert.Equal(result.Model, model); }
public async Task testPostRegisterUserAlreadyExists() { DriverRegisterViewModel model = new DriverRegisterViewModel(); model.Email = Constants.DEFAULT_EMAIL; model.Password = Constants.DEFAULT_PASSWORD; model.FirstName = "Matt"; var controller = ControllerSupplier.getAccountController(); var mockUserService = new Mock <IUserService>(); IdentityError error = new IdentityError(); error.Code = "user exists"; error.Description = "user exists"; IdentityResult identityResult = IdentityResult.Failed(error); mockUserService.Setup(m => m.CreateDriverUserAsync(model)).Returns(Task.FromResult <IdentityResult>(identityResult)); controller.userService = mockUserService.Object; var result = (ViewResult)await controller.Register(model); Assert.Equal(result.Model, model); Assert.True(controller.ViewData.ModelState.ErrorCount == 1); var allErrors = controller.ModelState.Values.SelectMany(v => v.Errors); Assert.True(allErrors.First().ErrorMessage.Contains(error.Description)); }
public async Task testGetIndexPageAndAddVehicle() { var controller = await ControllerSupplier.getVehiclesController(); //set Driver to controller var context = controller.getDbContext(); var driverEntity = new DeliveryService.Models.Entities.Driver(); var user = context.ApplicationUsers.First <ApplicationUser>(); // driverEntity.User = user; context.Drivers.Add(driverEntity); await context.SaveChangesAsync(); controller.setDriver(driverEntity); var result = (ViewResult)controller.Index().Result; Assert.NotNull(result.Model); Assert.Equal(result.Model, driverEntity.Vehicles); Vehicle vehicle = new Vehicle(); vehicle.RegistrationNumber = "123456"; var createResult = await controller.Create(vehicle); result = (ViewResult)controller.Index().Result; Assert.NotNull(result.Model); Assert.Equal(driverEntity.Vehicles.Count, 1); Assert.Equal(result.Model, driverEntity.Vehicles); }
// [Fact] public async Task testPostRegisterSuccess() { DriverRegisterViewModel model = new DriverRegisterViewModel(); model.Email = "*****@*****.**"; model.Password = "******"; var controller = ControllerSupplier.getAccountController(); var result = (ViewResult)await controller.Register(model); }
public void testGetResetPasswod() { var controller = ControllerSupplier.getAccountController(); var result = controller.ResetPassword("123"); var viewResult = Assert.IsType <ViewResult>(result); Assert.Null(viewResult.Model); Assert.Equal(viewResult.ViewName, "ResetPassword"); }
public async Task testPostRegisterInvalidModel() { DriverRegisterViewModel model = new DriverRegisterViewModel(); var controller = ControllerSupplier.getAccountController(); controller.ViewData.ModelState.AddModelError("Key", "ErrorMessage"); var result = (ViewResult)await controller.Register(model); Assert.Equal(result.Model, model); }
public async Task testGetConfimEmailWithNullUserId() { var controller = ControllerSupplier.getAccountController(); var result = await controller.ConfirmEmail(null, Constants.CONFIRM_CODE); Assert.NotNull(result); var viewName = ((ViewResult)result).ViewName; Assert.Equal(viewName, "Error"); }
public async Task testGetConfimEmailWithNullConfirmCode() { var controller = ControllerSupplier.getAccountController(); var result = await controller.ConfirmEmail(Constants.USER_ID, null); Assert.NotNull(result); var viewName = ((ViewResult)result).ViewName; Assert.Equal(viewName, "Error"); }
public async Task testPostResetPasswordUserIsNull() { ForgotPasswordViewModel model = new ForgotPasswordViewModel(); model.Email = "*****@*****.**"; var controller = ControllerSupplier.getAccountController(); var result = await controller.ForgotPassword(model) as ViewResult; Assert.Equal(result.ViewName, "ForgotPasswordConfirmation"); }
public async Task testResetPasswordInvalidModelState() { ForgotPasswordViewModel model = new ForgotPasswordViewModel(); var controller = ControllerSupplier.getAccountController(); controller.ViewData.ModelState.AddModelError("Key", "ErrorMessage"); var result = (ViewResult)await controller.ForgotPassword(model); Assert.Equal(result.Model, model); }
public void testGetLogin() { var controller = ControllerSupplier.getAccountController(); var result = controller.Login("return/url"); var viewResult = Assert.IsType <ViewResult>(result); Assert.Equal(viewResult.ViewData["ReturnUrl"], "return/url"); Assert.Null(viewResult.Model); Assert.Equal(viewResult.ViewName, "Login"); }
public void testGetRegister() { var controller = ControllerSupplier.getAccountController(); var result = controller.Register("return/url"); var viewResult = Assert.IsType <ViewResult>(result); Assert.Equal(viewResult.ViewData["ReturnUrl"], "return/url"); Assert.Equal(viewResult.Model.GetType(), typeof(DriverRegisterViewModel)); Assert.Equal(viewResult.ViewName, "Register"); }
public async Task testPostLoginAttemptWithInvalidModel() { LoginViewModel model = new LoginViewModel(); var controller = ControllerSupplier.getAccountController(); controller.ViewData.ModelState.AddModelError("Key", "ErrorMessage"); var result = (ViewResult)await controller.Login(model); Assert.Equal(result.Model, model); }
public async Task testGetConfirmEmailForExistingUserWithWrongCode() { var controller = ControllerSupplier.getAccountController(); await populateDatabaseWithUser(controller); var result = await controller.ConfirmEmail(Constants.USER_ID, "123"); Assert.NotNull(result); var viewName = ((ViewResult)result).ViewName; Assert.Equal(viewName, "Error"); }
public async Task testPostLoginUnknownUser() { LoginViewModel model = new LoginViewModel(); model.Email = Constants.DEFAULT_EMAIL; model.Password = Constants.DEFAULT_PASSWORD; var controller = ControllerSupplier.getAccountController(); var result = (ViewResult)await controller.Login(model); Assert.NotEmpty(controller.ViewData.ModelState.Values); var allErrors = controller.ModelState.Values.SelectMany(v => v.Errors); Assert.Equal(allErrors.First().ErrorMessage, "Invalid login attempt."); Assert.Equal(result.Model, model); }
public void testGetRegisterDriver() { var controller = ControllerSupplier.getAccountController(); string email = "*****@*****.**"; string firstName = "Alex"; var result = controller.RegisterDriver(1, email, firstName, "url"); var viewResult = Assert.IsType <ViewResult>(result); Assert.Equal(viewResult.ViewData["ReturnUrl"], "url"); Assert.Equal(viewResult.Model.GetType(), typeof(DriverRegisterViewModel)); Assert.Equal(viewResult.ViewName, "Register"); var model = (DriverRegisterViewModel)viewResult.Model; Assert.Equal(model.DriverTeamId, "1"); Assert.Equal(model.FirstName, firstName); Assert.Equal(model.Email, email); }
public async Task testPostLoginEmailNotConfirmed() { LoginViewModel model = new LoginViewModel(); model.Email = Constants.DEFAULT_EMAIL; model.Password = Constants.DEFAULT_PASSWORD; var controller = ControllerSupplier.getAccountController(); await populateDatabaseWithUser(controller); var result = (ViewResult)await controller.Login(model); Assert.NotEmpty(controller.ViewData.ModelState.Keys); var allErrors = controller.ModelState.Values.SelectMany(v => v.Errors); Assert.Equal(allErrors.First().ErrorMessage, "You must have a confirmed email to log in."); Assert.Equal(result.Model, model); }
public async Task testPostLogOff() { var controller = ControllerSupplier.getAccountController(); await populateDatabaseWithUser(controller); //sign in a user var userManager = controller.getUserManager(); var user = await userManager.FindByEmailAsync(Constants.DEFAULT_EMAIL); var signInManager = controller.getSignInManager(); await signInManager.PasswordSignInAsync(user.Email, Constants.DEFAULT_PASSWORD, false, lockoutOnFailure : false); var result = await controller.LogOff() as RedirectToActionResult; Assert.NotNull(result); Assert.Equal(result.ControllerName, "Home"); Assert.Equal(result.ActionName, "Index"); }
public async Task testEditClient() { var controller = ControllerSupplier.getClientsController().Result; controller.setGoogleMaps(getMockGoogleMaps()); //set Shipper to controller var context = controller.getDbContext(); var company = new Company(); Client client = getClient(); company.Clients.Add(client); context.Companies.Add(company); await context.SaveChangesAsync(); controller.setCompany(company); var result = (ViewResult)controller.Index().Result; Assert.NotNull(result.Model); Assert.Equal(result.Model, company.Clients); var clientModel = new Client(); //change email and leave the rest as it was clientModel.ID = client.ID; clientModel.Email = "*****@*****.**"; clientModel.FirstName = client.FirstName; clientModel.LastName = client.LastName; clientModel.Address.City = Constants.DEFAULT_CITY; await controller.Edit(client.ID, clientModel); Assert.Equal(company.Clients.ToList <Client>().First().Email, "*****@*****.**"); Assert.Equal(company.Clients.ToList <Client>().First().FirstName, client.FirstName); Assert.Equal(company.Clients.ToList <Client>().First().LastName, client.LastName); Assert.Equal(company.Clients.ToList <Client>().First().Address.City, client.Address.City); }
public async Task testPostRegisterUserFailureInvalidPassword() { DriverRegisterViewModel model = new DriverRegisterViewModel(); model.Email = "*****@*****.**"; model.Password = "******"; var controller = ControllerSupplier.getAccountController(); var mockUserService = new Mock <IUserService>(); IdentityError error = new IdentityError(); error.Code = "invalid password"; error.Description = "invalid password"; IdentityResult identityResult = IdentityResult.Failed(error); mockUserService.Setup(m => m.CreateDriverUserAsync(model)).Returns(Task.FromResult <IdentityResult>(identityResult)); controller.userService = mockUserService.Object; var result = (ViewResult)await controller.Register(model); Assert.Equal(result.Model, model); var allErrors = controller.ModelState.Values.SelectMany(v => v.Errors); Assert.True(allErrors.First().ErrorMessage.Contains(error.Description)); }
static void Main(string[] args) { int pilihan = 0; Item item = new Item(); MyContext _context = new MyContext(); Console.WriteLine("==========Item Data=========="); Console.WriteLine("1. Mangae Suppliers"); Console.WriteLine("2. Manage Items"); Console.WriteLine("3. Transaction"); Console.WriteLine("===================================="); Console.Write("Pilihanmu : "); pilihan = int.Parse(Console.ReadLine()); Console.WriteLine("===================================="); switch (pilihan) { case 1: ControllerSupplier bebas = new ControllerSupplier(); bebas.ManageSupplier(); break; case 2: ControllerItem namanyaapa = new ControllerItem(); namanyaapa.ManageItem(); break; case 3: controllerTransaction bingung = new controllerTransaction(); bingung.ManageTransaction(); break; default: Console.WriteLine("Your Choice is not found, try again see you later good bye."); break; } Console.Read(); }
public async Task testDeleteVehicle() { var controller = await ControllerSupplier.getVehiclesController(); //set Driver to controller var context = controller.getDbContext(); var driverEntity = new DeliveryService.Models.Entities.Driver(); var user = context.ApplicationUsers.First <ApplicationUser>(); //driverEntity.User = user; context.Drivers.Add(driverEntity); Vehicle vehicle = new Vehicle(); vehicle.RegistrationNumber = "123456"; driverEntity.Vehicles.Add(vehicle); await context.SaveChangesAsync(); controller.setDriver(driverEntity); await controller.DeleteConfirmed(vehicle.ID); Assert.Equal(driverEntity.Vehicles.Count, 0); }
public async Task testGetConfirmEmailForExistingUserShipperRole() { var controller = ControllerSupplier.getAccountController(); await populateDatabaseWithUser(controller); var userManager = controller.getUserManager(); var user = await userManager.FindByIdAsync(Constants.USER_ID); await userManager.AddToRoleAsync(user, AppRole.SHIPPER); var code = await userManager.GenerateEmailConfirmationTokenAsync(user); var result = await controller.ConfirmEmail(Constants.USER_ID, code); Assert.NotNull(result); var viewName = ((ViewResult)result).ViewName; Assert.Equal(viewName, "ConfirmEmail"); var dbContext = controller.getApplicationContext(); Assert.Equal(dbContext.Drivers.ToList <Driver>().Count, 0); }