public Animal(string name, AnimalTypeEnum type)
 {
     Name   = name;
     Type   = type;
     Rested = false;
     Fed    = false;
 }
示例#2
0
        public void EnumParsing_WithoutExtensions()
        {
            // Note that you can't parse directly to the property. You need
            // to use temporary variables. Consider this method an example of
            // steps you'd normally take when parsing enums.
            RandomModelObject obj           = new RandomModelObject();
            AnimalTypeEnum    tmpAnimalEnum = AnimalTypeEnum.Bird;

            Enum.TryParse <AnimalTypeEnum>("Cat", out tmpAnimalEnum);
            obj.NonNullableEnum = tmpAnimalEnum;
            Assert.AreEqual(AnimalTypeEnum.Cat, obj.NonNullableEnum, "Should have parsed to Cat type. ('Cat')");


            Enum.TryParse <AnimalTypeEnum>("3", out tmpAnimalEnum);  // we can also parse with values.
            obj.NonNullableEnum = tmpAnimalEnum;
            Assert.AreEqual(AnimalTypeEnum.Dog, obj.NonNullableEnum, "Should have parsed to Dog type.('3')");


            // For nullable values this can get annoying. A one-liner would be nice.
            AnimalTypeEnum tmpAnimalEnum2;

            if (Enum.TryParse <AnimalTypeEnum>("Dog", out tmpAnimalEnum))
            {
                obj.NullableEnum = tmpAnimalEnum;
            }
            else
            {
                obj.NullableEnum = null;
            }
            Assert.AreEqual(AnimalTypeEnum.Dog, obj.NullableEnum, "Should have parsed to nullable Dog type.");
        }
示例#3
0
        public void Create(AnimalTypeEnum animalType, string name)
        {
            switch (animalType)
            {
            case AnimalTypeEnum.Cat:
                _animals.Add(new Cat(name));
                break;

            case AnimalTypeEnum.Lion:
                _animals.Add(new Lion(name));
                break;

            case AnimalTypeEnum.Dog:
                _animals.Add(new Dog(name));
                break;

            case AnimalTypeEnum.Wolf:
                _animals.Add(new Wolf(name));
                break;

            case AnimalTypeEnum.Mouse:
                _animals.Add(new Mouse(name));
                break;

            case AnimalTypeEnum.Rat:
                _animals.Add(new Rat(name));
                break;

            default:
                _cli.DisplayError($"No such type.");
                break;
            }

            _cli.DisplayInfo($"Created {animalType} with name {name}.");
        }
示例#4
0
        public static AnimalBase AnimalFactory(AnimalTypeEnum animalTypeEnum)
        {
            AnimalBase createAnimal = null;

            switch (animalTypeEnum)
            {
            case AnimalTypeEnum.Cat:
                createAnimal = new Cat();
                break;

            case AnimalTypeEnum.Cow:
                createAnimal = new Cow();
                break;

            case AnimalTypeEnum.Dog:
                createAnimal = new Dog();
                break;

            case AnimalTypeEnum.Duck:
                createAnimal = new Duck();
                break;

            case AnimalTypeEnum.Pig:
                createAnimal = new Pig();
                break;
            }

            return(createAnimal);
        }
        private static T InitializeAnimal(AnimalTypeEnum type)
        {
            T animalObject = null;

            switch (type)
            {
            case AnimalTypeEnum.Cow:
                animalObject = AnimalBase.AnimalFactory(type) as T;
                break;

            case AnimalTypeEnum.Dog:
                animalObject = AnimalBase.AnimalFactory(type) as T;
                break;

            case AnimalTypeEnum.Cat:
                animalObject = AnimalBase.AnimalFactory(type) as T;
                break;

            case AnimalTypeEnum.Pig:
                animalObject = AnimalBase.AnimalFactory(type) as T;
                break;

            case AnimalTypeEnum.Duck:
                animalObject = AnimalBase.AnimalFactory(type) as T;
                break;
            }

            return(animalObject);
        }
示例#6
0
        public static List <Cattle> GetUserAnimals(int UId, int AnimalID)
        {
            ac.OpenConnection();


            List <Cattle> cattle = new List <Cattle>();

            //parameter and variable of this Procedure
            string[] variables = new string[] { "@UID", "@AnimalID" };
            string[] values    = new string[] { "" + UId, "" + AnimalID };

            //get data from  database
            DataTable data = ac.ExecuteDataTableProcedure("GetOneAnimal", variables, values, ac);


            if (data.Rows.Count != 0)
            {
                foreach (DataRow row in data.Rows)
                {
                    //offspring
                    List <Cattle> offSpring = new List <Cattle>();

                    //frame size
                    FrameSize frmeSize = (FrameSize)Enum.Parse(typeof(FrameSize), row["CattleFrameSize"].ToString());
                    //Breeding status
                    BreedingStatus bStatus = (BreedingStatus)Enum.Parse(typeof(BreedingStatus), row["CattleBreedingStatus"].ToString());
                    //Status Enum
                    StatusEnum sStatus = (StatusEnum)Enum.Parse(typeof(StatusEnum), row["AnimalStatus"].ToString());
                    //Gender Enum
                    GenderEnum gEnum = (GenderEnum)Enum.Parse(typeof(GenderEnum), row["AnimalGender"].ToString());
                    //animal type
                    AnimalTypeEnum animalType = (AnimalTypeEnum)Enum.Parse(typeof(AnimalTypeEnum), row["AnimalType"].ToString());


                    cattle.Add
                    (
                        new Cattle
                        (
                            int.Parse(row["AnimalTid"].ToString()), row["AnimalBreed"].ToString(), gEnum, double.Parse(row["AnimalAge"].ToString()),
                            int.Parse(row["AnimalYear"].ToString()), int.Parse(row["AnimalMonth"].ToString()), int.Parse(row["AnimalDay"].ToString()),
                            animalType, row[4].ToString(), row[5].ToString(), (int)(Math.Round(double.Parse(row["AnimalAge"].ToString()) / 24)), int.Parse(row["personid"].ToString()),
                            row["personname"].ToString(), row["personSurname"].ToString(), DateTime.Parse(row["personDOB"].ToString()),


                            int.Parse(row["CattleID"].ToString()), int.Parse(row["CattleParentFatherID"].ToString()), int.Parse(row["CattleParentMotherID"].ToString()), (row["CattleImage"].ToString())
                            , offSpring, sStatus, double.Parse(row["CattleScotralSize"].ToString()), row["CattleColor"].ToString(),
                            bStatus, frmeSize,


                            double.Parse(row["CattleBirthWeight"].ToString()), double.Parse(row["CattleWeaningWeight"].ToString()), double.Parse(row["CattlePostWeaningWeight"].ToString()),
                            double.Parse(row["CattleAdultSxWeight"].ToString()), double.Parse(row["CattleCurrentAdultWeight"].ToString()), DateTime.Parse(row["CattleCurrentWeightDateTaken"].ToString()), null, null, null

                        ));
                }
            }



            return(cattle);
        }
示例#7
0
 // Constructor
 public Species(string Name, int NumberOfEyes, int NumberOfLegs, AnimalTypeEnum animalKind)
 {
     this.name         = Name;
     this.numberOfEyes = NumberOfEyes;
     this.numberOfLegs = NumberOfLegs;
     this.animalKind   = animalKind;
 }
        public static IAnimal CreateInstance(AnimalTypeEnum animalTypeEnum)
        {
            switch (animalTypeEnum)
            {
            case AnimalTypeEnum.cat:
                return(new Cat());

            case AnimalTypeEnum.dog:
                return(new Dog());

            default:
                throw new Exception("错误");
            }
        }
示例#9
0
        public static IFactoty CreateFactoty(AnimalTypeEnum animalTypeEnum)
        {
            switch (animalTypeEnum)
            {
            case AnimalTypeEnum.cat:
                return(new CatFactory());

            case AnimalTypeEnum.dog:
                return(new DogFactory());

            default:
                throw new Exception("错误");
            }
        }
        public void ShouldCreateAnimalWithGivenNameAndType()
        {
            //Given
            StubCommandInterface stubbedCli = new StubCommandInterface();
            Laboratory           laboratory = new Laboratory(stubbedCli);
            AnimalTypeEnum       testType   = AnimalTypeEnum.Cat;
            string testName     = "Tom";
            string expectedInfo = $"Created {testType} with name {testName}.";

            //When
            laboratory.Create(testType, testName);

            //Then
            Assert.That(stubbedCli.InfoMessages, Does.Contain(expectedInfo));
        }
示例#11
0
        public Cattle
        (
            int aId, string aBreed, GenderEnum aGender, double aAge, int aYear, int aMonth, int aDay,
            AnimalTypeEnum aType, string aIdentifactionChar, string aCustomeIdentifaction,
            int oId,

            int pId, string pName, string pSurname, DateTime dob,

            int cId, int cParentFId, int cParentMId, string cImagePath, List <Cattle> cOffSpring,

            StatusEnum status, double cScotralSize, string cColor, BreedingStatus cBreedingStatus,

            FrameSize cFrameSize, double cBirthWeight, double cWeaningWeight, double cPostWeaningWeight,

            double cAdultSxWeight, double cCurrentAdultWeight, DateTime cCurrentWeightDateTaken, List <string> cDiagnoses, List <double> cAdultWeightHistory, List <DateTime> cAdultWeightDateHistory, DateTime aDOB



        )
            : base(aId, aBreed, aGender, aAge, aYear, aMonth, aDay, aType,
                   oId, pId, pName, pSurname, dob, status, aIdentifactionChar, aCustomeIdentifaction)
        {
            this.cId        = cId;
            this.cParentFId = cParentFId;
            this.cParentMId = cParentMId;
            this.cImagePath = cImagePath;
            this.cOffSpring = cOffSpring;


            this.cScotralSize            = cScotralSize;
            this.cColor                  = cColor;
            this.cBreedingStatus         = cBreedingStatus;
            this.cFrameSize              = cFrameSize;
            this.cBirthWeight            = cBirthWeight;
            this.cWeaningWeight          = cWeaningWeight;
            this.cPostWeaningWeight      = cPostWeaningWeight;
            this.cAdultSxWeight          = cAdultSxWeight;
            this.cCurrentAdultWeight     = cCurrentAdultWeight;
            this.cCurrentWeightDateTaken = cCurrentWeightDateTaken;

            //------
            this.cDiagnoses = cDiagnoses;
            this.cAdultWeightDateHistory = cAdultWeightDateHistory;
            this.cAdultWeightHistory     = cAdultWeightHistory;
            //------
            this.aDOB = aDOB;
        }
        public void ShouldDisplayErrorWhenDogIsNotFedOrRestedButSentToBarker()
        {
            //Given
            StubCommandInterface stubbedCli = new StubCommandInterface();
            Laboratory           laboratory = new Laboratory(stubbedCli);
            AnimalTypeEnum       testType   = AnimalTypeEnum.Dog;
            string testName = "Rex";

            laboratory.Create(AnimalTypeEnum.Dog, testName);

            //When
            laboratory.Barker(testName);

            //Then
            Assert.That(stubbedCli.ErrorsMessages.Count, Is.EqualTo(1));
            Assert.That(stubbedCli.BarksMessages, Does.Not.Contain(testName));
        }
示例#13
0
 public Animal(int aId, string aBreed, GenderEnum aGender, double aAge, int aYear, int aMonth, int aDay, AnimalTypeEnum aType,
               int oId, int pId, string pName, string pSurname, DateTime dob, StatusEnum status, string aIdentifactionChar, string aCustomeIdentifaction
               )
     : base(oId, pId, pName, pSurname, dob)
 {
     this.aId                   = aId;
     this.aBreed                = aBreed;
     this.aGender               = aGender;
     this.aAge                  = aAge;
     this.aYear                 = aYear;
     this.aMonth                = aMonth;
     this.aDay                  = aDay;
     this.aType                 = aType;
     this.status                = status;
     this.AIdentifactionChar    = aIdentifactionChar;
     this.ACustomeIdentifaction = aCustomeIdentifaction;
 }
        /// <summary>
        /// 读配置文件创建对象
        /// </summary>
        /// <returns></returns>
        public static IAnimal CreateInstanceByConfig()
        {
            string         config         = ConfigurationManager.AppSettings["AnimalTypeConfig"];
            AnimalTypeEnum animalTypeEnum = (AnimalTypeEnum)Enum.Parse(typeof(AnimalTypeEnum), config);

            switch (animalTypeEnum)
            {
            case AnimalTypeEnum.cat:
                return(new Cat());

            case AnimalTypeEnum.dog:
                return(new Dog());

            default:
                throw new Exception("错误");
            }
        }
        public void ShouldSendDogToBarkerIfFedAndRested()
        {
            //Given
            StubCommandInterface stubbedCli = new StubCommandInterface();
            Laboratory           laboratory = new Laboratory(stubbedCli);
            AnimalTypeEnum       testType   = AnimalTypeEnum.Dog;
            string testName = "Rex";

            laboratory.Create(AnimalTypeEnum.Dog, testName);
            laboratory.GoEat(testName);
            laboratory.GoToSleep(testName);

            //When
            laboratory.Barker(testName);

            //Then
            Assert.That(stubbedCli.BarksMessages, Does.Contain(testName));
        }
示例#16
0
 public void CheckIfAllAnimalsAreDifferentFromEachOther(
     [Values(AnimalTypeEnum.Cat, AnimalTypeEnum.Cow, AnimalTypeEnum.Dog, AnimalTypeEnum.Duck, AnimalTypeEnum.Pig)
     ] AnimalTypeEnum firstAnimalTypeEnumAnimal,
     [Values(AnimalTypeEnum.Cat, AnimalTypeEnum.Cow, AnimalTypeEnum.Dog, AnimalTypeEnum.Duck, AnimalTypeEnum.Pig)
     ] AnimalTypeEnum secondAnimalTypeEnumAnimal)
 {
     if (firstAnimalTypeEnumAnimal == secondAnimalTypeEnumAnimal)
     {
         Assert.That(firstAnimalTypeEnumAnimal, Is.EqualTo(secondAnimalTypeEnumAnimal));
     }
     else
     {
         Assert.That(firstAnimalTypeEnumAnimal, Is.Not.EqualTo(secondAnimalTypeEnumAnimal));
         Assert.That(
             AnimalBase.AnimalFactory(firstAnimalTypeEnumAnimal).AnimalName,
             Is.Not.EqualTo(AnimalBase.AnimalFactory(secondAnimalTypeEnumAnimal).AnimalName));
         Assert.That(
             AnimalBase.AnimalFactory(firstAnimalTypeEnumAnimal).AnimalSound,
             Is.Not.EqualTo(AnimalBase.AnimalFactory(secondAnimalTypeEnumAnimal).AnimalSound));
         Assert.That(
             AnimalBase.AnimalFactory(firstAnimalTypeEnumAnimal).GetGetAnimalNameAndSound(),
             Is.Not.EqualTo(AnimalBase.AnimalFactory(secondAnimalTypeEnumAnimal).GetGetAnimalNameAndSound()));
     }
 }
 public CreateAnimalCommand(List <Animal> animals, AnimalTypeEnum animalType, string name)
 {
     _animals    = animals;
     _animalType = animalType;
     _name       = name;
 }
示例#18
0
        }                                            // get method for animal kind

        public MyAnimal(AnimalTypeEnum kind)
        {
            this.kind = kind;
        }
示例#19
0
        public static IAnimal CreateInstance(AnimalTypeEnum animalTypeEnum)
        {
            IFactoty factoty = CreateFactoty(animalTypeEnum);

            return(factoty.CreatInstance());
        }
示例#20
0
 public Animal(int yob, string name, AnimalTypeEnum type)
 {
     this.YOB  = yob;
     this.Name = name;
     this.Type = type;
 }
示例#21
0
        public void Create(AnimalTypeEnum animalType, string name)
        {
            new CreateAnimalCommand(_animals, animalType, name).Execute();

            _cli.DisplayInfo($"Created {animalType} with name {name}.");
        }
示例#22
0
 /// <summary>
 /// The constructor, with the Name property been
 /// initialized.
 /// </summary>
 /// <param name="name">The value to initialize the Name property</param>
 /// <param name="age">The value to initialize the Age property</param>
 /// <param name="animalType">The value to initialize the AnimalType property</param>
 public Animal(string name, int age, AnimalTypeEnum animalType)
 {
     this.Name = name;
     this.Age = age;
     this.AnimalType = animalType;
 }
示例#23
0
        //get Offspring
        public static List <Cattle> GetAnimalsOffSpring(int UId, int AnimalID, string gender, Person person)
        {
            ac.OpenConnection();

//            create procedure GetAnimalOffspring
//@UID Bigint,
//@AID Bigint,
//@ParentGender varchar(100)

            List <Cattle> cattle = new List <Cattle>();

            //parameter and variable of this Procedure
            string[] variables = new string[] { "@UID", "@AID", "@ParentGender" };
            string[] values    = new string[] { "" + UId, AnimalID.ToString(), gender };

            //get data from  database
            DataTable data = ac.ExecuteDataTableProcedure("GetAnimalOffspring", variables, values, ac);



            if (data.Rows.Count != 0)
            {
                foreach (DataRow row in data.Rows)
                {
                    //A.PERSONID,
                    //A.AnimalTid	        0, A.AnimalType 1,	 A.AnimalBreed 2, A.AnimalCustomID 3,	 A.AnimalCurOwnerSignature 4,	 A.AnimalGender        5,
                    //A.AnimalAge            6, A.AnimalYear 7,	 A.AnimalMonth 8, A.AnimalDay      9,	 A.AnimalStatus            10,	 A.IdentificationChar  11,
                    //C.CattleParentFatherID 12,	C.CattleParentMotherID	13,C.CattleImage	14,C.CattleScotralSize	15,C.CattleColor	16,C.CattleBreedingStatus	17,
                    //C.CattleFrameSize	18,C.CattleBirthWeight	19,C.CattleWeaningWeight	20,C.CattlePostWeaningWeight	21,C.CattleAdultSxWeight 22,
                    //C.CattleCurrentAdultWeight 23,	C.CattleCurrentWeightDateTaken 24

                    //offspring
                    List <Cattle> offSpring = new List <Cattle>();
                    #region Enums
                    //frame size
                    FrameSize frmeSize = (FrameSize)Enum.Parse(typeof(FrameSize), row[19].ToString());
                    //Breeding status
                    BreedingStatus bStatus = (BreedingStatus)Enum.Parse(typeof(BreedingStatus), row[18].ToString());
                    //Status Enum
                    StatusEnum sStatus = (StatusEnum)Enum.Parse(typeof(StatusEnum), row[11].ToString());
                    //Gender Enum
                    GenderEnum gEnum = (GenderEnum)Enum.Parse(typeof(GenderEnum), row[6].ToString());
                    //animal type
                    AnimalTypeEnum animalType = (AnimalTypeEnum)Enum.Parse(typeof(AnimalTypeEnum), row[2].ToString());
                    #endregion

                    //weights
                    List <double>   weights    = DataAccessData.AnimalWeightHistory(person.PId, int.Parse(row[1].ToString())).Values.ToList();
                    List <DateTime> weightDate = DataAccessData.AnimalWeightHistory(person.PId, int.Parse(row[1].ToString())).Keys.ToList();
                    cattle.Add
                    (
                        new Cattle
                        (
                            int.Parse(row[1].ToString()), row[3].ToString(), gEnum, double.Parse(row[7].ToString()),
                            int.Parse(row[8].ToString()), int.Parse(row[9].ToString()), int.Parse(row[10].ToString()),
                            animalType, row[4].ToString(), row[5].ToString(), person.PId, person.PId, person.PName, person.PSurname, person.Dob, 14478899, int.Parse(row[13].ToString()), int.Parse(row[14].ToString()),
                            row[15].ToString()
                            , null,
                            sStatus, double.Parse(row[16].ToString()), row[17].ToString(),
                            bStatus, frmeSize,

                            double.Parse(row[20].ToString()), double.Parse(row[21].ToString()), double.Parse(row[22].ToString()),
                            double.Parse(row[23].ToString()), double.Parse(row[24].ToString()), DateTime.Parse(row[25].ToString()), null, weights, weightDate

                        ));
                }
            }


            return(cattle);
        }