public void GetOrAddWhenIdentityMapDoesNotContainNaturalKey()
        {
            // arrange
            var identityMap  = new SqlServerIdentityMap(this.ConnectionString);
            var registration = new Registration(Guid.NewGuid().ToString("N"));

            // act
            var identity     = identityMap.GetOrAdd(typeof(Car), typeof(Registration), registration);
            var sameIdentity = identityMap.GetOrAdd(typeof(Car), typeof(Registration), registration);

            // assert
            identity.Should().Be(sameIdentity);
        }
        public void TryGetWhenIdentityMapDoesNotContainNaturalKey()
        {
            // arrange
            var identityMap  = new SqlServerIdentityMap(this.ConnectionString);
            var registration = new Registration(Guid.NewGuid().ToString("N"));
            var identity     = default(Guid);

            // act
            var success = identityMap.TryGet(typeof(Car), typeof(Registration), registration, out identity);

            // assert
            success.Should().BeFalse();
        }
        public void RemoveFromIdentityMap()
        {
            // arrange
            var identityMap  = new SqlServerIdentityMap(this.ConnectionString);
            var registration = new Registration(Guid.NewGuid().ToString("N"));

            // act
            var identity = identityMap.GetOrAdd(typeof(Car), typeof(Registration), registration);

            identityMap.Remove(identity);
            var otherIdentity = identityMap.GetOrAdd(typeof(Car), typeof(Registration), registration);

            // assert
            identity.Should().NotBe(otherIdentity);
        }
        public void UseAlternateSchema()
        {
            // arrange
            var identityMap    = new SqlServerIdentityMap(this.ConnectionString, "alternate");
            var registration   = new Registration(Guid.NewGuid().ToString("N"));
            var actualIdentity = default(Guid);

            // act
            var initialSuccess    = identityMap.TryGet(typeof(Car), typeof(Registration), registration, out actualIdentity);
            var expectedIdentity  = identityMap.GetOrAdd(typeof(Car), typeof(Registration), registration);
            var subsequentSuccess = identityMap.TryGet(typeof(Car), typeof(Registration), registration, out actualIdentity);

            // assert
            initialSuccess.Should().BeFalse();
            subsequentSuccess.Should().BeTrue();
            actualIdentity.Should().Be(expectedIdentity);
        }
        public void TryGetWhenIdentityMapDoesContainNaturalKey()
        {
            // arrange
            var identityMap      = new SqlServerIdentityMap(this.ConnectionString);
            var otherIdentityMap = new SqlServerIdentityMap(this.ConnectionString);
            var registration     = new Registration(Guid.NewGuid().ToString("N"));
            var actualIdentity   = default(Guid);
            var sameIdentity     = default(Guid);

            // act
            var expectedIdentity = identityMap.GetOrAdd(typeof(Car), typeof(Registration), registration);
            var success          = otherIdentityMap.TryGet(typeof(Car), typeof(Registration), registration, out actualIdentity);
            var anotherSuccess   = otherIdentityMap.TryGet(typeof(Car), typeof(Registration), registration, out sameIdentity);

            // assert
            success.Should().BeTrue();
            actualIdentity.Should().Be(expectedIdentity);
            anotherSuccess.Should().BeTrue();
            sameIdentity.Should().Be(expectedIdentity);
        }
        public void TryGetWhenIdentityMapHasRemovedNaturalKey()
        {
            // arrange
            var identityMap      = new SqlServerIdentityMap(this.ConnectionString);
            var otherIdentityMap = new SqlServerIdentityMap(this.ConnectionString);
            var registration     = new Registration(Guid.NewGuid().ToString("N"));
            var somelIdentity    = default(Guid);

            // act
            var identity     = identityMap.GetOrAdd(typeof(Car), typeof(Registration), registration);
            var sameIdentity = otherIdentityMap.GetOrAdd(typeof(Car), typeof(Registration), registration);

            identityMap.Remove(identity);
            var success        = otherIdentityMap.TryGet(typeof(Car), typeof(Registration), registration, out somelIdentity);
            var anotherSuccess = otherIdentityMap.TryGet(typeof(Car), typeof(Registration), registration, out somelIdentity);

            // assert
            success.Should().BeFalse();
            anotherSuccess.Should().BeFalse();
        }
Example #7
0
        public void CanUpdateToVersion2Functionality()
        {
            // NOTE (Cameron): Version #2 adds type forwarding.
            // arrange
            // set up version #1
            // add data to version #1
            var sqlScript  = GetScript("dddlib.Persistence.SqlServer.Database.Scripts.Version01.sql");
            var naturalKey = Guid.NewGuid().ToString("N");

            this.ExecuteScript(sqlScript); // version #1
            this.ExecuteScript(@"exec [dbo].[TryAddNaturalKey] 'dddlib.Persistence.Tests.Integration.UpgradeDatabaseVersionTests+Vehicle', '{""Number"":""123""}', 0");

            // latest version
            var identityMap  = new SqlServerIdentityMap(this.ConnectionString);
            var registration = new Registration(Guid.NewGuid().ToString("N"));

            // act
            var actualIdentity = identityMap.GetOrAdd(typeof(Vehicle), typeof(Registration), registration);

            // assert
            ////actualIdentity.Should().Be(expectedIdentity);
            // "dddlib.Persistence.Tests.Integration.SqlServerIdentityMapTests+Car"
        }