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); }
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>())); }
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)); }
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); }
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)); }
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); }