コード例 #1
0
        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());
            }
        }
コード例 #2
0
        public void should_resolve_generic_instances_duck()
        {
            var    factory = new GenericFactory <ISpeek>();
            ISpeek speek   = factory.Create <Duck>();

            Assert.Equal("Duck is speaking~.", speek.Speek());
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
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);
                }
            }
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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?));
        }
コード例 #8
0
        //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);
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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();
        }
コード例 #11
0
        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();
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        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();
        }
コード例 #14
0
        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();
        }
コード例 #15
0
        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();
        }
コード例 #16
0
        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));
        }
コード例 #17
0
        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
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
        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);
            }
        }
コード例 #22
0
        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);
            }
        }
コード例 #23
0
        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);
            }
        }
コード例 #24
0
        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);
            }
        }
コード例 #25
0
        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);
            }
        }
コード例 #26
0
        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);
            }
        }
コード例 #27
0
        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());
        }
コード例 #28
0
        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);
            }
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: barisel/C-Sharp
        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);
        }
コード例 #30
0
 /// <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.");
     }
 }