Example #1
0
    public void Identity_conflict_throws_for_owned_composite_primary_key()
    {
        using var context = new IdentityConflictContext();
        context.Attach(
            new CompositeKey
        {
            Id1          = 77,
            Id2          = 78,
            AlternateId1 = 66,
            AlternateId2 = 67,
            Owned        = new CompositeKeyOwned()
        });

        var duplicateOwned = new CompositeKeyOwned();

        context.Entry(duplicateOwned).Property("CompositeKeyId1").CurrentValue = 77;
        context.Entry(duplicateOwned).Property("CompositeKeyId2").CurrentValue = 78;

        Assert.Equal(
            CoreStrings.IdentityConflictOwned("CompositeKeyOwned", "{'CompositeKeyId1', 'CompositeKeyId2'}"),
            Assert.Throws <InvalidOperationException>(
                () => context.Attach(
                    new CompositeKey
        {
            Id1          = 177,
            Id2          = 178,
            AlternateId1 = 166,
            AlternateId2 = 168,
            Owned        = duplicateOwned
        })).Message);
    }
Example #2
0
    public void Identity_conflict_throws_for_owned_primary_key()
    {
        using var context = new IdentityConflictContext();
        context.Attach(
            new SingleKey
        {
            Id          = 77,
            AlternateId = 66,
            Owned       = new SingleKeyOwned()
        });

        var duplicateOwned = new SingleKeyOwned();

        context.Entry(duplicateOwned).Property("SingleKeyId").CurrentValue = 77;

        Assert.Equal(
            CoreStrings.IdentityConflictOwned("SingleKeyOwned", "{'SingleKeyId'}"),
            Assert.Throws <InvalidOperationException>(
                () => context.Attach(
                    new SingleKey
        {
            Id          = 78,
            AlternateId = 67,
            Owned       = duplicateOwned
        })).Message);
    }
Example #3
0
        public void Identity_conflict_throws_for_composite_primary_key()
        {
            using (var context = new IdentityConflictContext())
            {
                context.Attach(
                    new CompositeKey
                {
                    Id1          = 77,
                    Id2          = 78,
                    AlternateId1 = 66,
                    AlternateId2 = 67
                });

                Assert.Equal(
                    CoreStrings.IdentityConflict("CompositeKey", "{'Id1', 'Id2'}"),
                    Assert.Throws <InvalidOperationException>(
                        () => context.Attach(
                            new CompositeKey
                {
                    Id1          = 77,
                    Id2          = 78,
                    AlternateId1 = 66,
                    AlternateId2 = 68
                })).Message);
            }
        }
Example #4
0
    public void Identity_conflict_throws_for_alternate_key()
    {
        using var context = new IdentityConflictContext();
        context.Attach(
            new SingleKey {
            Id = 77, AlternateId = 66
        });

        Assert.Equal(
            CoreStrings.IdentityConflict("SingleKey", "{'AlternateId'}"),
            Assert.Throws <InvalidOperationException>(
                () => context.Attach(
                    new SingleKey {
            Id = 78, AlternateId = 66
        })).Message);
    }
Example #5
0
 public void Identity_null_throws_for_alternate_key()
 {
     using var context = new IdentityConflictContext();
     Assert.Equal(
         CoreStrings.InvalidAlternateKeyValue("SingleKey", "AlternateId"),
         Assert.Throws <InvalidOperationException>(
             () => context.Attach(
                 new SingleKey {
         Id = 77, AlternateId = null
     })).Message);
 }
 public void Identity_null_throws_for_primary_key()
 {
     using (var context = new IdentityConflictContext())
     {
         Assert.Equal(
             CoreStrings.InvalidKeyValue("SingleKey", "Id"),
             Assert.Throws <InvalidOperationException>(
                 () => context.Attach(new SingleKey {
             Id = null, AlternateId = 67
         })).Message);
     }
 }
 public void Identity_null_throws_for_composite_alternate_key()
 {
     using (var context = new IdentityConflictContext())
     {
         Assert.Equal(
             CoreStrings.InvalidAlternateKeyValue("CompositeKey", "AlternateId2"),
             Assert.Throws <InvalidOperationException>(
                 () => context.Attach(
                     new CompositeKey {
             Id1 = 77, Id2 = 79, AlternateId1 = 66, AlternateId2 = null
         })).Message);
     }
 }