Beispiel #1
0
        public Planting(Flower flower, Soil soil, Pot pot)
        {
            // садить только цветок без горшка в пустой горшок
            Contract.Requires <ArgumentException>(flower.GetPot(DateTime.UtcNow) == null);
            Contract.Requires <ArgumentException>(pot.GetFlower(DateTime.UtcNow) == null);

            Contract.Ensures(pot.GetFlower(this.Date) == flower, "must be planted flower in pot on date of planting");
            Contract.Ensures(flower.GetPot(this.Date) == pot, "flower must be in this pot on date of planting");

            this.pot    = pot;
            this.soil   = soil;
            this.flower = flower;

            pot.Events.Add(this);
            flower.Events.Add(this);
            Debug.WriteLine("{0} planted to {1} with {2}", flower, pot, soil);
        }
Beispiel #2
0
        public void GetFlower_BeforeDateOfPlanting_ReturnsNull()
        {
            // arrange
            var pot    = new Pot();
            var flower = new Flower(new PlantSource(Plants.Hedera, SeedType.Seedling));

            new Planting(flower, new Soil(""), pot);

            // act
            var result = pot.GetFlower(DateTime.UtcNow.AddDays(-1));

            // assert
            Assert.AreEqual(null, result);
        }
Beispiel #3
0
        public void GetFlower_FromPotWithFlower_ReturnsIt()
        {
            // arrange
            var pot    = new Pot();
            var flower = new Flower(new PlantSource(Plants.Hedera, SeedType.Seedling));

            new Planting(flower, new Soil(""), pot);

            // act
            var result = pot.GetFlower(DateTime.UtcNow);

            // assert
            Assert.AreEqual(flower, result);
        }
Beispiel #4
0
        public void GetFlower_AtMomentBetweenTwoPlantings_ReturnsFirstFlower()
        {
            // arrange
            var pot     = new Pot("small pot");
            var flower1 = new Flower(new PlantSource(Plants.Hedera, SeedType.Seedling));
            var flower2 = new Flower(new PlantSource(Plants.Hedera, SeedType.Seedling));

            new Planting(flower1, new Soil(""), pot);
            var time = DateTime.UtcNow;

            // dirty fix
            Thread.Sleep(1000);
            pot.PullEverything();
            Thread.Sleep(1000);
            new Planting(flower2, new Soil(""), pot);

            // act
            var result = pot.GetFlower(time);

            // assert
            Assert.AreEqual(flower1, result);
        }