Example #1
0
        public void given_two_documents_with_the_same_value_for_unique_field_with_multiple_properties_when_created_then_throws_exception()
        {
            //1. Create Events
            var firstDocument = new UniqueUser {
                Id = Guid.NewGuid(), Email = "*****@*****.**", FirstName = "John", Surname = "Doe"
            };
            var secondDocument = new UniqueUser {
                Id = Guid.NewGuid(), Email = "*****@*****.**", FirstName = "John", Surname = "Doe"
            };


            using (var session = theStore.OpenSession())
            {
                //2. Save documents
                session.Store(firstDocument);
                session.Store(secondDocument);

                //3. Unique Exception Was thrown
                try
                {
                    session.SaveChanges();
                }
                catch (Marten.Exceptions.MartenCommandException exception)
                {
                    ((PostgresException)exception.InnerException).SqlState.ShouldBe(UniqueSqlState);
                }
            }
        }
Example #2
0
        public void given_two_documents_with_the_same_value_for_unique_field_with_single_property_when_created_then_throws_exception()
        {
            //1. Create Events
            const string email         = "*****@*****.**";
            var          firstDocument = new UniqueUser {
                Id = Guid.NewGuid(), Email = email, FirstName = "John", Surname = "Smith"
            };
            var secondDocument = new UniqueUser {
                Id = Guid.NewGuid(), Email = email, FirstName = "John", Surname = "Doe"
            };

            using (var session = theStore.OpenSession())
            {
                //2. Save documents
                session.Store(firstDocument);
                session.Store(secondDocument);

                //3. Unique Exception Was thrown
                try
                {
                    session.SaveChanges();
                }
                catch (DocumentAlreadyExistsException exception)
                {
                    ((PostgresException)exception.InnerException).SqlState.ShouldBe(UniqueSqlState);
                }
            }
        }