Example #1
0
        static void Main(string[] args)
        {
            var zipCode = GetZipCode();

            if (zipCode == 0)
            {
                Console.WriteLine("Exiting");
                return;
            }
            IWeatherStack _weatherStack = new WeatherStack();
            var           result        = _weatherStack.GetWeatherInformation(SerivceUrl, zipCode);

            while ((result.Success.HasValue && !result.Success.Value))
            {
                Console.WriteLine(result.Error.Info);
                Console.WriteLine("Please try again (or enter 0 to exit): ");
                zipCode = GetZipCode();
                if (zipCode == 0)
                {
                    return;
                }
                result = _weatherStack.GetWeatherInformation(SerivceUrl, zipCode);
            }

            IWeatherAnalysis _weatherAnalysis = new WeatherAnalysis();
            var canGoOutSide      = _weatherAnalysis.GoOuside(result) ? "Yes" : "No";
            var needWearSunscreen = _weatherAnalysis.WearSunscreen(result) ? "Yes" : "No";
            var canFlyKite        = _weatherAnalysis.FlyKite(result) ? "Yes" : "No";

            Console.WriteLine($"Should I go outside? {canGoOutSide}");
            Console.WriteLine($"Should I wear sunscreen? {needWearSunscreen}");
            Console.WriteLine($"Can I fly my kite? {canFlyKite}");

            Console.ReadLine();
        }
Example #2
0
        public void GoOuside_Error_Test()
        {
            mockWeather.Setup(p => p.Success).Returns(false);
            mock.Setup(p => p.GetWeatherInformation("", 0)).Returns(mockWeather.Object);

            IWeatherAnalysis weatherAnalysis = new WeatherAnalysis();
            var expected = false;
            var actual   = weatherAnalysis.GoOuside(mock.Object.GetWeatherInformation("", 0));

            actual.Should().Be(expected);
        }
Example #3
0
        public void Cant_GoOuside_Test()
        {
            mockWeatherCurrent.SetupGet <int>(p => p.WeatherCode).Returns(264);
            mockWeather.SetupGet(p => p.Current).Returns(mockWeatherCurrent.Object);
            mock.Setup(p => p.GetWeatherInformation("", 0)).Returns(mockWeather.Object);

            IWeatherAnalysis weatherAnalysis = new WeatherAnalysis();
            var expected = false;
            var actual   = weatherAnalysis.GoOuside(mock.Object.GetWeatherInformation("", 0));

            actual.Should().Be(expected, "cannot go outside when raining");
        }
Example #4
0
        public void Can_GoOuside_Test()
        {
            mockWeatherCurrent.SetupGet <int>(p => p.WeatherCode).Returns(262);
            mockWeather.SetupGet(p => p.Current).Returns(mockWeatherCurrent.Object);
            mock.Setup(p => p.GetWeatherInformation("", 0)).Returns(mockWeather.Object);

            IWeatherAnalysis weatherAnalysis = new WeatherAnalysis();
            var expected = true;
            var actual   = weatherAnalysis.GoOuside(mock.Object.GetWeatherInformation("", 0));

            actual.Should().Be(expected);
        }