Ejemplo n.º 1
0
        public async Task AcquireMissingData__TerminalDescriptor_DataContained__DataNotRetrieved()
        {
            MockedDataPool.Setup(_ => _.Contains(It.IsAny <ITerminalDescriptor>())).Returns(true);
            MockedDataRetriever.Setup(_ => _.RetrieveAsync(It.IsAny <ITerminalDescriptor>()))
            .Returns(Task.FromResult(InstanceRetrievalContext));

            await TestInstance.Acquire(TerminalDescriptor);

            MockedDataRetriever.Verify(_ => _.RetrieveAsync(It.IsAny <ITerminalDescriptor>()), Times.Never);
        }
Ejemplo n.º 2
0
        public async Task AcquireMissingData__TerminalDescriptor_DataNotContained__RetrievedDataSaved()
        {
            MockedDataPool.Setup(_ => _.Contains(It.IsAny <ITerminalDescriptor>())).Returns(false);
            MockedDataRetriever.Setup(_ => _.RetrieveAsync(It.IsAny <ITerminalDescriptor>()))
            .Returns(Task.FromResult(InstanceRetrievalContext));

            await TestInstance.Acquire(TerminalDescriptor);

            MockedDataPool.Verify(_ => _.SaveAsync(TerminalDescriptor, InstanceRetrievalContext, It.IsAny <Action>()));
        }
Ejemplo n.º 3
0
        public async Task AcquireMissingData_DataNotContained_DataCorrectlyRetrieved()
        {
            MockedDataPool.Setup(_ => _.Contains(It.IsAny <INonTerminalDescriptor>())).Returns(false);
            MockedDataRetriever.Setup(_ => _.RetrieveAsync(It.IsAny <INonTerminalDescriptor>()))
            .Returns(Task.FromResult(CollectionRetrievalContext));

            await TestInstance.Acquire(Descriptor);

            MockedDataRetriever.Verify(_ => _.RetrieveAsync(Descriptor));
        }
Ejemplo n.º 4
0
        public async Task AcquireMissingData_DataContained_DataSaveNotAttempted()
        {
            MockedDataPool.Setup(_ => _.Contains(It.IsAny <INonTerminalDescriptor>())).Returns(true);
            MockedDataRetriever.Setup(_ => _.RetrieveAsync(It.IsAny <INonTerminalDescriptor>()))
            .Returns(Task.FromResult(CollectionRetrievalContext));

            await TestInstance.Acquire(Descriptor);

            MockedDataPool.Verify(_ => _.SaveAsync(It.IsAny <INonTerminalDescriptor>(), It.IsAny <ICollectionRetrievalContext <IData> >()),
                                  Times.Never);
        }
Ejemplo n.º 5
0
        public async Task RetrieveAsync_TerminalDescriptor_DataRetrievedFromPool()
        {
            MockedTestInstance.Setup(_ => _.Acquire(It.IsAny <ITerminalDescriptor>()))
            .Returns(Task.FromResult(0));
            MockedDataPool.Setup(_ => _.Retrieve(It.IsAny <ITerminalDescriptor>()))
            .Returns(Data);

            var result = await TestInstance.RetrieveAsync(TerminalDescriptor);

            Assert.AreSame(result, Data);
            MockedDataPool.Verify(_ => _.Retrieve(TerminalDescriptor));
        }
Ejemplo n.º 6
0
        public async Task RetrieveAsync_NonTerminalDescriptor_DataRetrievedAfterBeingAcquired()
        {
            var callCounter      = 0;
            var acquireDataCall  = 0;
            var retrieveDataCall = 0;

            MockedTestInstance.Setup(_ => _.Acquire(It.IsAny <INonTerminalDescriptor>()))
            .Callback(() => acquireDataCall = ++callCounter)
            .Returns(Task.CompletedTask);
            MockedDataPool.Setup(_ => _.Retrieve(It.IsAny <INonTerminalDescriptor>()))
            .Callback(() => retrieveDataCall = ++callCounter);

            await TestInstance.RetrieveAsync(Descriptor);

            Assert.IsTrue(retrieveDataCall > acquireDataCall);
        }