Ejemplo n.º 1
0
        public void CanStoreAndHydrateAggregatePreviousVersion()
        {
            var repository = new AggregateRepository(theStore);

            var invoice = CreateInvoice();

            repository.Store(invoice);

            // SAMPLE: scenario-aggregate-versionedload
            var invoiceFromRepository = repository.Load <Invoice>(invoice.Id, 2);

            Assert.Equal(124, invoiceFromRepository.Total);
            // ENDSAMPLE
        }
Ejemplo n.º 2
0
        public void CanStoreAndHydrateAggregate()
        {
            var invoice = CreateInvoice();

            // SAMPLE: scenario-aggregate-storeandreadinvoice
            var repository = new AggregateRepository(theStore);

            repository.Store(invoice);

            var invoiceFromRepository = repository.Load <Invoice>(invoice.Id);

            Assert.Equal(invoice.ToString(), invoiceFromRepository.ToString());
            Assert.Equal(invoice.Total, invoiceFromRepository.Total);
            // ENDSAMPLE
        }
Ejemplo n.º 3
0
        public void CanGuardVersion()
        {
            var repository = new AggregateRepository(theStore);

            // SAMPLE: scenario-aggregate-conflict
            var invoice = CreateInvoice();
            var invoiceWithSameIdentity = CreateInvoice();

            repository.Store(invoice);

            Assert.Throws <EventStreamUnexpectedMaxEventIdException>(() =>
            {
                repository.Store(invoiceWithSameIdentity);
            });
            // ENDSAMPLE
        }
Ejemplo n.º 4
0
        public void CanRetrieveVersion()
        {
            var repository = new AggregateRepository(theStore);

            var invoice = CreateInvoice();

            invoice.Version.ShouldBe(3);
            repository.Store(invoice);

            // Assert version was incremented properly
            var invoiceFromRepository = repository.Load <Invoice>(invoice.Id);

            invoiceFromRepository.Version.ShouldBe(3);

            // Update aggregate
            invoiceFromRepository.AddLine(100, 23, "Some nice product with 23% VAT");
            repository.Store(invoiceFromRepository);

            // Assert version was incremented properly
            invoiceFromRepository = repository.Load <Invoice>(invoice.Id);
            invoiceFromRepository.Version.ShouldBe(4);
        }