Exemplo n.º 1
0
        public async Task <TestingModel> CalculateSomethingRandom(int a, int b)
        {
            var value = RandomService.GenerateRandomValue(1, 1000);

            var sleep = await Sleepy.SleepForATime();

            if (!sleep)
            {
                FactoryException.Create();
            }

            var result = FactoryTestingModel.Empty();

            if (value < 250 && value > 0)
            {
                result = FactoryTestingModel.Create("Plus", value, a + b);
            }
            else if (value < 500 && value >= 250)
            {
                result = FactoryTestingModel.Create("Minus 10", value, a + b - 10);
            }
            else if (value < 750 && value >= 500)
            {
                result = FactoryTestingModel.Create("Plus 10", value, a + b + 10);
            }
            else if (value <= 1000 && value >= 750)
            {
                result = FactoryTestingModel.Create("Plus 20", value, a + b + 20);
            }
            else
            {
                FactoryException.Create("Out of range");
            }
            return(await AsyncExecutor.FromResult(result));
        }
        public void CreateWithMessageTest(string message, FactoryException sut)
        {
            //act
            var expected = Assert.Throws <Exception>(() => sut.Create(message));

            //assert
            Assert.NotNull(expected);
            Assert.IsType <Exception>(expected);
            Assert.Equal(expected.Message, message);
        }