Beispiel #1
0
        private static IOperation <IPersistedObjectSpace> CreateAndGetCore(IAssertOperationFactory assert) =>
        Operation.Sequence(

            //
            // Exceptions thrown by Create.
            //
            Operation.Sequence(
                assert.ThrowsException <ArgumentNullException>().When(PersistedObjectSpaceOperation.CreateQueue <int>(null))
                ),

            //
            // Exceptions thrown by Get.
            //
            Operation.Sequence(
                assert.ThrowsException <ArgumentNullException>().When(PersistedObjectSpaceOperation.GetQueue <int>(null)),
                assert.ThrowsException <KeyNotFoundException>().When(PersistedObjectSpaceOperation.GetQueue <int>("bar"))
                ),

            //
            // Exceptions thrown by Delete.
            //
            Operation.Sequence(
                assert.ThrowsException <KeyNotFoundException>().When(PersistedObjectSpaceOperation.Delete("bar"))
                ),

            //
            // Create a new queue.
            //
            PersistedObjectSpaceOperation.CreateQueue <int>("bar").Apply(queue =>

                                                                         //
                                                                         // Check the new queue is present in the object space.
                                                                         //
                                                                         Operation.Sequence(

                                                                             //
                                                                             // Assert we can get the same instance back using GetQueue.
                                                                             //
                                                                             assert.AreSame(
                                                                                 PersistedObjectSpaceOperation.GetQueue <int>("bar"),
                                                                                 queue
                                                                                 ),

                                                                             //
                                                                             // Assert we can't create an artifact with the same name.
                                                                             //
                                                                             Operation.Sequence(
                                                                                 assert.ThrowsException <InvalidOperationException>().When(PersistedObjectSpaceOperation.CreateArray <int>("bar", 42)),
                                                                                 assert.ThrowsException <InvalidOperationException>().When(PersistedObjectSpaceOperation.CreateDictionary <int, int>("bar")),
                                                                                 assert.ThrowsException <InvalidOperationException>().When(PersistedObjectSpaceOperation.CreateList <int>("bar")),
                                                                                 assert.ThrowsException <InvalidOperationException>().When(PersistedObjectSpaceOperation.CreateQueue <int>("bar")),
                                                                                 assert.ThrowsException <InvalidOperationException>().When(PersistedObjectSpaceOperation.CreateSet <int>("bar")),
                                                                                 assert.ThrowsException <InvalidOperationException>().When(PersistedObjectSpaceOperation.CreateStack <int>("bar")),
                                                                                 assert.ThrowsException <InvalidOperationException>().When(PersistedObjectSpaceOperation.CreateValue <int>("bar"))
                                                                                 )
                                                                             )
                                                                         ),

            //
            // Delete queue.
            //
            PersistedObjectSpaceOperation.Delete("bar"),

            //
            // Check the queue is no longer present in the object space.
            //
            Operation.Sequence(
                assert.ThrowsException <KeyNotFoundException>().When(PersistedObjectSpaceOperation.GetQueue <int>("bar")),
                assert.ThrowsException <KeyNotFoundException>().When(PersistedObjectSpaceOperation.Delete("bar"))
                )
            );
Beispiel #2
0
        private static IOperation <IPersistedObjectSpace> ManOrBoyCore(IAssertOperationFactory assert) =>
        PersistedObjectSpaceOperation.CreateArray <int>("bar", 1).Bind(array =>
                                                                       Operation.Sequence(

                                                                           //
                                                                           // Check the identifier
                                                                           //
                                                                           assert.AreEqual(
                                                                               array.GetId(),
                                                                               "bar"
                                                                               ),

                                                                           //
                                                                           // Created with correct length
                                                                           //
                                                                           Operation.Sequence(
                                                                               assert.AreEqual(
                                                                                   array.Length(),
                                                                                   1
                                                                                   ),
                                                                               assert.AreEqual(
                                                                                   array.Count(),
                                                                                   1
                                                                                   )
                                                                               ),

                                                                           //
                                                                           // Out of bounds exceptions are thrown
                                                                           //
                                                                           Operation.Sequence(
                                                                               assert.ThrowsException <IndexOutOfRangeException>().When(
                                                                                   array.Get(-1)
                                                                                   ),
                                                                               assert.ThrowsException <IndexOutOfRangeException>().When(
                                                                                   array.Get(1)
                                                                                   )
                                                                               ),

                                                                           //
                                                                           // Elements initialized to default values
                                                                           //
                                                                           Operation.Sequence(
                                                                               assert.AreEqual(
                                                                                   array.Get(0),
                                                                                   0
                                                                                   ),
                                                                               assert.AreSequenceEqual(
                                                                                   array.Enumerate(),
                                                                                   new[] { 0 }
                                                                                   )
                                                                               ),

                                                                           //
                                                                           // Perform assignment
                                                                           //
                                                                           array.Set(0, 42),

                                                                           //
                                                                           // Check values after assignment
                                                                           //
                                                                           Operation.Sequence(
                                                                               assert.AreEqual(
                                                                                   array.Get(0),
                                                                                   42
                                                                                   ),
                                                                               assert.AreSequenceEqual(
                                                                                   array.Enumerate(),
                                                                                   new[] { 42 }
                                                                                   )
                                                                               )
                                                                           )
                                                                       );