Beispiel #1
0
        public void Can_use_decimal_as_identity_column()
        {
            var numNum1 = new NumNum {
                TheWalrus = "I"
            };
            var numNum2 = new NumNum {
                TheWalrus = "Am"
            };

            var anNum1 = new AnNum {
                TheWalrus = "Goo goo"
            };
            var anNum2 = new AnNum {
                TheWalrus = "g'joob"
            };

            var adNum1 = new AdNum {
                TheWalrus = "Eggman"
            };
            var adNum2 = new AdNum {
                TheWalrus = "Eggmen"
            };

            using (var context = new NumNumContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                context.AddRange(numNum1, numNum2, adNum1, adNum2, anNum1, anNum2);

                context.SaveChanges();
            }

            using (var context = new NumNumContext())
            {
                Assert.Equal(numNum1.Id, context.NumNums.Single(e => e.TheWalrus == "I").Id);
                Assert.Equal(numNum2.Id, context.NumNums.Single(e => e.TheWalrus == "Am").Id);

                Assert.Equal(anNum1.Id, context.AnNums.Single(e => e.TheWalrus == "Goo goo").Id);
                Assert.Equal(anNum2.Id, context.AnNums.Single(e => e.TheWalrus == "g'joob").Id);

                Assert.Equal(adNum1.Id, context.AdNums.Single(e => e.TheWalrus == "Eggman").Id);
                Assert.Equal(adNum2.Id, context.AdNums.Single(e => e.TheWalrus == "Eggmen").Id);
            }
        }
        public void Can_use_decimal_and_byte_as_identity_columns()
        {
            using (var testDatabase = OracleTestStore.CreateInitialized(DatabaseName))
            {
                var nownNum1 = new NownNum {
                    Id = 77.0m, TheWalrus = "Crying"
                };
                var nownNum2 = new NownNum {
                    Id = 78.0m, TheWalrus = "Walrus"
                };

                var numNum1 = new NumNum {
                    TheWalrus = "I"
                };
                var numNum2 = new NumNum {
                    TheWalrus = "Am"
                };

                var anNum1 = new AnNum {
                    TheWalrus = "Goo goo"
                };
                var anNum2 = new AnNum {
                    TheWalrus = "g'joob"
                };

                var adNum1 = new AdNum {
                    TheWalrus = "Eggman"
                };
                var adNum2 = new AdNum {
                    TheWalrus = "Eggmen"
                };

                var byteNownNum1 = new ByteNownNum {
                    Id = 77, Lucy = "Tangerine"
                };
                var byteNownNum2 = new ByteNownNum {
                    Id = 78, Lucy = "Trees"
                };

                var byteNum1 = new ByteNum {
                    Lucy = "Marmalade"
                };
                var byteNum2 = new ByteNum {
                    Lucy = "Skies"
                };

                var byteAnNum1 = new ByteAnNum {
                    Lucy = "Cellophane"
                };
                var byteAnNum2 = new ByteAnNum {
                    Lucy = "Flowers"
                };

                var byteAdNum1 = new ByteAdNum {
                    Lucy = "Kaleidoscope"
                };
                var byteAdNum2 = new ByteAdNum {
                    Lucy = "Eyes"
                };

                decimal[] preSaveValues;
                byte[]    preSaveByteValues;

                var options = Fixture.CreateOptions(testDatabase);
                using (var context = new NumNumContext(options))
                {
                    context.Database.EnsureCreated();

                    context.AddRange(
                        nownNum1, nownNum2, numNum1, numNum2, adNum1, adNum2, anNum1, anNum2,
                        byteNownNum1, byteNownNum2, byteNum1, byteNum2, byteAdNum1, byteAdNum2, byteAnNum1, byteAnNum2);

                    preSaveValues = new[]
                    {
                        numNum1.Id, numNum2.Id, adNum1.Id, adNum2.Id, anNum1.Id, anNum2.Id
                    };

                    preSaveByteValues = new[]
                    {
                        byteNum1.Id, byteNum2.Id, byteAdNum1.Id, byteAdNum2.Id, byteAnNum1.Id, byteAnNum2.Id
                    };

                    context.SaveChanges();
                }

                using (var context = new NumNumContext(options))
                {
                    Assert.Equal(nownNum1.Id, context.NownNums.Single(e => e.TheWalrus == "Crying").Id);
                    Assert.Equal(nownNum2.Id, context.NownNums.Single(e => e.TheWalrus == "Walrus").Id);
                    Assert.Equal(77.0m, nownNum1.Id);
                    Assert.Equal(78.0m, nownNum2.Id);

                    Assert.Equal(numNum1.Id, context.NumNums.Single(e => e.TheWalrus == "I").Id);
                    Assert.Equal(numNum2.Id, context.NumNums.Single(e => e.TheWalrus == "Am").Id);
                    Assert.NotEqual(numNum1.Id, preSaveValues[0]);
                    Assert.NotEqual(numNum2.Id, preSaveValues[1]);

                    Assert.Equal(anNum1.Id, context.AnNums.Single(e => e.TheWalrus == "Goo goo").Id);
                    Assert.Equal(anNum2.Id, context.AnNums.Single(e => e.TheWalrus == "g'joob").Id);
                    Assert.NotEqual(adNum1.Id, preSaveValues[2]);
                    Assert.NotEqual(adNum2.Id, preSaveValues[3]);

                    Assert.Equal(adNum1.Id, context.AdNums.Single(e => e.TheWalrus == "Eggman").Id);
                    Assert.Equal(adNum2.Id, context.AdNums.Single(e => e.TheWalrus == "Eggmen").Id);
                    Assert.NotEqual(anNum1.Id, preSaveValues[4]);
                    Assert.NotEqual(anNum2.Id, preSaveValues[5]);

                    Assert.Equal(byteNownNum1.Id, context.ByteNownNums.Single(e => e.Lucy == "Tangerine").Id);
                    Assert.Equal(byteNownNum2.Id, context.ByteNownNums.Single(e => e.Lucy == "Trees").Id);
                    Assert.Equal(77, byteNownNum1.Id);
                    Assert.Equal(78, byteNownNum2.Id);

                    Assert.Equal(byteNum1.Id, context.ByteNums.Single(e => e.Lucy == "Marmalade").Id);
                    Assert.Equal(byteNum2.Id, context.ByteNums.Single(e => e.Lucy == "Skies").Id);
                    Assert.NotEqual(byteNum1.Id, preSaveByteValues[0]);
                    Assert.NotEqual(byteNum2.Id, preSaveByteValues[1]);

                    Assert.Equal(byteAnNum1.Id, context.ByteAnNums.Single(e => e.Lucy == "Cellophane").Id);
                    Assert.Equal(byteAnNum2.Id, context.ByteAnNums.Single(e => e.Lucy == "Flowers").Id);
                    Assert.NotEqual(byteAdNum1.Id, preSaveByteValues[2]);
                    Assert.NotEqual(byteAdNum2.Id, preSaveByteValues[3]);

                    Assert.Equal(byteAdNum1.Id, context.ByteAdNums.Single(e => e.Lucy == "Kaleidoscope").Id);
                    Assert.Equal(byteAdNum2.Id, context.ByteAdNums.Single(e => e.Lucy == "Eyes").Id);
                    Assert.NotEqual(byteAnNum1.Id, preSaveByteValues[4]);
                    Assert.NotEqual(byteAnNum2.Id, preSaveByteValues[5]);
                }
            }
        }