Esempio n. 1
0
        public void TestRainBarrelCapacity()
        {
            #region Sub testmethod 'TestIsIllegal'
            System.Func <int, bool> TestIsIllegal = (capacity) => {
                try
                {
                    var barrel = new RainBarrel(0, (BucketOOP.Buckets.Enums.CapacityOption)capacity);
                }
                catch
                {
                    return(true);
                }

                return(false);
            };
            #endregion

            int[] allowedCapacities = new int[] { 80, 120, 160 };

            foreach (var capacity in allowedCapacities)
            {
                Assert.IsFalse(TestIsIllegal(capacity));
            }

            Assert.IsTrue(TestIsIllegal(0));
        }
Esempio n. 2
0
        private void bCreateRainBarrel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                double     content = tbRainBarrelContent.Text.Length == 0 ? 0 : double.Parse(tbRainBarrelContent.Text);
                RainBarrel rainBarrel;
                if (rbRainBarrelSmall.IsChecked == true)
                {
                    rainBarrel = RainBarrel.GetSmall(content);
                }
                else if (rbRainBarrelLarge.IsChecked == true)
                {
                    rainBarrel = RainBarrel.GetLarge(content);
                }
                else
                {
                    rainBarrel = RainBarrel.Get(content);
                }

                AddContainer(new RainBarrelViewModel(rainBarrel));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 3
0
        public void HaveRequestedCapacityOf160()
        {
            RainBarrel sut;
            int        requestedCapacity = 160;

            sut = new RainBarrel(0, 121);

            Assert.Equal(requestedCapacity, sut.Capacity);
        }
Esempio n. 4
0
        public void HaveRequestedContentOf100()
        {
            RainBarrel sut;
            int        requestedContent = 100;

            sut = new RainBarrel(requestedContent);

            Assert.Equal(requestedContent, sut.Content);
        }
Esempio n. 5
0
        public void HaveDefaultContentOfZero()
        {
            RainBarrel sut;
            int        defaultContent = 0;

            sut = new RainBarrel();

            Assert.Equal(defaultContent, sut.Content);
        }
Esempio n. 6
0
        public void HaveDefaultCapacityOf120()
        {
            RainBarrel sut;
            int        defaultCapacity = 120;

            sut = new RainBarrel();

            Assert.Equal(defaultCapacity, sut.Capacity);
        }
Esempio n. 7
0
        public void TestInheritance()
        {
            var bucket     = new Bucket();
            var rainBarrel = new RainBarrel();
            var oilBarrel  = new OilBarrel();

            Assert.IsTrue(bucket is BucketBase);
            Assert.IsTrue(rainBarrel is BucketBase);
            Assert.IsTrue(oilBarrel is BucketBase);
        }
Esempio n. 8
0
        public void CreateContainers()
        {
            Container container;

            // Test whether default containers have the correct capacity and content.
            container = Bucket.GetDefault();
            Assert.Equal(12, container.Capacity);
            Assert.Equal(0, container.Content);

            container = RainBarrel.Get();
            Assert.Equal(100, container.Capacity);
            Assert.Equal(0, container.Content);

            container = RainBarrel.GetSmall();
            Assert.Equal(80, container.Capacity);
            Assert.Equal(0, container.Content);

            container = RainBarrel.GetLarge();
            Assert.Equal(120, container.Capacity);
            Assert.Equal(0, container.Content);

            container = OilBarrel.Get();
            Assert.Equal(159, container.Capacity);
            Assert.Equal(0, container.Content);

            // Test whether or not an exception is thrown when creating valid/invalid conainers.
            Bucket.GetDefault(11);
            Bucket.GetDefault(12);
            Assert.Throws <ArgumentOutOfRangeException>(() => Bucket.GetDefault(13));

            Bucket.Get(11);
            Bucket.Get(10);
            Assert.Throws <ArgumentOutOfRangeException>(() => Bucket.Get(9));

            Bucket.Get(16, 15);
            Bucket.Get(16, 16);
            Assert.Throws <ArgumentOutOfRangeException>(() => Bucket.Get(16, 17));

            RainBarrel.Get(99);
            RainBarrel.Get(100);
            Assert.Throws <ArgumentOutOfRangeException>(() => RainBarrel.Get(101));

            RainBarrel.GetSmall(79);
            RainBarrel.GetSmall(80);
            Assert.Throws <ArgumentOutOfRangeException>(() => RainBarrel.GetSmall(81));

            RainBarrel.GetLarge(119);
            RainBarrel.GetLarge(120);
            Assert.Throws <ArgumentOutOfRangeException>(() => RainBarrel.GetLarge(121));

            OilBarrel.Get(158);
            OilBarrel.Get(159);
            Assert.Throws <ArgumentOutOfRangeException>(() => OilBarrel.Get(160));
        }
Esempio n. 9
0
 public RainBarrelViewModel(RainBarrel rainBarrel) : base(rainBarrel)
 {
 }