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")) ) );
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()) ) );