Esempio n. 1
0
        public void GetResources_ShouldReturnNewRousourcesObjectWithCorrectlySetProperties(string command)
        {
            var commandParams       = command.Split(' ');
            var resourcesParameters = new Dictionary <char, uint>();

            for (int i = 2; i < commandParams.Length; i++)
            {
                var resourceType = commandParams[i];
                var key          = resourceType[0];
                var paramz       = resourceType.Split(
                    new char[] { '(', ')' },
                    StringSplitOptions.RemoveEmptyEntries);

                var value = uint.Parse(paramz[1]);

                resourcesParameters[key] = value;
            }
            var resourcesFactory = new ResourcesFactory();

            var actualResources = resourcesFactory.GetResources(command);

            Assert.That(actualResources,
                        Is.InstanceOf <Resources>()
                        .With.Property("GoldCoins").EqualTo(resourcesParameters['g'])
                        .And.Property("SilverCoins").EqualTo(resourcesParameters['s'])
                        .And.Property("BronzeCoins").EqualTo(resourcesParameters['b']));
        }
Esempio n. 2
0
        public void GetResources_ShouldThrowInvalidOperationException_WhenStringCommandParameterIsNotValid(string command)
        {
            var resourcesFactory = new ResourcesFactory();

            Assert.That(() => resourcesFactory.GetResources(command),
                        Throws.InstanceOf <InvalidOperationException>().With.Message.Contains("Invalid command"));
        }
Esempio n. 3
0
        public void GetResources_ShouldThrowOverflowException_WhenCommandIsCorrectButOneOfTheValuesIsLargerThanUIntMaxValue(string command)
        {
            var resourcesFactory = new ResourcesFactory();

            Assert.That(() => resourcesFactory.GetResources(command),
                        Throws.InstanceOf <OverflowException>());
        }
Esempio n. 4
0
        public void GetResources_ShouldThrowOverflowException_WhenTheInputCommandIsCorrect_ButTheResourceAmountsAreTooBig(string command)
        {
            var resourceFactory = new ResourcesFactory();

            // Act & Assert
            Assert.Throws <OverflowException>(() => resourceFactory.GetResources(command));
        }
Esempio n. 5
0
        public void GetResources_WhenInCorrectlySetUpProperties_ShouldThrowOverflowException(String str)
        {
            var resourcesFactory = new ResourcesFactory();


            Assert.Throws <OverflowException>(() => resourcesFactory.GetResources(str));
        }
        public void GetResources_ShouldThrowOverflowException_WhenSomeOfTheValuesOverflowsUnitMaxValue(string command)
        {
            // Arrange
            var rf = new ResourcesFactory();

            // Act and Assert
            Assert.Throws<OverflowException>(() => rf.GetResources(command));
        }
        public void ThrowInvalidOperationExceptionWhenPassedCommandIsInvalidCaseFour()
        {
            //Arrange
            var sut = new ResourcesFactory();

            //Act & Assert
            Assert.ThrowsException <InvalidOperationException>(() => sut.GetResources("absolutelyRandomStringThatMustNotBeAValidCommand"));
        }
Esempio n. 8
0
        public void GetResources_WhenInCorrectlySetUpProperties_ShouldThrowInvalidOperationException(String str)
        {
            var resourcesFactory = new ResourcesFactory();

            //Assert.Throws<InvalidOperationException>(() => resourcesFactory.GetResources(str));

            Assert.That(() => resourcesFactory.GetResources(str), Throws.InvalidOperationException.With.Message.Contains("command"));
        }
Esempio n. 9
0
        public void ThrowOverflowException_WhenAnyValueIsMoreThanIntMaxValue(string command)
        {
            // Arrange
            var factory = new ResourcesFactory();

            //Act and Assert
            Assert.Throws <OverflowException>(() => factory.GetResources(command));
        }
        public void ThrowOverflowException_WhenValidCommandIsPassedButAnyOfTheValuesIsLagrerThanUintMaxValue(string overflowCommand)
        {
            // Arrange
            var factory = new ResourcesFactory();

            // Act and Assert
            Assert.Throws <OverflowException>(() => factory.GetResources(overflowCommand));
        }
        public void ThrowInvalidOperationExceptionWhenPassedCommandIsInvalidCaseThree()
        {
            //Arrange
            var sut = new ResourcesFactory();

            //Act & Assert
            Assert.ThrowsException <InvalidOperationException>(() => sut.GetResources("tansta resources a b"));
        }
        public void GetResources_WhenValidCommandWithAmountLargerThanMaxIsPassed_ShouldThrowOverflowException(string invalidCommand)
        {
            // Arrange
            var resourcesFactory = new ResourcesFactory();

            // Act&Assert
            Assert.Throws <OverflowException>(() => resourcesFactory.GetResources(invalidCommand));
        }
Esempio n. 13
0
        public void ThrowInvalidOperationExceptionWhichContainsThreStringCommand_WhenInputStringIsInvalidCommand(string input)
        {
            // arrange
            var factory = new ResourcesFactory();

            // act and assert
            Assert.Throws <InvalidOperationException>(() => factory.GetResources(input));
        }
Esempio n. 14
0
        public void GetResources_ShouldThrowOverflowException_WhenSomeOfTheValuesOverflowsUnitMaxValue(string command)
        {
            // Arrange
            var rf = new ResourcesFactory();

            // Act and Assert
            Assert.Throws <OverflowException>(() => rf.GetResources(command));
        }
Esempio n. 15
0
        public void ThrowOverflowException_WhenAnyOfTheParametersIsLargerThanMaxValue(string command)
        {
            // Arrange
            ResourcesFactory factory = new ResourcesFactory();

            // Act && Assert
            Assert.Throws <OverflowException>(() => factory.GetResources(command));
        }
        public void ThrowInvalidOperationException_WhenInvalidCommandIsPassed(string invalidCommand)
        {
            // Arrange
            var factory = new ResourcesFactory();

            // Act and Assert
            Assert.Throws <InvalidOperationException>(() => factory.GetResources(invalidCommand));
        }
        public void ThrowOverflowExceptionWhenWhenBronzeAmountExceedsTheLimit()
        {
            //Arrange
            var sut = new ResourcesFactory();

            //Act & Assert
            Assert.ThrowsException <OverflowException>(() => sut.GetResources("create resources gold(20) silver(30) bronze(4294967296)"));
        }
Esempio n. 18
0
        public void ThrowOverfloweException_WhenInputStringIsValidButAnyREsourceAmountIsBIggerThanTheUintMaxSize(string input)
        {
            // arrange
            var factory = new ResourcesFactory();

            // act and assert
            Assert.Throws <OverflowException>(() => factory.GetResources(input));
        }
        public void GetResources_WhenInvalidCommandPassed_ShouldThrowInvalidOperationException_ContainingStringCommand(string invalidCommand)
        {
            // Arrange
            var resourcesFactory = new ResourcesFactory();

            // Act&Assert
            Assert.Throws <InvalidOperationException>(() => resourcesFactory.GetResources(invalidCommand), "command");
        }
        public void ThrowInvalidOperationExceptionWhenPassedCommandIsNull()
        {
            //Arrange
            var sut = new ResourcesFactory();

            //Act & Assert
            Assert.ThrowsException <InvalidOperationException>(() => sut.GetResources(null));
        }
Esempio n. 21
0
        public void ThrowOveflowException_WhenCommandIsInValidFormatButResourcesAmountIsTooLarge(string command)
        {
            // Arrange
            var factory = new ResourcesFactory();

            // Act & Assert
            Assert.Throws <OverflowException>(() => factory.GetResources(command));
        }
        public void GetResources_ShouldThrowsInvalidOperationException_WhenInvalidCommandStringPassed(string input)
        {
            // Arrange
            var rf = new ResourcesFactory();

            // Act and Assert
            var exc = Assert.Throws<InvalidOperationException>(()=> rf.GetResources(input));
            StringAssert.Contains(expectedInvalidOperationMessage, exc.Message);
        }
Esempio n. 23
0
        public void GetResources_ShouldThrowsInvalidOperationException_WhenInvalidCommandStringPassed(string input)
        {
            // Arrange
            var rf = new ResourcesFactory();

            // Act and Assert
            var exc = Assert.Throws <InvalidOperationException>(() => rf.GetResources(input));

            StringAssert.Contains(expectedInvalidOperationMessage, exc.Message);
        }
Esempio n. 24
0
        public void ThrowInvalidOperationException_WhenCommandIsInvalid(string command)
        {
            // Arrange
            var factory = new ResourcesFactory();

            // Act & Assert
            var ex = Assert.Throws <InvalidOperationException>(() => factory.GetResources(command));

            StringAssert.Contains("command", ex.Message);
        }
Esempio n. 25
0
        public void ReturnNewlyCreatedResourcesWithCorrectlySetProperties_WhenInputStringIsInTheCorrectFormat(string command)
        {
            var factory = new ResourcesFactory();

            var resource = factory.GetResources(command);

            Assert.True(resource.BronzeCoins == 40 &&
                        resource.SilverCoins == 30 &&
                        resource.GoldCoins == 20);
        }
Esempio n. 26
0
        public void ThrowInvalidOperationExceptionWithMessageContainingCommand_WhenInvalidCommandIsPassed(string command)
        {
            var factory         = new ResourcesFactory();
            var expectedMessage = "command";

            var exc = Assert.Throws <InvalidOperationException>
                          (() => factory.GetResources(command));

            StringAssert.Contains(expectedMessage, exc.Message);
        }
Esempio n. 27
0
        GetResources_ShouldThrowOverflowException_WhenTheInputStringCommandIsInTheCorrectFormatButAnyOfTheValuesAmountIsLargerThanUintMaxValue
            (string command)
        {
            // Arrange
            string enteredCommand   = command;
            var    resourcesFactory = new ResourcesFactory();

            // Act and Assert
            var exception = Assert.Throws <OverflowException>(() => resourcesFactory.GetResources(enteredCommand));
        }
Esempio n. 28
0
        public void ThrowInvalidOperationException_WhenInvalidInputStringIsPassed(string command)
        {
            // Arrange
            var factory = new ResourcesFactory();
            var commandMessageSubstring = "command";

            //Act and Assert
            var exception = Assert.Throws <InvalidOperationException>(() => factory.GetResources(command));

            StringAssert.Contains(commandMessageSubstring, exception.Message);
        }
Esempio n. 29
0
        public void GetResourcesShouldThrowOverflowExceptionWhenValidCommandButResourceAmountTooMuch(string validCommand)
        {
            //Arrange
            var factory = new ResourcesFactory();

            // and capture
            //var createdResource = factory.GetResources(validCommand);

            //Act and Assert/check
            Assert.Throws <OverflowException>(() => factory.GetResources(validCommand));
        }
Esempio n. 30
0
        public void GetResourcesShouldReturnANewlyCreatedResourceObject(string validCommand)
        {
            //Arrange
            var factory = new ResourcesFactory();

            //Act and capture
            var createdResource = factory.GetResources(validCommand);

            //Assert/check
            Assert.IsInstanceOf <Resources>(createdResource);
        }
Esempio n. 31
0
        public void GetResources_WhenTheInputIsValid_ShouldReturnANewlyCreatedResourcesObjectWithCorrectlyProperties(string command)
        {
            var resoursFactory = new ResourcesFactory();

            var resourses = resoursFactory.GetResources(command);

            Assert.IsInstanceOf <IResources>(resourses);
            Assert.IsTrue(resourses.GoldCoins == 20);
            Assert.IsTrue(resourses.SilverCoins == 30);
            Assert.IsTrue(resourses.BronzeCoins == 40);
        }
Esempio n. 32
0
        public void GetResources_ShouldReturnInstanceOfResurceWithProperlySetProperties_IfPassedInCreationStringIsValidNoMatterOfOrder(string validCreationString)
        {
            var factory = new ResourcesFactory();

            var result = factory.GetResources(validCreationString);

            Assert.IsInstanceOf <Resources>(result);
            Assert.AreEqual(25, result.GoldCoins);
            Assert.AreEqual(35, result.SilverCoins);
            Assert.AreEqual(45, result.BronzeCoins);
        }
        public void GetResources_ShouldReturnNewlyCreatedResource_NoMatterTheOrderOfTheParams(string input)
        {
            // Arrange
            var rf = new ResourcesFactory();

            // Act
            var resource = rf.GetResources(input);

            // Assert
            Assert.AreEqual(resource.GoldCoins, goldCoins);
            Assert.AreEqual(resource.SilverCoins, silverCoins);
            Assert.AreEqual(resource.BronzeCoins, bronzeCoins);
        }