コード例 #1
0
        public static async Task Updates_requests_for_long_lead_time_and_short_lead_time()
        {
            var mockAllocationCreator = new Mock <IAllocationCreator>(MockBehavior.Strict);

            foreach (var date in AllocationDates)
            {
                var expectedLeadTimeType = LongLeadTimeDates.Contains(date) ? LeadTimeType.Long : LeadTimeType.Short;

                mockAllocationCreator
                .Setup(a => a.Create(
                           date,
                           It.IsAny <IReadOnlyCollection <Request> >(),
                           It.IsAny <IReadOnlyCollection <Reservation> >(),
                           It.IsAny <IReadOnlyList <User> >(),
                           It.IsAny <Configuration>(),
                           expectedLeadTimeType))
                .Returns(NewlyAllocatedRequests.Where(r => r.Date == date).ToArray());
            }

            var mockRequestRepository = CreateMockRequestRepository();

            var requestUpdater = new RequestUpdater(
                mockAllocationCreator.Object,
                Mock.Of <IConfigurationRepository>(),
                CreateMockDateCalculator().Object,
                mockRequestRepository.Object,
                Mock.Of <IReservationRepository>(),
                CreateUserRepository.WithUsers(DefaultUsers));

            await requestUpdater.Update();

            mockRequestRepository.VerifyAll();
        }
コード例 #2
0
        public static async Task Returns_newly_updated_requests()
        {
            var mockAllocationCreator = new Mock <IAllocationCreator>(MockBehavior.Strict);

            foreach (var date in AllocationDates)
            {
                mockAllocationCreator
                .Setup(a => a.Create(
                           date,
                           It.IsAny <IReadOnlyCollection <Request> >(),
                           It.IsAny <IReadOnlyCollection <Reservation> >(),
                           It.IsAny <IReadOnlyCollection <User> >(),
                           It.IsAny <Configuration>(),
                           It.IsAny <LeadTimeType>()))
                .Returns(NewlyAllocatedRequests.Where(r => r.Date == date).ToArray());
            }

            var requestUpdater = new RequestUpdater(
                mockAllocationCreator.Object,
                Mock.Of <IConfigurationRepository>(),
                CreateMockDateCalculator().Object,
                CreateMockRequestRepository().Object,
                Mock.Of <IReservationRepository>(),
                CreateUserRepository.WithUsers(DefaultUsers));

            var result = await requestUpdater.Update();

            Assert.NotNull(result);
            Assert.Equal(NewlyAllocatedRequests.Count, result.Count);
            Assert.All(NewlyAllocatedRequests, r => Assert.Contains(r, result));
        }
コード例 #3
0
        public static async Task Uses_newly_updated_requests_from_previous_days()
        {
            var mockAllocationCreator = new Mock <IAllocationCreator>(MockBehavior.Strict);

            foreach (var date in AllocationDates)
            {
                var expectedCumulativeRequests = InitialRequests.Where(r => r.Date < ShortLeadTimeDates.First())
                                                 .Concat(NewlyAllocatedRequests.Where(r => r.Date < date))
                                                 .Concat(InitialRequests.Where(r => r.Date >= date))
                                                 .ToArray();

                mockAllocationCreator
                .Setup(a => a.Create(
                           date,
                           It.Is <IReadOnlyCollection <Request> >(r =>
                                                                  r.Count == expectedCumulativeRequests.Length && expectedCumulativeRequests.All(r.Contains)),
                           It.IsAny <IReadOnlyCollection <Reservation> >(),
                           It.IsAny <IReadOnlyCollection <User> >(),
                           It.IsAny <Configuration>(),
                           It.IsAny <LeadTimeType>()))
                .Returns(NewlyAllocatedRequests.Where(r => r.Date == date).ToArray());
            }

            var requestUpdater = new RequestUpdater(
                mockAllocationCreator.Object,
                Mock.Of <IConfigurationRepository>(),
                CreateMockDateCalculator().Object,
                CreateMockRequestRepository().Object,
                Mock.Of <IReservationRepository>(),
                CreateUserRepository.WithUsers(DefaultUsers));

            await requestUpdater.Update();

            mockAllocationCreator.VerifyAll();
        }
コード例 #4
0
        public static async Task Uses_repository_dependencies()
        {
            var arbitraryReservation = new Reservation("user1", 4.December(2020));
            var reservations         = new[] { arbitraryReservation };

            var mockReservationRepository = new Mock <IReservationRepository>(MockBehavior.Strict);

            mockReservationRepository
            .Setup(r => r.GetReservations(EarliestConsideredDate, LastConsideredDate))
            .ReturnsAsync(reservations);

            var arbitraryUser = CreateUser.With(userId: "user1");
            var users         = new[] { arbitraryUser };

            var mockUserRepository = new Mock <IUserRepository>(MockBehavior.Strict);

            mockUserRepository
            .Setup(r => r.GetUsers())
            .ReturnsAsync(users);

            var arbitraryConfiguration = new Configuration(1, 2, 3);

            var mockConfigurationRepository = new Mock <IConfigurationRepository>(MockBehavior.Strict);

            mockConfigurationRepository
            .Setup(r => r.GetConfiguration())
            .ReturnsAsync(arbitraryConfiguration);

            var mockAllocationCreator = new Mock <IAllocationCreator>(MockBehavior.Strict);

            foreach (var date in AllocationDates)
            {
                mockAllocationCreator
                .Setup(a => a.Create(
                           date,
                           It.IsAny <IReadOnlyCollection <Request> >(),
                           reservations,
                           users,
                           arbitraryConfiguration,
                           It.IsAny <LeadTimeType>()))
                .Returns(NewlyAllocatedRequests.Where(r => r.Date == date).ToArray());
            }

            var requestUpdater = new RequestUpdater(
                mockAllocationCreator.Object,
                mockConfigurationRepository.Object,
                CreateMockDateCalculator().Object,
                CreateMockRequestRepository().Object,
                mockReservationRepository.Object,
                mockUserRepository.Object);

            await requestUpdater.Update();

            mockAllocationCreator.VerifyAll();
        }