Beispiel #1
0
        //private IGetCruise _getCruise;

        //public InjectionTest(IGetCruise getCruise)
        //{
        //    _getCruise = getCruise;
        //}

        public List <CruiseDTO> GetCruises(CruiseRequestDTO request)
        {
            //TODO: This method receives a generic request, that has a cruise company code on it
            //There is an interface (IGetCruise) that is implemented by 3 classes (Company1, Company2 and Company3)
            //Make sure that the correct class is injected based on the CruiseCompanyCode on the request
            //without directly referencing the 3 classes and the method GetCruises of the chosen implementation is called

            var list = new List <CruiseDTO>();

            if (request.CruiseCompanyCode == 1)
            {
                Company1 company1 = new Company1();
                list = company1.GetCruises(request);
            }
            else if (request.CruiseCompanyCode == 2)
            {
                Company2 company2 = new Company2();
                list = company2.GetCruises(request);
            }
            else if (request.CruiseCompanyCode == 3)
            {
                Company3 company3 = new Company3();
                list = company3.GetCruises(request);
            }
            else
            {
                throw new System.Exception("Incorrect company code");
            }

            return(list);
        }
        public List <CruiseDTO> GetCruises(CruiseRequestDTO request)
        {
            //TODO: This method receives a generic request, that has a cruise company code on it
            //There is an interface (IGetCruise) that is implemented by 3 classes (Company1, Company2 and Company3)
            //Make sure that the correct class is injected based on the CruiseCompanyCode on the request
            //without directly referencing the 3 classes and the method GetCruises of the chosen implementation is called

            List <CruiseDTO> result = null;

            switch (request.CruiseCompanyCode)
            {
            case 1:
                result = new Company1().GetCruises(request);
                break;

            case 2:
                result = new Company2().GetCruises(request);
                break;

            case 3:
                result = new Company3().GetCruises(request);
                break;

            default:
                throw new System.Exception("Company not found");
            }


            return(result);
        }
        public List <CruiseDTO> GetCruises(CruiseRequestDTO request)
        {
            //TODO: This method receives a generic request, that has a cruise company code on it
            //There is an interface (IGetCruise) that is implemented by 3 classes (Company1, Company2 and Company3)
            //Make sure that the correct class is injected based on the CruiseCompanyCode on the request
            //without directly referencing the 3 classes and the method GetCruises of the chosen implementation is called
            List <CruiseDTO> ListCruise = new List <CruiseDTO>();

            if (request.CruiseCompanyCode.Equals(1))
            {
                Company1 company1 = new Company1();
                ListCruise = company1.GetCruises(request);
            }
            else if (request.CruiseCompanyCode.Equals(2))
            {
                Company2 company2 = new Company2();
                ListCruise = company2.GetCruises(request);
            }
            else if (request.CruiseCompanyCode.Equals(3))
            {
                Company3 company3 = new Company3();
                ListCruise = company3.GetCruises(request);
            }

            else
            {
                throw new Exception("não existe código 4");
            }

            return(ListCruise);
        }