コード例 #1
0
            public void OptionalChildren_Still_Throws_When_Required_Children_Are_Not_Returned()
            {
                var reader = SetupDataReader(
                    new Dictionary <string, object>
                {
                    { "Id", 42 }
                });

                var toTest = new HierarchicalTypeRowFactory <BothOptionalAndNonOptionalChildren>();

                toTest.Invoking(f => f.ParseRows(reader, new IDataTransformer[0], CancellationToken.None))
                .ShouldThrow <StoredProcedureException>("because a required result set was missing");
            }
コード例 #2
0
            public void CancelsWhenTokenCanceledBeforeExecuting()
            {
                var reader = new Mock <IDataReader>();

                var cts = new CancellationTokenSource();

                cts.Cancel();

                var toTest = new HierarchicalTypeRowFactory <SolarSystem>();

                toTest.Invoking(f => f.ParseRows(reader.Object, Enumerable.Empty <IDataTransformer>(), cts.Token))
                .ShouldThrow <OperationCanceledException>("the operation was cancelled");

                reader.Verify(d => d.Read(), Times.Never);
            }
コード例 #3
0
            public void Throws_If_OptionalChildren_Returned_But_RequiredChildren_Of_OptionalChildren_AreNot()
            {
                using (GlobalSettings.UseTestInstance())
                {
                    GlobalSettings.Instance.InterfaceMap.TryAdd(typeof(ILevel4), typeof(Level4));

                    var reader = SetupDataReader(
                        new Dictionary <string, object>
                    {
                        { "Id", 42 }
                    },
                        new Dictionary <string, object>
                    {
                        { "Level2Id", 42 },
                        { "Name", 15 }
                    });

                    var toTest = new HierarchicalTypeRowFactory <OptionalRequired>();
                    toTest.Invoking(t => t.ParseRows(reader, new IDataTransformer[0], CancellationToken.None))
                    .ShouldThrow <StoredProcedureException>("because a required result set was missing");
                }
            }
コード例 #4
0
            public void CancelsWhenTokenCanceled()
            {
                var sema   = new SemaphoreSlim(0, 1);
                var values = new Dictionary <string, object>
                {
                    { "Id", 0 },
                    { "Galaxy_Id", 0 },
                    { "Name", "Sol" }
                };

                var reader = new Mock <IDataReader>();

                SetupDataReader(reader, values);
                var execCount = 0;

                reader.Setup(d => d.Read())
                .Callback(() =>
                {
                    sema.Release();
                    Thread.Sleep(100);
                    ++execCount;
                })
                .Returns(() => execCount == 1);

                var cts = new CancellationTokenSource();

                var toTest = new HierarchicalTypeRowFactory <SolarSystem>();
                var task   = Task.Factory.StartNew(() => toTest.Invoking(f => f.ParseRows(reader.Object, Enumerable.Empty <IDataTransformer>(), cts.Token))
                                                   .ShouldThrow <OperationCanceledException>("the operation was cancelled"),
                                                   cts.Token);

                sema.Wait(TimeSpan.FromMilliseconds(250));
                cts.Cancel();

                task.Wait(TimeSpan.FromMilliseconds(250)).Should().BeTrue();
            }