//TEST: USERS_NOPROFILE_TEST //Test the functionality of the User noProfile method using test data. public void Users_noProfile_Test() { //ARRANGE UsersController usersController = new UsersController(); MyDataEntities db = new MyDataEntities(); //ACT ViewResult result = usersController.noProfile() as ViewResult; //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ViewResult)); Assert.AreEqual("noProfile", result.ViewName); }
//TEST: USER_DELETE_FAILURETEST //Test the functionality of the User Delete method when using unintended test data. //Because the User has already been deleted by the previous method, this will result in a value of -1 (signifying a // failure to delete a user), rather than the value of 1 that is returned on the successful deletion of a user. public void Users_Delete_FAILURETest() { SqlSecurityManager manager = new SqlSecurityManager(); //ARRANGE UsersController usersController = new UsersController(); MyDataEntities db = new MyDataEntities(); //ACT int result = manager.Delete("testRegisterUser"); //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(int)); Assert.AreEqual(result, -1); }
//TEST: ORDER_REMOVE_TEST //Test the functionality of the Order Remove method using test data. public void Order_Remove_Test() { //ARRANGE OrderController orderController = new OrderController(); MyDataEntities db = new MyDataEntities(); //Grab the previously created test user and test product and find their IDs var productArray = db.Products.Where(x => x.ProductName == "testProduct").ToList(); var userArray = db.Users.Where(x => x.UserName == "testRegisterUser").ToList(); int testProductID = 0; foreach (var item in productArray) { testProductID = item.ProductID; } int testUserID = 0; foreach (var item in userArray) { testUserID = item.UserID; } //Using the UserID create a list of orders owned by the user (Should cotnain 1 order) and record the orderID var orderArray = db.Orders.Where(x => x.UserID == testUserID).ToList(); int testOrderID = 0; foreach (var item in orderArray) { testOrderID = item.OrderID; } //Using the OrderID and ProductID get the list of OrderProducts (Should contain 1 item) and record its OrderProductID to be // used int he remove method var orderProductArray = db.OrderProducts.Where(x => x.OrderID == testOrderID) .Where(x => x.ProductID == testProductID).ToList(); int testOrderProductID = 0; foreach (var item in orderProductArray) { testOrderProductID = item.OrderProductID; } //ACT ActionResult result = orderController.Remove(testOrderProductID); //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(JsonResult)); }
//TEST: SQLSECURITYMANAGER_LOADUSER_FAILURETEST //Test the functionality of the SqlSecurityManager LoadUser method when using unintended test data. //Loading a username that is not owned by any User will simply return a null User. public void SqlSecurityManager_LoadUser_FAILURETest() { SqlSecurityManager manager = new SqlSecurityManager(); MyDataEntities db = new MyDataEntities(); //ARRANGE User test; string username = "******"; //ACT test = manager.LoadUser(username); //ASSERT Assert.AreEqual(0, test.UserID); Assert.IsNull(test.UserName); Assert.IsNull(test.Password); }
public ActionResult Edit(EmpTable postedData) { //Create the Context object MyDataEntities context = new MyDataEntities(); //Find the matching record var rec = context.EmpTables.FirstOrDefault((e) => e.EmpID == postedData.EmpID); //Set the values to the record rec.EmpName = postedData.EmpName; rec.EmpAddress = postedData.EmpAddress; rec.EmpSalary = postedData.EmpSalary; rec.EmpPhone = postedData.EmpPhone; //Update the record to the database context.SaveChanges();//Commmit the transaction.... //Redirect to the AllEmployees Page.... return(RedirectToAction("AllEmployees")); }
//TEST: SPADDUSER_TEST //Test that adding a user to the database is successful public void spAddUser_Test() { //ARRANGE string testUserName = "******"; string testEmailAddress = "*****@*****.**"; MyDataEntities db = new MyDataEntities(); //ACT ObjectResult <Store.Data.spAddUser_Result> result = db.spAddUser(testUserName, testEmailAddress); //Use the testUserName to get the User object that we just made var item = db.Users.Where(x => x.UserName == testUserName).FirstOrDefault(); string returnUserName = item.UserName; string returnEmailAddress = item.EmailAddress; //ASSERT //Compare the UserName and Password we started with and ensure that the User Object has the same properties. Assert.AreEqual(testUserName, returnUserName); Assert.AreEqual(testEmailAddress, returnEmailAddress); }
public ActionResult Login(Manager account) { using (MyDataEntities mde = new MyDataEntities()) { var user = mde.Managers.Where(a => a.Username.Equals(account.Username) && a.Password.Equals(account.Password)).FirstOrDefault(); if (user != null) { FormsAuthentication.SetAuthCookie(user.Username, false); return(RedirectToAction("Orders")); } else { ViewBag.Error = "Incorrect user or password"; } } ModelState.Remove("Password"); return(View()); }
public ActionResult Login(Table t) { if (ModelState.IsValid) { using (MyDataEntities dc = new MyDataEntities()) { var v = dc.Tables.Where(a => a.UserName.Equals(t.UserName) && a.Password.Equals(t.Password)).FirstOrDefault(); if (v != null) { Session["LogedUserId"]=v.Id.ToString(); Session["LogedUserFullName"]=v.FullName.ToString(); return RedirectToAction("AfterLogin"); } } } return View(t); }
public ActionResult DeleteEvent(int id) { bool status = false; using (MyDataEntities dc = new MyDataEntities()) { var v = dc.Events.Where(a => a.EventId == id).FirstOrDefault(); if (v != null) { dc.Events.Remove(v); dc.SaveChanges(); status = true; } } return(new JsonResult { Data = new { status = status } }); }
//TEST: ORDER_INDEX_TEST //Test the functionality of the Order Index method using test data. public void Order_Index_Test() { //ARRANGE OrderController orderController = new OrderController(); MyDataEntities db = new MyDataEntities(); //Grab the previously created test user and find their ID var array = db.Users.Where(x => x.UserName == "testRegisterUser").ToList(); int testUserID = 0; foreach (var item in array) { testUserID = item.UserID; } //ACT ActionResult result = orderController.ShowIndex(1, testUserID); //ASSERT Assert.IsInstanceOfType(result, typeof(ViewResult)); }
//TEST: PRODUCTS_DETAILS_TEST //Test the functionality of the Product Details method using test data. public void Products_Details_Test() { //ARRANGE ProductsController productsController = new ProductsController(); MyDataEntities db = new MyDataEntities(); //Grab the previously created test product and find its ProductID var array = db.Products.Where(x => x.ProductName == "testProduct").ToList(); int testProductID = 0; foreach (var item in array) { testProductID = item.ProductID; } //ACT ActionResult result = productsController.Details(testProductID); //ASSERT Assert.IsInstanceOfType(result, typeof(ViewResult)); }
//TEST: SPDELETEUSER_TEST //Test that a user can be successfully deleted from the database public void spDeleteUser_Test() { //ARRANGE string testUserName = "******"; MyDataEntities db = new MyDataEntities(); //Grab the user we want to manipulate based on the testUserName parameter var array = db.Users.Where(x => x.UserName == testUserName).ToList(); //ACT int deletedID = 0; foreach (var item in array) { //Deletion check the passed back ID deletedID = db.spDeleteUser(item.UserID); } //ASSERT //If the entry is successfully deleted, the program will return a value of -1. 0 if not successful Assert.AreEqual(-1, deletedID); }
public async Task <string> GetPaged(int pageNo = 1) { // If authentitcated user if (IsLoggedIn()) { // get query to json with paging using (MyDataEntities mde = new MyDataEntities()) { int totalPage, totalRecord, pageSize; pageSize = 5; totalRecord = mde.Orders.Count(); totalPage = (totalRecord / pageSize) + ((totalRecord % pageSize) > 0 ? 1 : 0); // Order records by var query = (from b in mde.Orders join man in mde.Managers on b.ManagerId equals man.ManagerId orderby b.Number select new { OrderId = b.OrderId, Manager = man.Name, Number = b.Number, Created_date = b.Created_date, Delivery_date = b.Delivery_date, Description = b.Description }); var pagedQuery = query.Skip(pageSize * (pageNo - 1)).Take(pageSize); var toJson = await pagedQuery.ToListAsync(); OrdersWithPaging pagedOrders = new OrdersWithPaging { Orders = toJson, TotalPage = totalPage }; var jsonSerialiser = new JavaScriptSerializer(); var json = jsonSerialiser.Serialize(pagedOrders); return(json); } } else { return("You are not authorized to view this"); } }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } MyDataEntities customerEntities = new MyDataEntities(); var q = from r in customerEntities.Products where r.ProductName == value.ToString() select r; if (q.Count() == 0) { return(""); } return(q.FirstOrDefault().ProductID); }
//TEST: SHOPPINGCART_SHOWCART_TEST //Test the functionality of the ShoppingCart ShowCart method using test data. public void ShoppingCart_ShowCart_Test() { //ARRANGE ShoppingCartController shoppingCartController = new ShoppingCartController(); MyDataEntities db = new MyDataEntities(); //Grab the previously created test user and find their ID var initialArray = db.Users.Where(x => x.UserName == "testRegisterUser").ToList(); int testUserID = 0; foreach (var item in initialArray) { testUserID = item.UserID; } //ACT ActionResult result = shoppingCartController.ShowCart(testUserID); //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ViewResult)); }
//TEST: PRODUCT_DELETE_TEST //Test the functionality of the Product Delete method using test data. public void Products_Delete_Test() { //ARRANGE ProductsController productsController = new ProductsController(); MyDataEntities db = new MyDataEntities(); //Grab the test product that we created in Products_Create and find its ProductID var array = db.Products.Where(x => x.ProductName == "testProduct").ToList(); int testProductID = 0; foreach (var item in array) { testProductID = item.ProductID; } //ACT ActionResult result = productsController.Delete(testProductID); //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(JsonResult)); }
//TEST: SHOPPINGCART_DELETE_TEST //Test the functionality of the ShoppingCart Delete method using test data. public void ShoppingCart_Delete_Test() { //ARRANGE ShoppingCartController shoppingCartController = new ShoppingCartController(); MyDataEntities db = new MyDataEntities(); //Grab the test user that we created in Users_Register and find their UserID. This is used to delete the User's cart var userArray = db.Users.Where(x => x.UserName == "testRegisterUser").ToList(); int testUserID = 0; foreach (var item in userArray) { testUserID = item.UserID; } //ACT ActionResult result = shoppingCartController.Delete(testUserID); //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(JsonResult)); }
//TEST: WEBAPI_GETORDERS_TEST //Test the functionality of the WebAPI GetOrders method using test data. public void WebAPI_GetOrders_Test() { MyDataEntities db = new MyDataEntities(); OrderShippingController os = new OrderShippingController(); //ARRANGE db.SaveChanges(); List <Order> list = new List <Order>(); //This time value is equal to 1 minute and the purpose is to subtract the current time by 1 minutes and get all the orders created //within the last minute (we will only find our test order) TimeSpan time = new TimeSpan(0, 1, 0); DateTime startDate = DateTime.Now.Subtract(time); DateTime endDate = DateTime.Now; //ACT list = os.GetOrders(startDate, endDate); //ASSERT Assert.IsNotNull(list); Assert.IsInstanceOfType(list, typeof(List <Order>)); Assert.IsTrue(list.Count() == 1); }
//TEST: SQLSECURITYMANAGER_DELETEUSER_TEST //Test the functionality of the SqlSecurityManager DeleteUser method using test data. public void SqlSecurityManager_DeleteUser_Test() { SqlSecurityManager manager = new SqlSecurityManager(); MyDataEntities db = new MyDataEntities(); //ARRANGE //Grab the test user that we created in SqlSecurityManager_RegisterUser and find their UserID to be used in the Delete method var userArray = db.Users.Where(x => x.UserName == "testSqlUser").ToList(); int testUserID = 0; foreach (var item in userArray) { testUserID = item.UserID; } //ACT int result = manager.Delete("testSqlUser"); //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(int)); Assert.AreEqual(result, 1); }
//TEST: SHOPPINGCART_SHOWCART_FAILURETEST //Test the functionality of the ShoppingCart ShowCart method when using unintended test data. //This will give the method a UserID of a User that does not have their own Shopping Cart. The method will simply redirect // the process back to the homepage rather than returning the Shopping Cart View. public void ShoppingCart_ShowCart_FAILURETest() { ShoppingCartController shoppingCartController = new ShoppingCartController(); MyDataEntities db = new MyDataEntities(); //ARRANGE var initialArray = db.Users.Where(x => x.UserName == "No one").ToList(); int testUserID = 0; foreach (var item in initialArray) { testUserID = item.UserID; } //ACT RedirectResult result = shoppingCartController.ShowCart(testUserID) as RedirectResult; //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(RedirectResult)); Assert.IsTrue(result.Url.Equals("~/Home/Index")); }
//TEST: SPUPDATEUSER_TEST //Test that a user's details can be updated successfully public void spUpdateUser_Test() { //ARRANGE string testUserName = "******"; string testEmailAddress = "*****@*****.**"; MyDataEntities db = new MyDataEntities(); //Grab the user we want to manipulate based on the testUserName parameter var array = db.Users.Where(x => x.UserName == testUserName).ToList(); //We already grabbed the user with our previous UserName, now we can change it to what we want to test testUserName = "******"; //ACT int successfulUpdateID = 0; foreach (var item in array) { //Update + check the passed back ID successfulUpdateID = db.spUpdateUser(item.UserID, testUserName, testEmailAddress); } //ASSERT //If the entry is successfully updated, the program will return a value of -1. 0 if not successful Assert.AreEqual(-1, successfulUpdateID); }
public async Task <string> GetManagers() { if (IsLoggedIn()) { using (MyDataEntities mde = new MyDataEntities()) { //var query = await mde.Managers.ToListAsync(); var query = await(from m in mde.Managers select new { ManagerId = m.ManagerId, Name = m.Name }).ToListAsync(); var jsonSerialiser = new JavaScriptSerializer(); var json = jsonSerialiser.Serialize(query); return(json); } } else { return("You are not authorized to view this"); } }
//TEST: SQLSECURITYMANAGER_LOADUSER_TEST //Test the functionality of the SqlSecurityManager LoadUser method using test data. public void SqlSecurityManager_LoadUser_Test() { SqlSecurityManager manager = new SqlSecurityManager(); MyDataEntities db = new MyDataEntities(); //ARRANGE //Grab the test user that we created in SqlSecurityManager_RegisterUser and find their UserID var userArray = db.Users.Where(x => x.UserName == "testSqlUser").ToList(); int testUserID = 0; foreach (var item in userArray) { testUserID = item.UserID; } //These parameters refer to the test user that we created in SqlSecurityManager_RegisterUser User test; string username = "******"; //ACT test = manager.LoadUser(username); //ASSERT Assert.AreEqual(testUserID, test.UserID); }
public async Task <string> GetAll() { // Get all elements from DB using (MyDataEntities mde = new MyDataEntities()) { var query = (from b in mde.Orders join man in mde.Managers on b.ManagerId equals man.ManagerId orderby b.Number select new { OrderId = b.OrderId, Manager = man.Name, Number = b.Number, Created_date = b.Created_date.ToString(), Delivery_date = b.Delivery_date.ToString(), Description = b.Description }); var toJson = await query.ToListAsync(); var jsonSerialiser = new JavaScriptSerializer(); var json = jsonSerialiser.Serialize(toJson); return(json); } }
public PreventiveRepository(MyDataEntities dbEntity = null) { this.dbEntity = dbEntity ?? new MyDataEntities(); }
public StageRepository(MyDataEntities dbEntity) { this.dbEntity = dbEntity ?? new MyDataEntities(); }
public Item getItems(int id) { db = new MyDataEntities(); return(db.Items.Find(id)); }
public Item[] getItem() { db = new MyDataEntities(); return(db.Items.ToArray()); }
public Producer getProducers(int id) { db = new MyDataEntities(); return(db.Producers.Find(id)); }
public Producer[] getProducer() { db = new MyDataEntities(); return(db.Producers.ToArray()); }
public CustomerRepository(MyDataEntities dbEntity = null) { this.dbEntity = dbEntity ?? new MyDataEntities(); }