コード例 #1
0
        public async Task CreateAirlineCommandHandler_Should_ChatchThrownAnyExeception()
        {
            var repositoryMock = new Mock <IFlightRepository>();
            var bussinesMock   = new Mock <IBussinesRuleEvaluator>();

            repositoryMock.Setup(x => x.GetScheduledFlightAsync(It.IsAny <int>())).ThrowsAsync(new Exception("Test"));
            var sut = new GetSummaryQueryHandler(repositoryMock.Object, bussinesMock.Object);

            // Act
            await Assert.ThrowsAsync <Exception>(() => sut.Handle(new GetSummaryQuery(), CancellationToken.None));
        }
コード例 #2
0
        public async Task Handle_WithExistingEstimates_ReturnCorrectSummary(decimal optimisticEstimate, decimal pessimisticEstimate, int teamSize)
        {
            var clients = Builder <Client>
                          .CreateListOfSize(10)
                          .All()
                          .With((c, index) => c.AccountManager = new Domain.ValueObjects.Contact($"Email-{index}", $"DisplayName-{index}"))
                          .With(x => x.Id = 0)
                          .Build();

            var estimates = Builder <Estimate>
                            .CreateListOfSize(20)
                            .All().With(x => x.Id            = 0)
                            .TheFirst(10).With(e => e.Client = clients[0])
                            .TheRest().With(e => e.Client    = clients[1])
                            .Build();

            var backlogItems = Builder <BacklogItem>
                               .CreateListOfSize(30)
                               .All().With(x => x.Id = 0)
                               .TheFirst(10).With(bi => bi.Estimate = estimates[0])
                               .With(bi => bi.OptimisticEstimate    = optimisticEstimate)
                               .With(bi => bi.PessimisticEstimate   = pessimisticEstimate)
                               .TheNext(10).With(bi => bi.Estimate  = estimates[1])
                               .TheRest().With(bi => bi.Estimate    = estimates[2])
                               .Build();

            using (var db = new InMemoryDataContextBuilder()
                            .WithClients(clients)
                            .WithEstimates(estimates)
                            .WithBackloItems(backlogItems)
                            .BuildScoped())
            {
                var startDate = new System.DateTime(2000, 1, 1);

                // Setup mock
                var mockDateTimeProvider = Substitute.For <IDateTimeProvider>();
                mockDateTimeProvider.Now.Returns(startDate);

                var handler = new GetSummaryQueryHandler(db.Context, mockDateTimeProvider);

                var result = await handler.Handle(new GetSummaryQuery(estimates[0].Id, teamSize), CancellationToken.None);

                decimal expectedOptimisticDuration  = ((optimisticEstimate * 10) / 8) / teamSize;
                decimal expectedPessimisticDuration = ((pessimisticEstimate * 10) / 8) / teamSize;

                result.OptimisticDuration.Should().Be(expectedOptimisticDuration);
                result.PessimisticDuration.Should().Be(expectedPessimisticDuration);
                result.OptimisticEndDate.Should().BeSameDateAs(startDate.AddDays((double)expectedOptimisticDuration));
                result.PessimisticEndDate.Should().BeSameDateAs(startDate.AddDays((double)expectedPessimisticDuration));
            }
        }
コード例 #3
0
        public async Task CreateAirlineCommandHandler_Should_Handle_FLIGHTMAYNOTPROCEED_GivenValidRequest()
        {
            // Arrange
            var repositoryMock = new Mock <IFlightRepository>();
            var bussinesMock   = new Mock <IBussinesRuleEvaluator>();

            repositoryMock.Setup(x => x.GetScheduledFlightAsync(It.IsAny <int>())).ReturnsAsync(new Flight()
            {
                Id         = 1,
                Passengers = new List <Passenger>()
                {
                    new Passenger()
                    {
                        Type = PassengerType.GENERAL,
                        Name = "Test",
                        Age  = 23,
                    }
                },
                FlightRoute = new FlightRoute("London", "Paris")
                {
                    BaseCost                 = 50,
                    BasePrice                = 100,
                    LoyaltyPointsGained      = 5,
                    MinimumTakeOffPercentage = 0.7
                },
                Plane = new Plane
                {
                    Id            = 123,
                    Name          = "Antonov AN-2",
                    NumberOfSeats = 12
                },
            });
            repositoryMock.Setup(x => x.GetScheduledFlightsAsync()).ReturnsAsync(new List <Flight>()
            {
                new Flight()
                {
                    Id          = 2,
                    Passengers  = new List <Passenger>(),
                    FlightRoute = new FlightRoute("test", "test"),
                    Plane       = new Plane {
                        Id            = 124,
                        Name          = "Bombardier Q400",
                        NumberOfSeats = 12
                    }
                },
                new Flight()
                {
                    Id          = 3,
                    Passengers  = new List <Passenger>(),
                    FlightRoute = new FlightRoute("test", "test"),
                    Plane       = new Plane {
                        Id            = 125,
                        Name          = "ATR 640",
                        NumberOfSeats = 12
                    }
                }
            });

            var sut = new GetSummaryQueryHandler(repositoryMock.Object, bussinesMock.Object);

            // Act
            var result = await sut.Handle(new GetSummaryQuery(), CancellationToken.None);

            // Assert
            Assert.Contains("General sales: 1", result);
            Assert.Contains("Discounted sales: 0", result);
            Assert.Contains("Loyalty member sales: 0", result);
            Assert.Contains("Airline employee comps: 0", result);
            Assert.Contains("FLIGHT MAY NOT PROCEED", result);
        }
コード例 #4
0
        public async Task CreateAirlineCommandHandler_Should_Handle_FLIGHTMAYPROCEED_GivenValidRequest()
        {
            // Arrange
            var repositoryMock = new Mock <IFlightRepository>();
            var bussinesMock   = new Mock <IBussinesRuleEvaluator>();


            repositoryMock.Setup(x => x.GetScheduledFlightAsync(It.IsAny <int>())).ReturnsAsync(new Flight()
            {
                Id         = 1,
                Passengers = new List <Passenger>()
                {
                    new Passenger()
                    {
                        Type = PassengerType.GENERAL,
                        Name = "Test1",
                        Age  = 12,
                    },
                    new Passenger()
                    {
                        Type = PassengerType.DISCOUNTED,
                        Name = "Test2",
                        Age  = 13,
                    },
                    new Passenger()
                    {
                        Type = PassengerType.AIRLINEEMPLOYEE,
                        Name = "Test3",
                        Age  = 15,
                    },
                    new Passenger()
                    {
                        Type = PassengerType.LOYALTYMEMBER,
                        Name = "Test4",
                        Age  = 16,
                    }
                },
                FlightRoute = new FlightRoute("London", "Paris")
                {
                    BaseCost                 = 50,
                    BasePrice                = 100,
                    LoyaltyPointsGained      = 5,
                    MinimumTakeOffPercentage = 0
                },
                Plane = new Plane
                {
                    Id            = 123,
                    Name          = "Antonov AN-2",
                    NumberOfSeats = 4
                },
            });
            bussinesMock.Setup(x => x.Evaluate(It.IsAny <FlightInfo>(), It.IsAny <List <IBussinesRule> >())).Returns(true);
            var sut = new GetSummaryQueryHandler(repositoryMock.Object, bussinesMock.Object);

            // Act
            var result = await sut.Handle(new GetSummaryQuery(), CancellationToken.None);

            // Assert
            Assert.Contains("General sales: 1", result);
            Assert.Contains("Discounted sales: 1", result);
            Assert.Contains("Loyalty member sales: 1", result);
            Assert.Contains("Airline employee comps: 1", result);
            Assert.Contains("THIS FLIGHT MAY PROCEED", result);
        }