Example #1
0
        private static IOperation <IPersistedObjectSpace> ManOrBoyCore(IAssertOperationFactory assert) =>
        PersistedObjectSpaceOperation.CreateValue <int>("bar").Bind(value =>
                                                                    Operation.Sequence(

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

                                                                        //
                                                                        // Initialized with default value
                                                                        //
                                                                        assert.AreEqual(
                                                                            value.Get(),
                                                                            0
                                                                            ),

                                                                        //
                                                                        // Perform assignment
                                                                        //
                                                                        value.Set(42),

                                                                        //
                                                                        // Check value after assignment
                                                                        //
                                                                        assert.AreEqual(
                                                                            value.Get(),
                                                                            42
                                                                            )
                                                                        )
                                                                    );
Example #2
0
        private static IOperation <IPersistedObjectSpace> ManOrBoyCore(IAssertOperationFactory assert) =>
        PersistedObjectSpaceOperation.CreateQueue <int>("bar").Bind(queue =>
                                                                    Operation.Sequence(

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

                                                                        //
                                                                        // Empty at the start
                                                                        //
                                                                        Operation.Sequence(
                                                                            assert.AreEqual(
                                                                                queue.Count(),
                                                                                0
                                                                                ),
                                                                            assert.AreSequenceEqual(
                                                                                queue.Enumerate(),
                                                                                Array.Empty <int>()
                                                                                )
                                                                            ),

                                                                        //
                                                                        // Enqueue a value
                                                                        //
                                                                        queue.Enqueue(42),

                                                                        //
                                                                        // Peek and enumerate value
                                                                        //
                                                                        Operation.Sequence(
                                                                            assert.AreEqual(
                                                                                queue.Peek(),
                                                                                42
                                                                                ),
                                                                            assert.AreEqual(
                                                                                queue.Count(),
                                                                                1
                                                                                ),
                                                                            assert.AreSequenceEqual(
                                                                                queue.Enumerate(),
                                                                                new[] { 42 }
                                                                                )
                                                                            ),

                                                                        //
                                                                        // Enqueue a value
                                                                        //
                                                                        queue.Enqueue(43),

                                                                        //
                                                                        // Peek and enumerate values
                                                                        //
                                                                        Operation.Sequence(
                                                                            assert.AreEqual(
                                                                                queue.Peek(),
                                                                                42
                                                                                ),
                                                                            assert.AreEqual(
                                                                                queue.Count(),
                                                                                2
                                                                                ),
                                                                            assert.AreSequenceEqual(
                                                                                queue.Enumerate(),
                                                                                new[] { 42, 43 }
                                                                                )
                                                                            ),

                                                                        //
                                                                        // Dequeue a value
                                                                        //
                                                                        assert.AreEqual(
                                                                            queue.Dequeue(),
                                                                            42
                                                                            ),

                                                                        //
                                                                        // Peek and enumerate value
                                                                        //
                                                                        Operation.Sequence(
                                                                            assert.AreEqual(
                                                                                queue.Peek(),
                                                                                43
                                                                                ),
                                                                            assert.AreEqual(
                                                                                queue.Count(),
                                                                                1
                                                                                ),
                                                                            assert.AreSequenceEqual(
                                                                                queue.Enumerate(),
                                                                                new[] { 43 }
                                                                                )
                                                                            ),

                                                                        //
                                                                        // Dequeue another value
                                                                        //
                                                                        assert.AreEqual(
                                                                            queue.Dequeue(),
                                                                            43
                                                                            ),

                                                                        //
                                                                        // Empty now
                                                                        //
                                                                        Operation.Sequence(
                                                                            assert.AreEqual(
                                                                                queue.Count(),
                                                                                0
                                                                                ),
                                                                            assert.AreSequenceEqual(
                                                                                queue.Enumerate(),
                                                                                Array.Empty <int>()
                                                                                )
                                                                            ),

                                                                        //
                                                                        // Can't dequeue anymore
                                                                        //
                                                                        assert.ThrowsException <InvalidOperationException>().When(queue.Dequeue())
                                                                        )
                                                                    );
Example #3
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 }
                                                                                   )
                                                                               )
                                                                           )
                                                                       );