Exemplo n.º 1
0
        public static FizzBuzzOperationResults ExecuteFizzBuzz(object objectToDivide, int lowNumber, int highNumber)
        {
            var result = new FizzBuzzOperationResults();
            result.ResultDictionary = new Dictionary<DividendQuotientPair, string>();

            if (lowNumber > highNumber)
            {
                result.RunStatus = FizzBuzzOperationResultCodes.LowerNumberIsHigherThanHighNumber;
                return result;
            }

            var isImplementingIAmDivisibleInterface = objectToDivide as IAmDivisible != null;
            var areNumbersEqual = lowNumber == highNumber;
            var objToDivide = objectToDivide as IAmDivisible;

            if (isImplementingIAmDivisibleInterface)
            {
                bool divisibleByMinValue = objToDivide.AmDivisibleBy(lowNumber);
                bool divisibleByMaxValue = objToDivide.AmDivisibleBy(highNumber);

                if (divisibleByMinValue && divisibleByMaxValue)
                {
                    result.RunStatus = FizzBuzzOperationResultCodes.FizzBuzz;
                    result.ResultDictionary = PopulateDicitonary(areNumbersEqual, objToDivide, lowNumber, highNumber);
                    result.logger.LogValidAction(objectToDivide.GetType().ToString(), lowNumber, highNumber, result.RunStatus.ToString());
                }
                else if (divisibleByMaxValue)
                {
                    result.RunStatus = FizzBuzzOperationResultCodes.Buzz;
                    result.ResultDictionary = PopulateDicitonary(areNumbersEqual, objToDivide, lowNumber, highNumber);
                    result.logger.LogValidAction(objectToDivide.GetType().ToString(), lowNumber, highNumber, result.RunStatus.ToString());
                }
                else if (divisibleByMinValue)
                {
                    result.RunStatus = FizzBuzzOperationResultCodes.Fizz;
                    result.ResultDictionary = PopulateDicitonary(areNumbersEqual, objToDivide, lowNumber, highNumber);
                    result.logger.LogValidAction(objectToDivide.GetType().ToString(), lowNumber, highNumber, result.RunStatus.ToString());
                }
            }
            else
            {
                result.RunStatus = FizzBuzzOperationResultCodes.InvalidType;
                if (objectToDivide == null)
                {
                    result.ResultDictionary = PopulateDicitonary(areNumbersEqual, null, lowNumber, highNumber);
                    result.logger.LogInvalidAction("null", lowNumber, highNumber, result.RunStatus.ToString());
                }
                else
                {
                    result.ResultDictionary = PopulateDicitonary(areNumbersEqual, objectToDivide, lowNumber, highNumber);
                    result.logger.LogInvalidAction(objectToDivide.GetType().ToString(), lowNumber, highNumber, result.RunStatus.ToString());
                }
            }

            return result;
        }
Exemplo n.º 2
0
        public void ExecuteFizzBuzz_ValidDataType_FizzBuzz_DifferentButDivisibleNumbers()
        {
            // Arrange
            var expectedResult = new FizzBuzzOperationResults(FizzBuzzOperationResultCodes.FizzBuzz);
            var supportedDateType = new Cake("Chocolate", 10);

            // Act
            var actualresult = FizzBuzz.ExecuteFizzBuzz(supportedDateType, 5, 10);

            // Assert
            Assert.AreEqual(expectedResult.RunStatus, actualresult.RunStatus);
        }
Exemplo n.º 3
0
        public void ExecuteFizzBuzz_InvalidDataType()
        {
            // Arrange
            var expectedResult = new FizzBuzzOperationResults(FizzBuzzOperationResultCodes.InvalidType);
            var unsupportedObjectType = new Stopwatch();

            // Act
            var actualresult = FizzBuzz.ExecuteFizzBuzz(unsupportedObjectType, 5, 10);

            // Assert
            Assert.AreEqual(expectedResult.RunStatus, actualresult.RunStatus);
        }
Exemplo n.º 4
0
        public void ExecuteFizzBuzz_LowerNumberIsHigherThanHighNumber()
        {
            // Arrange
            var expectedResult = new FizzBuzzOperationResults(FizzBuzzOperationResultCodes.LowerNumberIsHigherThanHighNumber);
            var supportedDateType = new Cake("Chocolate", 10);
            var lowNumber = 100;

            var highNumber = 20;

            // Act
            var actualresult = FizzBuzz.ExecuteFizzBuzz(supportedDateType, lowNumber, highNumber);

            // Assert
            Assert.AreEqual(expectedResult.RunStatus, actualresult.RunStatus);
        }
        public void RepresentationOfResultAsStringMakesSense()
        {
            // Arrange
            var resultOfDivisionWithLow = 10;
            var resultOfDivisionWithHigh = 2;
            var lowValue = 10;
            var highValue = 90;

            var expectedResultDictionary = TestingFactory.GetDictionary();

            // Act
            var sut = new FizzBuzzOperationResults(FizzBuzzOperationResultCodes.Fizz, expectedResultDictionary);
            var actualResult = sut.ToString();

            // Assert
        }
Exemplo n.º 6
0
        private Operation ProcessRequest(string typeOfObjectToUse, string lowValue,
            string highValue, FizzBuzzOperationResults fizzBuzzResult)
        {
            var typeUsed = new List<Models.Type>()
            {
                new Models.Type() {Name = typeOfObjectToUse}
            };

            var result = new Operation()
            {
                LowNumber = int.Parse(lowValue),
                HighNumber = int.Parse(highValue),
                DateExecuted = DateTime.Now,
                Output = fizzBuzzResult.RunStatus.ToString(),
                Result = fizzBuzzResult.ToString(),
                Types = typeUsed
            };

            return result;
        }
Exemplo n.º 7
0
 public FizzBuzzServiceResponse(FizzBuzzOperationResults operationResults, FizzBuzzServiceResponseCode ServiceResponseCode, Exception Exception)
 {
 }
Exemplo n.º 8
0
 public FizzBuzzServiceResponse(FizzBuzzOperationResults operationResults)
 {
 }
Exemplo n.º 9
0
        public void Run_CollectionOf_InValidObjects()
        {
            // Arrange
            var expectedOperationResult = new FizzBuzzOperationResults();
            expectedOperationResult.RunStatus = FizzBuzzOperationResultCodes.InvalidType;
            expectedOperationResult.ResultDictionary = TestingFactory.GetDictionary(1);

            var listOfExpectedResult = new List<FizzBuzzOperationResults>()
            {
                expectedOperationResult,
                expectedOperationResult,
                expectedOperationResult,
                expectedOperationResult,
                expectedOperationResult
            };

            var testValues = new List<object>()
            {
                new Stopwatch(),
                1,
                "Hello there string!",
                FizzBuzzOperationResultCodes.Fizz,
                null
            };

            // Act
            var listOfActualresults = FizzBuzz.Run(testValues, 10, 90);

            // Assert
            for (int i = 0; i < listOfExpectedResult.Count; i++)
            {
                Assert.AreEqual(listOfExpectedResult[i].RunStatus, listOfActualresults[i].RunStatus);
                Assert.AreEqual(listOfExpectedResult[i].ResultDictionary.Count, listOfActualresults[i].ResultDictionary.Count);
            }
        }
Exemplo n.º 10
0
        public void Run_CollectionOf_BothValidAndInvalidValues_NumbersAre0_ObjectDividendIs0()
        {
            // Arrange
            var expectedOperationResult = new FizzBuzzOperationResults();
            expectedOperationResult.RunStatus = FizzBuzzOperationResultCodes.ObjectValueIsZero;
            expectedOperationResult.ResultDictionary = new Dictionary<DividendQuotientPair, string>();
            var expectedDictionaryOfResults = TestingFactory.GetDictionary();
            var listOfExpectedResult = new List<FizzBuzzOperationResults>()
            {
                expectedOperationResult,
                new FizzBuzzOperationResults(FizzBuzzOperationResultCodes.InvalidType, expectedDictionaryOfResults),
                expectedOperationResult,
                new FizzBuzzOperationResults(FizzBuzzOperationResultCodes.InvalidType, expectedDictionaryOfResults),
                expectedOperationResult,
                new FizzBuzzOperationResults(FizzBuzzOperationResultCodes.InvalidType, expectedDictionaryOfResults),
                expectedOperationResult,
                new FizzBuzzOperationResults(FizzBuzzOperationResultCodes.InvalidType, expectedDictionaryOfResults),
                expectedOperationResult,
                new FizzBuzzOperationResults(FizzBuzzOperationResultCodes.InvalidType, expectedDictionaryOfResults)
            };

            var testValues = new List<object>()
            {
                new Cake("Shoe", 00), //0
                new Stopwatch(),
                new Cake("Strawberry", 0), //2
                1,
                new Cake("Chocolate", 00000), //4
                "Hello there string!",
                new Cake("Vanilla", 00000000), //6
                FizzBuzzOperationResultCodes.Fizz,
                new Cake("Mouse", 0000), //8
                null
            };

            // Act
            var listOfActualresults = FizzBuzz.Run(testValues, 0, 0);

            // Assert
            for (int i = 0; i < listOfExpectedResult.Count; i++)
            {
                Assert.AreEqual(listOfExpectedResult[i].RunStatus, listOfActualresults[i].RunStatus);
                Assert.AreEqual(listOfExpectedResult[i].ResultDictionary.Count, listOfActualresults[i].ResultDictionary.Count);
            }
        }