예제 #1
0
        public void TestException()
        {
            //Arrange
            GetWeatherForecasts command = null;
            var handler = new GetWeatherForecastsHandler();

            //Act
            Func <Task <IReadOnlyList <WeatherForecast> > > action = () => handler.Handle(command, CancellationToken.None);

            //Assert
            action.Should().ThrowExactly <NullReferenceException>();
        }
        public async Task <IReadOnlyList <WeatherForecast> > Handle(GetWeatherForecasts request, CancellationToken cancellationToken)
        {
            if (request is null)
            {
                throw new NullReferenceException("Request cannot be null");
            }

            var rng = new Random();
            var weatherForecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date         = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary      = Summaries[rng.Next(Summaries.Length)]
            })
                                   .ToList()
                                   .AsReadOnly();

            return(await Task.FromResult <IReadOnlyList <WeatherForecast> >(weatherForecasts));
        }
예제 #3
0
        public async Task TestMethod1()
        {
            //Arrange
            var command = new GetWeatherForecasts();
            var handler = new GetWeatherForecastsHandler();

            //Act
            var result = await handler.Handle(command, CancellationToken.None);

            this.TestContext.WriteLine(result.ToString());

            //Assert
            result.Should().NotBeNull();
            result.Count.Should().Be(5);

            foreach (var item in result)
            {
                item.Summary.Should().BeOneOf(Summaries);
                item.TemperatureC.Should().BeInRange(-20, 55);
            }
        }