Пример #1
0
        public async Task ChangeBuilderAsync__DelegatesToCollectionManager()
        {
            var awaited = false;

            MockedCollectionsManager.Setup(_ => _.ChangeBuilderAsync(It.IsAny <ICollection <IData> >(), It.IsAny <IDataBuilder <IData> >()))
            .Returns(Task.Delay(200).ContinueWith(_ => awaited = true));

            await TestInstance.ChangeBuilderAsync(Collection, DataBuilder);

            MockedCollectionsManager.Verify(_ => _.ChangeBuilderAsync(Collection, DataBuilder));
            Assert.IsTrue(awaited);
        }
        public async Task ChangeBuilderAsync__ItemsBuildUsingChangedBuilder()
        {
            var collection = new List <IData>()
            {
                new Mock <IData>().Object, new Mock <IData>().Object
            };
            var mockedDataBuilder = new Mock <IDataBuilder <IData> >();
            var dataBuilder       = mockedDataBuilder.Object;

            TestInstance.RegisterCollection(collection, Descriptor, DataBuilder);
            await TestInstance.ChangeBuilderAsync(collection, dataBuilder);

            foreach (var item in collection)
            {
                mockedDataBuilder.Verify(_ => _.DoWorkAsync(item));
            }
        }
        public async Task ChangeBuilderAsync_CollectionNotRegistered_InvalidOperationException()
        {
            var caught = false;

            MockedTestInstance.Setup(_ => _.BuildCollectionAsync(It.IsAny <ICollection <IData> >()))
            .Returns(Task.FromResult(0));

            try
            {
                await TestInstance.ChangeBuilderAsync(Collection, DataBuilder);
            }
            catch (InvalidOperationException)
            {
                caught = true;
            }

            Assert.IsTrue(caught);
        }