public void WriteATestToEnsureTheBuyBeerMethodChecksThePersonsAge()
        {
            var mock = new ___();

            BuyBeer(mock.Object);

            mock.___();             // verify the user's age was checked.
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            bool loop = true;

            while (loop == true)
            {
                Console.WriteLine("___  ___          _        _____ _                 ");
                Console.WriteLine("|  \/  |         (_)      /  ___| |                ");
                Console.WriteLine("| .  . |_   _ ___ _  ___  \ `--.| |_ ___  _ __ ___ ");
                //Console.WriteLine("| |\/| | | | / __| |/ __|  `--. \ __/ _ \| '__/ _ \");



                loop = false;
            }
            ;
        }
Exemplo n.º 3
0
        public void UsingWhatYouHaveLearned_CreateACompletelyFunctionalIVolumeMock()
        {
            // Use Moq to create a Mock<IVolume> instance.
            // Have the internal volume start at 50.
            // The Louder and Quieter methods should incrament/decrament the internal volume by the passed in amount.
            // The Louder and Quieter methods should return the internal volume level after the change.
            // For example if the internal volume was 10, and .Quieter(2) is called, then it should return 8.
            // The volume should stay in the range 0 to 100. It should not go below 0 or over 100.
            // If .Louder(999) is called, then the volume should be at 100.
            // The CurrentVolume() methoud should always return the internal volume level, as a string.
            // If a negative number is passed to either Louder or Quieter, then it should throw an ArgumentOutOfRangeException.

            var mock = new ___();
            // ...setup your mock here...

            // Do not change these Asserts. Your setup mock should make all of these pass the way they are.
            var volume = mock.Object;

            Assert.AreEqual("50", volume.CurrentVolume());
            Assert.AreEqual(40, volume.Quieter(10));
            Assert.AreEqual("40", volume.CurrentVolume());
            Assert.AreEqual(60, volume.Louder(20));
            Assert.AreEqual("60", volume.CurrentVolume());
            Assert.AreEqual(0, volume.Quieter(1000));
            Assert.AreEqual("0", volume.CurrentVolume());
            Assert.AreEqual(100, volume.Louder(1000));
            Assert.AreEqual("100", volume.CurrentVolume());
            try
            {
                volume.Louder(-1);
                Assert.Fail("Louder did not throw an exception on a negative input.");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentOutOfRangeException));
            }
            try
            {
                volume.Quieter(-1);
                Assert.Fail("Quieter did not throw an exception on a negative input.");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentOutOfRangeException));
            }
        }
Exemplo n.º 4
0
        public void CreateAMockIAdditionThatOnlyAddsPositiveNumbersAndThrowsAnExceptionIfEitherNumerIsNegative()
        {
            // hint: remember that MockBehavior.Strict will cause an Exception if the parameters don't match any .Setup() filters.
            var mock = new ___();

            mock.____();

            Assert.AreEqual(3, mock.Object.Add(1, 2));
            Assert.AreEqual(10, mock.Object.Add(0, 10));

            try
            {
                mock.Object.Add(5, -5);
                Assert.Fail("The .Add() method did not throw an Exception when a negative number was passed in.");
            }
            catch (Exception)
            {
                // expecting an Exception because we passed in a negative number.
            }
        }
Exemplo n.º 5
0
        public void CreateANewMockOfIVolumeToMakeThisTestPass()
        {
            var mock = new ___();

            Assert.IsInstanceOfType(mock, typeof(Moq.Mock <IVolume>));
        }