コード例 #1
0
ファイル: FlightServiceTest.cs プロジェクト: gundarsv/FlyIt
            public async Task ReturnUnexpectedIfThrowsException()
            {
                var userFlight = new Entity.UserFlight()
                {
                    Flight = new Entity.Flight()
                    {
                        FlightNo = "FLIGHTNO",
                        Date     = DateTimeOffset.Now,
                        Status   = "Landed"
                    }
                };

                var flightResponse = new FlightsResponse()
                {
                    Data = new List <Data>()
                    {
                        new Data()
                        {
                            FlightDate = userFlight.Flight.Date,
                            Flight     = new Flight()
                            {
                                Iata = "TEST",
                            },
                            FlightStatus = "Active",
                        }
                    }
                };

                userManager.Setup(um => um.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(new User());
                repository.Setup(r => r.GetFlightByIdAsync(It.IsAny <int>())).ReturnsAsync(new Entity.Flight());
                repository.Setup(r => r.GetUserFlightByIdAsync(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(userFlight);
                repository.Setup(r => r.UpdateFlightAsync(It.Is <Entity.Flight>(f => f.FlightNo == userFlight.Flight.FlightNo))).ReturnsAsync(userFlight.Flight);
                aviationstackFlightService.Setup(asfs => asfs.GetFlight(It.IsAny <string>())).ReturnsAsync(flightResponse);
                repository.Setup(r => r.UpdateFlightAsync(It.Is <Entity.Flight>(f => f.FlightNo == flightResponse.Data[0].Flight.Iata))).ThrowsAsync(new Exception());

                var result = await service.GetFlight(It.IsAny <ClaimsPrincipal>(), It.IsAny <int>());

                userManager.Verify(um => um.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once);
                repository.Verify(r => r.GetFlightByIdAsync(It.IsAny <int>()), Times.Once);
                repository.Verify(r => r.GetUserFlightByIdAsync(It.IsAny <int>(), It.IsAny <int>()), Times.Once);
                repository.Verify(r => r.UpdateFlightAsync(It.Is <Entity.Flight>(f => f.FlightNo == userFlight.Flight.FlightNo)), Times.Once);
                aviationstackFlightService.Verify(asfs => asfs.GetFlight(It.IsAny <string>()), Times.Once);
                repository.Verify(r => r.UpdateFlightAsync(It.Is <Entity.Flight>(f => f.FlightNo == flightResponse.Data[0].Flight.Iata)), Times.Once);

                Assert.IsNull(result.Data);
                Assert.AreEqual(ResultType.Unexpected, result.ResultType);
            }
コード例 #2
0
ファイル: FlightServiceTest.cs プロジェクト: gundarsv/FlyIt
            public async Task ReturnSuccessIfCanBeUpdatedDatesAreEqualAndCompareAreEqual()
            {
                var userFlight = new Entity.UserFlight()
                {
                    Flight = new Entity.Flight()
                    {
                        FlightNo = "FLIGHTNO",
                        Date     = DateTimeOffset.Now,
                        Status   = "Landed"
                    }
                };

                userManager.Setup(um => um.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(new User());
                repository.Setup(r => r.GetFlightByIdAsync(It.IsAny <int>())).ReturnsAsync(new Entity.Flight());
                repository.Setup(r => r.GetUserFlightByIdAsync(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(userFlight);
                repository.Setup(r => r.UpdateFlightAsync(It.IsAny <Entity.Flight>())).ReturnsAsync(new Entity.Flight());
                aviationstackFlightService.Setup(asfs => asfs.GetFlight(It.IsAny <string>())).ReturnsAsync(new FlightsResponse()
                {
                    Data = new List <Data>()
                    {
                        new Data()
                        {
                            FlightDate = userFlight.Flight.Date,
                            Flight     = new Flight()
                            {
                                Iata = userFlight.Flight.FlightNo,
                            },
                            FlightStatus = userFlight.Flight.Status,
                        }
                    }
                });

                var result = await service.GetFlight(It.IsAny <ClaimsPrincipal>(), It.IsAny <int>());

                userManager.Verify(um => um.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once);
                repository.Verify(r => r.GetFlightByIdAsync(It.IsAny <int>()), Times.Once);
                repository.Verify(r => r.GetUserFlightByIdAsync(It.IsAny <int>(), It.IsAny <int>()), Times.Once);
                repository.Verify(r => r.UpdateFlightAsync(It.IsAny <Entity.Flight>()), Times.Once);
                aviationstackFlightService.Verify(asfs => asfs.GetFlight(It.IsAny <string>()), Times.Once);

                Assert.IsNotNull(result.Data);
                Assert.AreEqual(ResultType.Ok, result.ResultType);
            }