Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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();
        }
Пример #4
0
        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();
        }