Ejemplo n.º 1
0
        public void which_was_allready_deleted_should_fail()
        {
            const string stream = "which_was_allready_deleted_should_fail";
            using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var create = connection.CreateStreamAsync(stream, new byte[0]);
                Assert.DoesNotThrow(create.Wait);

                var delete = connection.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
                Assert.DoesNotThrow(delete.Wait);

                var secondDelete = connection.DeleteStreamAsync(stream, ExpectedVersion.Any);
                Assert.That(() => secondDelete.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<StreamDeletedException>());
            }
        }
Ejemplo n.º 2
0
 public void which_does_not_exist_should_fail()
 {
     const string stream = "which_does_not_exist_should_fail";
     using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
     {
         var delete = connection.DeleteStreamAsync(stream, ExpectedVersion.Any);
         Assert.Inconclusive();
         //Assert.That(() => delete.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<WrongExpectedVersionException>());
     }
 }
Ejemplo n.º 3
0
        public void with_invalid_expected_version_should_fail()
        {
            const string stream = "with_invalid_expected_version_should_fail";
            using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var create = connection.CreateStreamAsync(stream, new byte[0]);
                Assert.DoesNotThrow(create.Wait);

                var delete = connection.DeleteStreamAsync(stream, 1);
                Assert.That(() => delete.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<WrongExpectedVersionException>());
            }
        }
Ejemplo n.º 4
0
        public void which_already_exists_should_success_when_passed_empty_stream_expected_version()
        {
            const string stream = "which_already_exists_should_success_when_passed_empty_stream_expected_version";
            using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var create = connection.CreateStreamAsync(stream, new byte[0]);
                Assert.DoesNotThrow(create.Wait);

                var delete = connection.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
                Assert.DoesNotThrow(delete.Wait);
            }
        }
Ejemplo n.º 5
0
        public void write_to_and_delete()
        {
            var endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113);

            using (var connection = new EventStoreConnection(endpoint))
            {
                var ev     = new TestEvent("Some data");
                var stream = string.Format("test-delete-{0}", Guid.NewGuid());

                var appendTask = connection.AppendToStreamAsync(stream, -2, new[] { ev });
                appendTask.Wait();
                Assert.IsTrue(appendTask.Result.IsSuccessful, "Failed to append data to stream.");

                var data = connection.ReadEventStream(stream, 0, int.MaxValue);

                var lastEventVersion = data.Events[data.Events.Length - 1].EventNumber;

                var deleteTask = connection.DeleteStreamAsync(stream, lastEventVersion);
                deleteTask.Wait();
                Assert.IsTrue(deleteTask.Result.IsSuccessful, "Failed to delete stream.");
            }
        }
Ejemplo n.º 6
0
        public void should_fail_to_commit_if_started_with_correct_ver_but_on_commit_stream_was_deleted()
        {
            const string stream = "should_fail_to_commit_if_started_with_correct_ver_but_on_commit_stream_was_deleted";
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
                store.CreateStream(stream, new byte[0]);

            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var start = store.StartTransactionAsync(stream, ExpectedVersion.EmptyStream);
                Assert.DoesNotThrow(start.Wait);

                var write = store.TransactionalWriteAsync(start.Result.TransactionId, start.Result.Stream, new[] { new TestEvent() });
                Assert.DoesNotThrow(write.Wait);

                var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
                Assert.DoesNotThrow(delete.Wait);

                var commit = store.CommitTransactionAsync(start.Result.TransactionId, start.Result.Stream);
                Assert.That(() => commit.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<StreamDeletedException>());
            }
        }
Ejemplo n.º 7
0
 public static Task DeleteStreamAsync(string stream, int expectedVersion)
 {
     return(_connection.DeleteStreamAsync(stream, expectedVersion));
 }
Ejemplo n.º 8
0
        //[Test]
        //public void write_sync_null_failure()
        //{
        //    var endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113);
        //    using (var connection = new EventStoreConnection(endpoint))
        //    {
        //        var ev = new TestEvent("Some data");
        //        var task = connection.AppendToStreamAsync("test", -2, new[] { ev });
        //        task.Wait();

        //        var result = task.Result;
        //        Assert.IsTrue(result.IsSuccessful, "Written Successfully");
        //    }
        //}

        public void write_to_and_delete() {
            var endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113);
            using (var connection = new EventStoreConnection(endpoint))
            {
                var ev = new TestEvent("Some data");
                var stream = string.Format("test-delete-{0}", Guid.NewGuid());

                var appendTask = connection.AppendToStreamAsync(stream, -2, new[] { ev });
                appendTask.Wait();
                Debug.Assert(appendTask.Result.IsSuccessful, "Failed to append data to stream.");

                var data = connection.ReadEventStream(stream, 0, int.MaxValue);

                var lastEventVersion = data.Events[data.Events.Length - 1].EventNumber;

                var deleteTask = connection.DeleteStreamAsync(stream, lastEventVersion);
                deleteTask.Wait();
                Debug.Assert(deleteTask.Result.IsSuccessful, "Failed to delete stream.");
            }
        }
Ejemplo n.º 9
0
        public void should_fail_writing_with_invalid_exp_ver_to_deleted_stream()
        {
            const string stream = "should_fail_writing_with_invalid_exp_ver_to_deleted_stream";
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var create = store.CreateStreamAsync(stream, new byte[0]);
                Assert.DoesNotThrow(create.Wait);

                var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
                Assert.DoesNotThrow(delete.Wait);

                var append = store.AppendToStreamAsync(stream, 5, new[] { new TestEvent() });
                Assert.That(() => append.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<StreamDeletedException>());
            }
        }