public async Task <IHttpActionResult> Get(int userRewardAccountTransactionTypeTranslationId, int numChildLevels) { try { if (!base.OnActionExecuting(out HttpStatusCode httpStatusCode, out string message)) { return(Content(httpStatusCode, message)); } var dbItem = await Repo.Get_UserRewardAccountTransactionTypeTranslationAsync(userRewardAccountTransactionTypeTranslationId, numChildLevels); if (dbItem == null) { Warn("Unable to get object via Web API", LogMessageType.Instance.Warn_WebApi, httpResponseStatusCode: 404, url: Request.RequestUri.ToString()); return(NotFound()); } RunCustomLogicOnGetEntityByPK(ref dbItem, userRewardAccountTransactionTypeTranslationId, numChildLevels); return(Ok(_factory.Create(dbItem))); } catch (Exception ex) { Error(message: ex.Message, logMessageType: LogMessageType.Instance.Exception_WebApi, ex: ex); if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } return(InternalServerError()); } }
public void should_resolve_generic_instances_duck() { var factory = new GenericFactory <ISpeek>(); ISpeek speek = factory.Create <Duck>(); Assert.Equal("Duck is speaking~.", speek.Speek()); }
public void FillProductList() { int i = 0; List <string[]> productData = DataLayer.GetTableData("STLProduct"); foreach (String[] row in productData) { Guid uid = Guid.NewGuid(); DataLayer.RemoveCriteria(); DataLayer.SetCriteria("RawMaterial_ID", "RawMaterial_RawMaterial_ID"); DataLayer.SetCriteria("STLProduct_STLProduct_ID", row[0]); List <string[]> rawMaterials = DataLayer.GetTableData("STLProduct_has_RawMaterial", "RawMaterial", new string[] { "materialName", "Quantity" }); string[,] materials = new string[rawMaterials.Count, 2]; foreach (String[] mat in rawMaterials) { materials[i, 0] = mat[0]; materials[i, 1] = mat[1]; i++; } GenericFactory <IProduct> .Register(uid, () => new Product(Convert.ToInt16(row[0]), row[1], row[2], Convert.ToDouble(row[3]), Convert.ToDouble(row[4]), materials)); IProduct product = GenericFactory <IProduct> .Create(uid); ProductList.Add(product); i = 0; } }
public void FillWorkOrderList() { List <string[]> lineItemData = DataLayer.GetTableData("WorkOrder"); string[] columns = { "WorkOrder_ID", "dateRequired", "Customer_customer_ID", "Quantity" }; List <string[]> workOrderData = DataLayer.GetTableData("WorkOrder", columns); foreach (String[] row in workOrderData) { string[] columns1 = { "STLProduct_STLProduct_ID" }; DataLayer.RemoveCriteria(); DataLayer.SetCriteria("WorkOrder_WorkOrder_ID", row[0]); List <string[]> workOrderData1 = DataLayer.GetTableData("WorkOrder_has_STLProduct", "WorkOrder", columns1); foreach (String[] row1 in workOrderData1) { Guid uid = Guid.NewGuid(); GenericFactory <IWorkOrder> .Register(uid, () => new WorkOrder(Convert.ToInt16(row[0]), Convert.ToInt16(row[2]), Convert.ToInt16(row1[0]), Convert.ToInt16(row[3]), DateTime.ParseExact(row[1], "dd/MM/yyyy", null))); IWorkOrder workOrder = GenericFactory <IWorkOrder> .Create(uid); workOrderList.Add(workOrder); } } }
public void should_resolve_generic_instances_goat() { var factory = new GenericFactory <ISpeek>(); ISpeek speek = factory.Create <Goat>(); Assert.Equal("I am a goat.", speek.Speek()); }
public void Execute(object parameter) { // Especificamos null ya que el método CreateInstance no reconoce los parámetros con // valores por defecto var masterViewModel = GenericFactory <CreateServicioMasterViewModel> .Create((MemoryContext)parameter, null); NavigationService.Current.PushAsync(GenericFactory <CreateServicioMasterView> .Create(masterViewModel)); }
void GenericHelperScalar <T>() where T : struct { var value = GenericFactory.Create <T>(); var nullable = GenericFactory.Create <T?>(); Assert.AreEqual(value, default(T)); Assert.AreEqual(nullable, default(T?)); GenericCompareTrue(value, default(T)); GenericCompareTrue(nullable, default(T?)); }
//NUnit workaround. It can't compare two null arrays void GenericHelperArraySegment() { var value = GenericFactory.Create <ArraySegment <byte> >(); var nullable = GenericFactory.Create <ArraySegment <byte>?>(); Assert.IsNull(value.Array); Assert.AreEqual(0, value.Count); Assert.AreEqual(0, value.Offset); Assert.IsNull(nullable); }
public static void AddLineItem(int lineid, int qty, double unitPrice, double linePrice, double vat, int productID) { Guid uid = Guid.NewGuid(); GenericFactory <ILineItem> .Register(uid, () => new LineItem( lineid, qty, unitPrice, linePrice, vat, productID)); ILineItem line = GenericFactory <ILineItem> .Create(uid); _data.AddRow("STL_LineItem", new string[] { "Quantity", "UnitPrice", "LinePrice", "VAT", "STLProduct_ID" }, new string[] { qty.ToString(), unitPrice.ToString(), linePrice.ToString(), vat.ToString(), productID.ToString() }); model.FillLineItemList(); }
public static void AddProduct(int prodID, string prodName, string prodInstructions, double price, double vat) { Guid uid = Guid.NewGuid(); GenericFactory <IProduct> .Register(uid, () => new Product(prodID, prodName, prodInstructions, price, vat)); ILineItem line = GenericFactory <ILineItem> .Create(uid); _data.AddRow("STLProduct", new string[] { "STLProduct_ID", "productName", "manufacturingInstructions", "productPrice", "VAT" }, new string[] { prodID.ToString(), prodName, prodInstructions, price.ToString(), vat.ToString() }); model.FillProductList(); }
public static void AddCustomProduct(int prodId, string productName, string productDescription, int quantity, int rfqId) { Guid uid = Guid.NewGuid(); GenericFactory <IProduct> .Register(uid, () => new Product(prodId, productName, productDescription, quantity, rfqId)); IProduct prod = GenericFactory <IProduct> .Create(uid); _data.AddRow("CustomProduct", new string[] { "CustomProduct_ID", "productName", "description", "quantity", "Rfq_ID" }, new string[] { prodId.ToString(), productName, productDescription, quantity.ToString(), rfqId.ToString() }); model.FillUserList(); }
public static void AddUser(int userId, string username, string password) { Guid uid = Guid.NewGuid(); GenericFactory <IUser> .Register(uid, () => new User(userId, username, password)); IUser user = GenericFactory <IUser> .Create(uid); _data.AddRow("Users", new string[] { "user_ID", "userName", "password" }, new string[] { userId.ToString(), username, password }); model.FillUserList(); }
public static void AddCustomer(int customer_ID, string custFirstName, string custLastName, string custCompanyName, string custPhoneNum, string[] custAddress) { Guid uid = Guid.NewGuid(); GenericFactory <ICustomer> .Register(uid, () => new Customer(customer_ID, custFirstName, custLastName, custCompanyName, custPhoneNum, custAddress)); ICustomer cus = GenericFactory <ICustomer> .Create(uid); _data.AddRow("Customer", new string[] { "customer_ID", "custFirstName", "custLastName", "custCompanyName", "custPhoneNum", "custAddress", "custAddLine2", "custCounty" }, new string[] { customer_ID.ToString(), custFirstName, custLastName, custCompanyName, custPhoneNum, custAddress[0], custAddress[1], custAddress[2] }); model.FillCustomerList(); }
public static void AddMaterial(int MatID, string MatName, string MatDescription) { Guid uid = Guid.NewGuid(); GenericFactory <IMaterial> .Register(uid, () => new Material(MatID, MatName, MatDescription)); IMaterial mat = GenericFactory <IMaterial> .Create(uid); _data.AddRow("RawMaterial", new string[] { "RawMaterial_ID", "materialName", "materialDescription" }, new string[] { MatID.ToString(), MatName, MatDescription }); model.FillMaterialsList(); }
public static void AddEmployee(int employeeID, string firstName, string lastName, string phoneNum, int deptId, int userId) { Guid uid = Guid.NewGuid(); GenericFactory <IEmployee> .Register(uid, () => new Employee(employeeID, firstName, lastName, phoneNum, deptId, userId)); IEmployee emp = GenericFactory <IEmployee> .Create(uid); _data.AddRow("Employee", new string[] { "employee_ID", "empFirstName", "empLastName", "empPhoneNum", "department_ID", "User_user_ID" }, new string[] { employeeID.ToString(), firstName, lastName, phoneNum, deptId.ToString(), userId.ToString() }); model.FillEmployeeList(); }
public void Failure_KeyDoesNotExist() { // Setup var factory = new GenericFactory <int, Exception>(new Dictionary <int, Type>() { { 0, typeof(Exception) }, { 1, typeof(InvalidProgramException) }, }); // Execution and Assert Assert.ThrowsException <ArgumentException>(() => factory.Create(2)); }
public void AddCustomerInfo() { CustomerDbObject customer = GenericFactory <CustomerDbObject> .Create("Lead"); IRepositoryDAL <CustomerDbObject> databaseLayer0 = GenericFactory <IRepositoryDAL <CustomerDbObject> > .Create("SQLDatabase"); IRepositoryDAL <CustomerDbObject> databaseLayer = DALFactory.CreateCustomerDAL(DALType.ADOSQL); IRepositoryDAL <CustomerDbObject> databaseLayer1 = DALFactory.CreateCustomerDAL(DALType.EF); databaseLayer.Add(customer); // in memory databaseLayer.Save(); // physical saving }
public void Failure_IncorrectType() { // Setup var factory = new GenericFactory <int, Exception>(new Dictionary <int, Type>() { { 0, typeof(Exception) }, { 1, typeof(InvalidProgramException) }, { 2, typeof(List <Exception>) } }); // Execution and Assert Assert.ThrowsException <InvalidCastException>(() => factory.Create(2)); }
public void FillLineItemList() { List <string[]> lineItemData = DataLayer.GetTableData("STL_LineItem"); foreach (String[] row in lineItemData) { Guid uid = Guid.NewGuid(); GenericFactory <ILineItem> .Register(uid, () => new LineItem(Convert.ToInt16(row[0]), Convert.ToInt16(row[1]), Convert.ToDouble(row[2]), Convert.ToDouble(row[3]), Convert.ToDouble(row[4]), Convert.ToInt16(row[5]))); ILineItem lineItem = GenericFactory <ILineItem> .Create(uid); LineItemList.Add(lineItem); } }
public void FillLotTravellerList() { List <string[]> lotTravellerData = DataLayer.GetTableData("LotTraveller"); foreach (String[] row in lotTravellerData) { Guid uid = Guid.NewGuid(); GenericFactory <ILotTraveller> .Register(uid, () => new LotTraveller(Convert.ToInt16(row[0]), row[1])); ILotTraveller lotTraveller = GenericFactory <ILotTraveller> .Create(uid); lotTravellerList.Add(lotTraveller); } }
public void FillEmployeeList() { List <string[]> employeeData = DataLayer.GetTableData("employee"); foreach (String[] row in employeeData) { Guid uid = Guid.NewGuid(); GenericFactory <IEmployee> .Register(uid, () => new Employee(Convert.ToInt16(row[0]), row[1], row[2], row[3], Convert.ToInt16(row[4]), Convert.ToInt16(row[5]))); IEmployee emp = GenericFactory <IEmployee> .Create(uid); EmployeeList.Add(emp); } }
public void FillDocumentList(string table) { List <string[]> documentData = DataLayer.GetTableData(table); foreach (String[] row in documentData) { Guid uid = Guid.NewGuid(); GenericFactory <IDocument> .Register(uid, () => new Document(Convert.ToInt16(row[0]), row[1], DateTime.ParseExact(row[2], "dd/MM/yyyy", null))); IDocument doc = GenericFactory <IDocument> .Create(uid); DocumentList.Add(doc); } }
public void FillMaterialsList() { List <string[]> materialsData = DataLayer.GetTableData("RawMaterial"); foreach (String[] row in materialsData) { Guid uid = Guid.NewGuid(); GenericFactory <IMaterial> .Register(uid, () => new Material(Convert.ToInt16(row[0]), row[1], row[2], Convert.ToInt16(row[3]))); IMaterial material = GenericFactory <IMaterial> .Create(uid); materialsList.Add(material); } }
public void FillCustomerList() { List <string[]> custData = DataLayer.GetTableData("Customer"); foreach (String[] row in custData) { Guid uid = Guid.NewGuid(); GenericFactory <ICustomer> .Register(uid, () => new Customer(Convert.ToInt16(row[0]), row[1], row[2], row[3], row[4], new string[] { row[5], row[6], row[7] })); ICustomer customer = GenericFactory <ICustomer> .Create(uid); CustomerList.Add(customer); } }
public void FillUserList() { List <string[]> userData = DataLayer.GetTableData("users"); foreach (String[] row in userData) { Guid uid = Guid.NewGuid(); GenericFactory <IUser> .Register(uid, () => new User(Convert.ToInt16(row[0]), row[1], row[2])); IUser user = GenericFactory <IUser> .Create(uid); UserList.Add(user); } }
public void FillCustomProductList() { List <string[]> customProductData = DataLayer.GetTableData("CustomProduct"); foreach (String[] row in customProductData) { Guid uid = Guid.NewGuid(); GenericFactory <IProduct> .Register(uid, () => new Product(Convert.ToInt16(row[0]), row[1], row[2], Convert.ToInt16(row[3]), Convert.ToInt16(row[4]))); IProduct customProduct = GenericFactory <IProduct> .Create(uid); customProductList.Add(customProduct); } }
public void Success_CorrectTypeCreated() { // Setup var factory = new GenericFactory <int, Exception>(new Dictionary <int, Type>() { { 0, typeof(Exception) }, { 1, typeof(InvalidProgramException) }, }); // Execution var result = factory.Create(1); // Assert Assert.IsNotNull(result); Assert.AreEqual(typeof(InvalidProgramException), result.GetType()); }
public void FillDocumentList(string table, bool criteria) { DataLayer.RemoveCriteria(); DataLayer.SetCriteria("responded", criteria); List <string[]> documentData = DataLayer.GetTableData(table); foreach (String[] row in documentData) { Guid uid = Guid.NewGuid(); GenericFactory <IDocument> .Register(uid, () => new Document(Convert.ToInt16(row[0]), row[1], DateTime.ParseExact(row[2], "dd/MM/yyyy", null), Convert.ToBoolean(row[3]))); IDocument doc = GenericFactory <IDocument> .Create(uid); DocumentList.Add(doc); } }
static void Main(string[] args) { ActivatorManager.CreateInstance <UserManager>(); ActivatorManager.CreateInstanceWithConst <UserManager>(); var userList = ActivatorManager.CreateInstanceGenericList <UserManager>(); var user = ActivatorManager.GetInstance <UserManager>(); var user2 = ActivatorManager.GetInstanceConst <UserManager>(); // GetInstanceWithGenericConstructer Family family = new Family { FatherName = "zafer", MotherName = "ayse" }; var user3 = ActivatorManager.GetInstanceWithGenericConstructer <UserManager, Family>(family); // var factory = new GenericFactory <string, UserManager>(); factory.Register("key", typeof(Family)); UserManager newInstance = factory.Create("key", family); }
/// <summary> /// Creates a new algorithm based on the quality strategy provided /// </summary> /// <param name="strategyType">The strategy</param> /// <exception cref="ArgumentException">Indicates that the strategy type that was provided was invalid</exception> /// <exception cref="GildedRoseException">Indicates that the lookup list that was provided in the constructor /// was invalid</exception> /// <returns>The quality algorithm</returns> public IShelfLifeAlgorithm Create(ShelfLifeStrategy strategyType) { try { return(_genericFactory.Create(strategyType)); } catch (ArgumentException ex) { // This exception means that the shelf life strategy did not exist in the lookup provided. // We don't rethrow here because the parameter name would make no sense to the caller. throw new ArgumentException(nameof(strategyType), ex); } catch (InvalidCastException) { // This means the type specified in the lookup list is not compatible with our return type // TODO: This should really be a custom exception type throw new GildedRoseException($"The lookup list item relating to '{strategyType}' was not compatible" + $"with the IShelfLifeAlgorithm return type."); } }