コード例 #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));
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: one-up1/Buckets
        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);
            }
        }
コード例 #3
0
ファイル: RainBarrelShould.cs プロジェクト: Meintje/Buckets
        public void HaveRequestedCapacityOf160()
        {
            RainBarrel sut;
            int        requestedCapacity = 160;

            sut = new RainBarrel(0, 121);

            Assert.Equal(requestedCapacity, sut.Capacity);
        }
コード例 #4
0
ファイル: RainBarrelShould.cs プロジェクト: Meintje/Buckets
        public void HaveRequestedContentOf100()
        {
            RainBarrel sut;
            int        requestedContent = 100;

            sut = new RainBarrel(requestedContent);

            Assert.Equal(requestedContent, sut.Content);
        }
コード例 #5
0
ファイル: RainBarrelShould.cs プロジェクト: Meintje/Buckets
        public void HaveDefaultContentOfZero()
        {
            RainBarrel sut;
            int        defaultContent = 0;

            sut = new RainBarrel();

            Assert.Equal(defaultContent, sut.Content);
        }
コード例 #6
0
ファイル: RainBarrelShould.cs プロジェクト: Meintje/Buckets
        public void HaveDefaultCapacityOf120()
        {
            RainBarrel sut;
            int        defaultCapacity = 120;

            sut = new RainBarrel();

            Assert.Equal(defaultCapacity, sut.Capacity);
        }
コード例 #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);
        }
コード例 #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));
        }
コード例 #9
0
 public RainBarrelViewModel(RainBarrel rainBarrel) : base(rainBarrel)
 {
 }