Ejemplo n.º 1
0
        public Mock <PaymentPlanProcessor> CreateMockModelForQueue()
        {
            ProcessCalled = new List <int>();
            var mockModel = new Mock <PaymentPlanProcessor>(MockProcessor.Object, MockContacts.Object, MockPlans.Object, new RandomGenerator(), Config)
            {
                CallBase = true
            };

            mockModel.Setup(x => x.ProcessAsync(It.IsAny <ApiCustomContact>(), It.IsAny <IEnumerable <ApiPaymentPlan> >(), It.IsAny <DateTimeOffset>()))
            .Returns <ApiCustomContact, IEnumerable <ApiPaymentPlan>, DateTimeOffset>((contact, planList, currentDate) =>
            {
                ProcessCalled.Add(contact.Id !.Value);
                return(Task.FromResult(new PaymentResult()));
            });
            MockContacts.Setup(x => x.SelectAsync(It.IsAny <int>()))
            .Returns <int>((id) => Task.FromResult(new ApiCustomContact()
            {
                Id = id
            }));
            MockPlans.Setup(x => x.SelectAsync(It.IsAny <ApiSearchOptions>()))
            .Returns(Task.FromResult <IList <ApiPaymentPlan> >(new List <ApiPaymentPlan>()));
            return(mockModel);
        }
Ejemplo n.º 2
0
        public async Task ProcessInQueueAsync_LongTask_WaitUntilFinish()
        {
            var mockModel = CreateMockModelForQueue();

            MockPlans.Setup(x => x.SelectAsync(It.IsAny <ApiSearchOptions>()))
            .Returns(async() =>
            {
                await Task.Delay(100);
                return(new List <ApiPaymentPlan>());
            });

            var task1 = mockModel.Object.ProcessInQueueAsync(1, 0, _now).ConfigureAwait(false);
            var task2 = mockModel.Object.ProcessInQueueAsync(2, 0, _now).ConfigureAwait(false);
            var task3 = mockModel.Object.ProcessInQueueAsync(3, 0, _now).ConfigureAwait(false);

            var result1 = await task1;

            Assert.Single(ProcessCalled);
            var result2 = await task2;

            Assert.Equal(2, ProcessCalled.Count);
            await task3;
        }