public async Task FillCollectionAsync__CollectionFilledWithData()
        {
            MockedTestInstance.Setup(_ => _.RegisterCollection(It.IsAny <ICollection <IData> >(),
                                                               It.IsAny <INonTerminalDescriptor>(), It.IsAny <IDataBuilder <IData> >()));
            MockedTestInstance.Setup(_ => _.FillCollectionWithData(It.IsAny <ICollection <IData> >(),
                                                                   It.IsAny <INonTerminalDescriptor>()));
            MockedTestInstance.Setup(_ => _.BuildCollectionAsync(It.IsAny <ICollection <IData> >()))
            .Returns(Task.FromResult(0));

            await TestInstance.FillCollectionAsync(new FillCollectionArgs <IData>(Collection, Descriptor));

            MockedTestInstance.Verify(_ => _.FillCollectionWithData(Collection, Descriptor));
        }
        public async Task FillCollectionAsync__Builder_AlreadyRegisteredWithDescriptor_CollectionNotEmpty__ChangeBuilderDelegatedToRepository()
        {
            MockedCollection.Setup(_ => _.Count).Returns(RandomizationHelper.Instance.GetInt());
            MockedTestInstance.Setup(_ =>
                                     _.IsCollectionRegisteredWithDescriptor(It.IsAny <ICollection <IData> >(),
                                                                            It.IsAny <INonTerminalDescriptor>())).Returns(true);
            MockedDataRepository.Setup(_ => _.FillCollectionAsync(It.IsAny <IFillCollectionArgs <IData> >()))
            .Returns(Task.FromResult(0));

            await TestInstance.FillCollectionAsync(Collection, Descriptor, DataBuilder);

            MockedDataRepository.Verify(_ => _.ChangeBuilderAsync(Collection, DataBuilder), Times.Once);
        }
        public async Task FillCollectionAsync__NoBuilder_AlreadyRegisteredWithDescriptor_CollectionEmpty__DelegatedToRepository()
        {
            MockedCollection.Setup(_ => _.Count).Returns(0);
            MockedTestInstance.Setup(_ =>
                                     _.IsCollectionRegisteredWithDescriptor(It.IsAny <ICollection <IData> >(),
                                                                            It.IsAny <INonTerminalDescriptor>())).Returns(true);
            MockedDataRepository.Setup(_ => _.FillCollectionAsync(It.IsAny <IFillCollectionArgs <IData> >()))
            .Returns(Task.FromResult(0));

            await TestInstance.FillCollectionAsync(Collection, Descriptor);

            MockedDataRepository.Verify(_ => _.FillCollectionAsync(It.IsAny <IFillCollectionArgs <IData> >()));
        }
Пример #4
0
        public async Task FillCollectionAsync__CollectionFilled()
        {
            var awaited = false;

            MockedTestInstance.Setup(_ => _.Acquire(It.IsAny <INonTerminalDescriptor>()))
            .Returns(Task.Delay(0));
            MockedCollectionsManager.Setup(_ => _.FillCollectionAsync(It.IsAny <IFillCollectionArgs <IData> >()))
            .Returns(Task.Delay(200).ContinueWith(_ => awaited = true));

            await TestInstance.FillCollectionAsync(FillCollectionArgs);

            MockedCollectionsManager.Verify(_ => _.FillCollectionAsync(FillCollectionArgs));
            Assert.IsTrue(awaited);
        }
        public async Task FillCollectionAsync__Builder_NotAlreadyRegisteredWithDescriptor__ChangeBuilderNotDelegatedToRepository()
        {
            MockedTestInstance.Setup(_ =>
                                     _.IsCollectionRegisteredWithDescriptor(It.IsAny <ICollection <IData> >(),
                                                                            It.IsAny <INonTerminalDescriptor>())).Returns(false);
            MockedDataRepository.Setup(_ => _.FillCollectionAsync(It.IsAny <IFillCollectionArgs <IData> >()))
            .Returns(Task.FromResult(0));

            await TestInstance.FillCollectionAsync(Collection, Descriptor, DataBuilder);

            MockedDataRepository.Verify(
                _ => _.ChangeBuilderAsync(It.IsAny <ICollection <IData> >(), It.IsAny <IDataBuilder <IData> >()),
                Times.Never);
        }
        public async Task FillCollectionAsync_KeepSyncedSpecified_CollectionBuiltUsingRegisteredBuilder()
        {
            var awaited = false;

            MockedTestInstance.Setup(_ => _.RegisterCollection(It.IsAny <ICollection <IData> >(),
                                                               It.IsAny <INonTerminalDescriptor>(), It.IsAny <IDataBuilder <IData> >()));
            MockedTestInstance.Setup(_ => _.FillCollectionWithData(It.IsAny <ICollection <IData> >(),
                                                                   It.IsAny <INonTerminalDescriptor>()));
            MockedTestInstance.Setup(_ => _.BuildCollectionAsync(It.IsAny <ICollection <IData> >()))
            .Returns(Task.Delay(10).ContinueWith(_ => awaited = true));

            await TestInstance.FillCollectionAsync(new FillCollectionArgs <IData>(Collection, Descriptor));

            MockedTestInstance.Verify(_ => _.BuildCollectionAsync(Collection));
            Assert.IsTrue(awaited);
        }
Пример #7
0
        public async Task FillCollectionAsync__CollectionFilledAfterDataAcquired()
        {
            var callCounter              = 0;
            var acquireDataCallNumber    = 0;
            var fillCollectionCallNumber = 0;

            MockedTestInstance.Setup(_ => _.Acquire(It.IsAny <INonTerminalDescriptor>()))
            .Callback(() => acquireDataCallNumber = ++callCounter)
            .Returns(Task.Delay(10));
            MockedCollectionsManager.Setup(_ => _.FillCollectionAsync(It.IsAny <IFillCollectionArgs <IData> >()))
            .Callback(() => fillCollectionCallNumber = ++callCounter)
            .Returns(Task.Delay(10));

            await TestInstance.FillCollectionAsync(FillCollectionArgs);

            Assert.IsTrue(fillCollectionCallNumber > acquireDataCallNumber);
        }
        public async Task FillCollectionAsync__CollectionFilledWithDataAfterRegistration()
        {
            var callCounter              = 0;
            var registrationCallNumber   = 0;
            var fillCollectionCallNumber = 0;

            MockedTestInstance.Setup(_ => _.RegisterCollection(It.IsAny <ICollection <IData> >(), It.IsAny <INonTerminalDescriptor>(),
                                                               It.IsAny <IDataBuilder <IData> >()))
            .Callback(() => registrationCallNumber = ++callCounter);
            MockedTestInstance.Setup(_ => _.FillCollectionWithData(It.IsAny <ICollection <IData> >(),
                                                                   It.IsAny <INonTerminalDescriptor>())).Callback(() => fillCollectionCallNumber = ++callCounter);
            MockedTestInstance.Setup(_ => _.BuildCollectionAsync(It.IsAny <ICollection <IData> >()))
            .Returns(Task.FromResult(0));

            await TestInstance.FillCollectionAsync(new FillCollectionArgs <IData>(Collection, Descriptor));

            Assert.IsTrue(fillCollectionCallNumber > registrationCallNumber);
        }
        public async Task FillCollectionAsync__Builder_NotAlreadyRegisteredWithDescriptor__FillDelegatedToRepository()
        {
            var awaited = false;

            MockedTestInstance.Setup(_ =>
                                     _.IsCollectionRegisteredWithDescriptor(It.IsAny <ICollection <IData> >(),
                                                                            It.IsAny <INonTerminalDescriptor>())).Returns(false);
            MockedDataRepository.Setup(_ =>
                                       _.FillCollectionAsync(It.IsAny <IFillCollectionArgs <IData> >()))
            .Returns(Task.Delay(10).ContinueWith(_ => awaited = true));

            await TestInstance.FillCollectionAsync(Collection, Descriptor, DataBuilder);

            MockedDataRepository.Verify(_ =>
                                        _.FillCollectionAsync(It.Is <IFillCollectionArgs <IData> >(args =>
                                                                                                   Equals(args.Collection, Collection) && args.Descriptor == Descriptor && args.Builder == DataBuilder)));
            Assert.IsTrue(awaited);
            MockedTestInstance.Verify(_ => _.IsCollectionRegisteredWithDescriptor(Collection, Descriptor));
        }