public void Insert_with_explicit_with_default_keys()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextNoKeyGenerationNullableKey(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    context.AddRange(
                        new NullableKeyBlog {
                        Id = 0, Name = "One Unicorn"
                    },
                        new NullableKeyBlog {
                        Id = 1, Name = "Two Unicorns"
                    });

                    context.SaveChanges();
                }

                using (var context = new BlogContextNoKeyGenerationNullableKey(testStore.Name))
                {
                    var blogs = context.NullableKeyBlogs.OrderBy(e => e.Id).ToList();

                    Assert.Equal(0, blogs[0].Id);
                    Assert.Equal(1, blogs[1].Id);
                }
            }
        }
        public void Update_explicit_value_in_computed_column()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextComputedColumn(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    context.Add(new FullNameBlog {
                        FirstName = "One", LastName = "Unicorn"
                    });

                    context.SaveChanges();
                }

                using (var context = new BlogContextComputedColumn(testStore.Name))
                {
                    var blog = context.FullNameBlogs.Single();

                    blog.FullName = "The Gorilla";

                    // The property 'FullName' on entity type 'FullNameBlog' is defined to be read-only after it has been saved,
                    // but its value has been modified or marked as modified.
                    Assert.Equal(
                        CoreStrings.PropertyReadOnlyAfterSave("FullName", "FullNameBlog"),
                        Assert.Throws <InvalidOperationException>(() => context.SaveChanges()).Message);
                }
            }
        }
        public void Can_track_an_entity_with_more_than_10_properties()
        {
            using (var testDatabase = OracleTestStore.CreateInitialized(DatabaseName))
            {
                var options = Fixture.CreateOptions(testDatabase);
                using (var context = new GameDbContext(options))
                {
                    context.Database.EnsureCreated();

                    context.Characters.Add(new PlayerCharacter(new Level {
                        Game = new Game()
                    }));

                    context.SaveChanges();
                }

                using (var context = new GameDbContext(options))
                {
                    var character = context.Characters
                                    .Include(c => c.Level.Game)
                                    .OrderBy(c => c.Id)
                                    .First();

                    Assert.NotNull(character.Game);
                    Assert.NotNull(character.Level);
                    Assert.NotNull(character.Level.Game);
                }
            }
        }
        public void Insert_with_sequence_HiLo()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextHiLo(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    context.AddRange(new Blog {
                        Name = "One Unicorn"
                    }, new Blog {
                        Name = "Two Unicorns"
                    });

                    context.SaveChanges();
                }

                using (var context = new BlogContextHiLo(testStore.Name))
                {
                    var blogs = context.Blogs.OrderBy(e => e.Id).ToList();

                    Assert.Equal(1, blogs[0].Id);
                    Assert.Equal(2, blogs[0].OtherId);
                    Assert.Equal(3, blogs[1].Id);
                    Assert.Equal(4, blogs[1].OtherId);
                }
            }
        }
        public void Insert_and_update_with_computed_column()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextComputedColumn(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    var blog = context.Add(new FullNameBlog {
                        FirstName = "One", LastName = "Unicorn"
                    }).Entity;

                    context.SaveChanges();

                    Assert.Equal("One Unicorn", blog.FullName);
                }

                using (var context = new BlogContextComputedColumn(testStore.Name))
                {
                    var blog = context.FullNameBlogs.Single();

                    Assert.Equal("One Unicorn", blog.FullName);

                    blog.LastName = "Pegasus";

                    context.SaveChanges();

                    Assert.Equal("One Pegasus", blog.FullName);
                }
            }
        }
        public void Insert_with_client_generated_GUID_key()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                Guid afterSave;
                using (var context = new BlogContextClientGuidKey(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    var blog = context.Add(new GuidBlog {
                        Name = "One Unicorn"
                    }).Entity;

                    var beforeSave      = blog.Id;
                    var beforeSaveNotId = blog.NotId;

                    Assert.NotEqual(default(Guid), beforeSave);
                    Assert.NotEqual(default(Guid), beforeSaveNotId);

                    context.SaveChanges();

                    afterSave = blog.Id;
                    var afterSaveNotId = blog.NotId;

                    Assert.Equal(beforeSave, afterSave);
                    Assert.Equal(beforeSaveNotId, afterSaveNotId);
                }

                using (var context = new BlogContextClientGuidKey(testStore.Name))
                {
                    Assert.Equal(afterSave, context.GuidBlogs.Single().Id);
                }
            }
        }
        private static async Task Delete_database_test(bool async, bool open)
        {
            using (var testDatabase = OracleTestStore.CreateInitialized("EnsureDeleteBlogging"))
            {
                if (!open)
                {
                    testDatabase.CloseConnection();
                }

                using (var context = new OracleDatabaseCreatorTest.BloggingContext(testDatabase))
                {
                    var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(context);

                    Assert.True(async ? await creator.ExistsAsync() : creator.Exists());

                    if (async)
                    {
                        Assert.True(await context.Database.EnsureDeletedAsync());
                    }
                    else
                    {
                        Assert.True(context.Database.EnsureDeleted());
                    }

                    Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State);

                    Assert.False(async ? await creator.ExistsAsync() : creator.Exists());

                    Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State);
                }
            }
        }
Example #8
0
        public async Task Insert_batch_record_async()
        {
            using (var testDatabase = OracleTestStore.CreateInitialized(DatabaseName))
            {
                var options = Fixture.CreateOptions(testDatabase);

                using (var context = new OracleBatchInsertContext(options))
                {
                    await context.GetService <IRelationalDatabaseCreator>().CreateTablesAsync();

                    for (int i = 0; i < 5000; i++)
                    {
                        context.Add(new Movie
                        {
                            Description = $"The EntityFramework {i}",
                            Publication = DateTime.Now
                        });
                    }

                    var rows = await context.SaveChangesAsync();

                    Assert.Equal(1, (await context.Movies.SingleAsync(e => e.Description == "The EntityFramework 0")).Id);
                    Assert.Equal(5000, (await context.Movies.LastAsync()).Id);
                    Assert.Equal(5000, rows);
                    Assert.NotEqual(4999, rows);
                }
            }
        }
        public void Insert_with_key_default_value_from_sequence()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextKeyColumnWithDefaultValue(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    context.AddRange(new Blog {
                        Name = "One Unicorn"
                    }, new Blog {
                        Name = "Two Unicorns"
                    });

                    context.SaveChanges();
                }

                using (var context = new BlogContextKeyColumnWithDefaultValue(testStore.Name))
                {
                    var blogs = context.Blogs.OrderBy(e => e.Id).ToList();

                    Assert.Equal(77, blogs[0].Id);
                    Assert.Equal(78, blogs[1].Id);
                }
            }
        }
        public async Task Can_save_changes_in_tracked_entities()
        {
            using (var testDatabase = OracleTestStore.CreateInitialized(DatabaseName))
            {
                int updatedId;
                int deletedId;
                int addedId;
                var options = Fixture.CreateOptions(testDatabase);
                using (var db = new BloggingContext(options))
                {
                    var blogs = await CreateBlogDatabaseAsync <Blog>(db);

                    var toAdd = db.Blogs.Add(
                        new Blog
                    {
                        Name       = "Blog to Insert",
                        George     = true,
                        TheGu      = new Guid("0456AEF1-B7FC-47AA-8102-975D6BA3A9BF"),
                        NotFigTime = new DateTime(1973, 9, 3, 0, 10, 33, 777),
                        ToEat      = 64,
                        OrNothing  = 0.123456789,
                        Fuse       = 777,
                        WayRound   = 9876543210,
                        Away       = 0.12345f,
                        AndChew    = new byte[16]
                    }).Entity;
                    db.Entry(toAdd).State = EntityState.Detached;

                    var toUpdate = blogs[0];
                    toUpdate.Name = "Blog is Updated";
                    updatedId     = toUpdate.Id;
                    var toDelete = blogs[1];
                    toDelete.Name = "Blog to delete";
                    deletedId     = toDelete.Id;

                    db.Remove(toDelete);
                    db.Entry(toAdd).State = EntityState.Added;

                    await db.SaveChangesAsync();

                    addedId = toAdd.Id;
                    Assert.NotEqual(0, addedId);

                    Assert.Equal(EntityState.Unchanged, db.Entry(toUpdate).State);
                    Assert.Equal(EntityState.Unchanged, db.Entry(toAdd).State);
                    Assert.DoesNotContain(toDelete, db.ChangeTracker.Entries().Select(e => e.Entity));
                }

                using (var db = new BloggingContext(options))
                {
                    var toUpdate = db.Blogs.Single(b => b.Id == updatedId);
                    Assert.Equal("Blog is Updated", toUpdate.Name);
                    Assert.Equal(0, db.Blogs.Count(b => b.Id == deletedId));
                    Assert.Equal("Blog to Insert", db.Blogs.Single(b => b.Id == addedId).Name);
                }
            }
        }
        public void Insert_with_non_key_default_value()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextNonKeyDefaultValue(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    var blogs = new List <Blog>
                    {
                        new Blog {
                            Name = "One Unicorn"
                        },
                        new Blog {
                            Name = "Two Unicorns", CreatedOn = new DateTime(1969, 8, 3, 0, 10, 0)
                        }
                    };

                    context.AddRange(blogs);

                    context.SaveChanges();

                    Assert.NotEqual(new DateTime(), blogs[0].CreatedOn);
                    Assert.NotEqual(new DateTime(), blogs[1].CreatedOn);
                    Assert.Null(blogs[0].OtherId);
                    Assert.Null(blogs[1].OtherId);
                }

                using (var context = new BlogContextNonKeyDefaultValue(testStore.Name))
                {
                    var blogs = context.Blogs.OrderBy(e => e.Name).ToList();

                    Assert.NotEqual(new DateTime(), blogs[0].CreatedOn);
                    Assert.Equal(new DateTime(1969, 8, 3, 0, 10, 0), blogs[1].CreatedOn);

                    blogs[0].CreatedOn = new DateTime(1973, 9, 3, 0, 10, 0);
                    blogs[1].Name      = "Zwo Unicorns";

                    context.SaveChanges();
                }

                using (var context = new BlogContextNonKeyDefaultValue(testStore.Name))
                {
                    var blogs = context.Blogs.OrderBy(e => e.Name).ToList();

                    Assert.Equal(new DateTime(1969, 8, 3, 0, 10, 0), blogs[1].CreatedOn);
                    Assert.Equal(new DateTime(1973, 9, 3, 0, 10, 0), blogs[0].CreatedOn);
                }
            }
        }
        public void Can_use_string_enum_or_byte_array_as_key()
        {
            using (var testDatabase = OracleTestStore.CreateInitialized(DatabaseName))
            {
                var sNum1 = new SNum {
                    TheWalrus = "I"
                };
                var sNum2 = new SNum {
                    TheWalrus = "Am"
                };

                var enNum1 = new EnNum {
                    TheWalrus = "Goo goo", Id = ENum.BNum
                };
                var enNum2 = new EnNum {
                    TheWalrus = "g'joob", Id = ENum.CNum
                };

                var bNum1 = new BNum {
                    TheWalrus = "Eggman"
                };
                var bNum2 = new BNum {
                    TheWalrus = "Eggmen"
                };

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

                    context.AddRange(sNum1, sNum2, enNum1, enNum2, bNum1, bNum2);

                    context.SaveChanges();
                }

                using (var context = new ENumContext(options))
                {
                    Assert.Equal(sNum1.Id, context.SNums.Single(e => e.TheWalrus == "I").Id);
                    Assert.Equal(sNum2.Id, context.SNums.Single(e => e.TheWalrus == "Am").Id);

                    Assert.Equal(enNum1.Id, context.EnNums.Single(e => e.TheWalrus == "Goo goo").Id);
                    Assert.Equal(enNum2.Id, context.EnNums.Single(e => e.TheWalrus == "g'joob").Id);

                    Assert.Equal(bNum1.Id, context.BNums.Single(e => e.TheWalrus == "Eggman").Id);
                    Assert.Equal(bNum2.Id, context.BNums.Single(e => e.TheWalrus == "Eggmen").Id);
                }
            }
        }
        public void Insert_with_non_key_default_value_readonly()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextNonKeyReadOnlyDefaultValue(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    context.AddRange(
                        new Blog {
                        Name = "One Unicorn"
                    },
                        new Blog {
                        Name = "Two Unicorns"
                    });

                    context.SaveChanges();

                    Assert.NotEqual(new DateTime(), context.Blogs.ToList()[0].CreatedOn);
                }

                DateTime dateTime0;

                using (var context = new BlogContextNonKeyReadOnlyDefaultValue(testStore.Name))
                {
                    var blogs = context.Blogs.OrderBy(e => e.Id).ToList();

                    dateTime0 = blogs[0].CreatedOn;

                    Assert.NotEqual(new DateTime(), dateTime0);
                    Assert.NotEqual(new DateTime(), blogs[1].CreatedOn);

                    blogs[0].Name      = "One Pegasus";
                    blogs[1].CreatedOn = new DateTime(1973, 9, 3, 0, 10, 0);

                    context.SaveChanges();
                }

                using (var context = new BlogContextNonKeyReadOnlyDefaultValue(testStore.Name))
                {
                    var blogs = context.Blogs.OrderBy(e => e.Id).ToList();

                    Assert.Equal(dateTime0, blogs[0].CreatedOn);
                    Assert.Equal(new DateTime(1973, 9, 3, 0, 10, 0), blogs[1].CreatedOn);
                }
            }
        }
        public void Insert_with_ValueGeneratedOnAdd_GUID_nonkey_property_throws()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextClientGuidNonKey(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    var blog = context.Add(new GuidBlog {
                        Name = "One Unicorn"
                    }).Entity;

                    Assert.Equal(default(Guid), blog.NotId);

                    // No value set on a required column
                    Assert.Throws <DbUpdateException>(() => context.SaveChanges());
                }
            }
        }
        public void Resolve_concurreny()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextConcurrencyWithRowversion(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    var blog = context.Add(new ConcurrentBlog {
                        Name = "One Unicorn"
                    }).Entity;

                    context.SaveChanges();

                    using (var innerContext = new BlogContextConcurrencyWithRowversion(testStore.Name))
                    {
                        var updatedBlog = innerContext.ConcurrentBlogs.Single();
                        updatedBlog.Name = "One Pegasus";
                        innerContext.SaveChanges();
                        var currentTimestamp = updatedBlog.Timestamp.ToArray();

                        try
                        {
                            blog.Name = "One Earth Pony";
                            context.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            // Update origianal values (and optionally any current values)
                            // Would normally do this with just one method call
                            context.Entry(blog).Property(e => e.Id).OriginalValue        = updatedBlog.Id;
                            context.Entry(blog).Property(e => e.Name).OriginalValue      = updatedBlog.Name;
                            context.Entry(blog).Property(e => e.Timestamp).OriginalValue = updatedBlog.Timestamp;

                            context.SaveChanges();

                            Assert.NotEqual(blog.Timestamp, currentTimestamp);
                        }
                    }
                }
            }
        }
        public void Insert_explicit_value_into_computed_column()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextComputedColumn(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    context.Add(new FullNameBlog {
                        FirstName = "One", LastName = "Unicorn", FullName = "Gerald"
                    });

                    // The property 'FullName' on entity type 'FullNameBlog' is defined to be read-only before it is
                    // saved, but its value has been set to something other than a temporary or default value.
                    Assert.Equal(
                        CoreStrings.PropertyReadOnlyBeforeSave("FullName", "FullNameBlog"),
                        Assert.Throws <InvalidOperationException>(() => context.SaveChanges()).Message);
                }
            }
        }
        public void Insert_and_update_with_computed_column_with_function()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextComputedColumnWithFunction(testStore.Name))
                {
                    context.Database.ExecuteSqlCommand
                    (
                        @"CREATE OR REPLACE FUNCTION
GetFullName(First NVARCHAR2, Second NVARCHAR2)
RETURN NVARCHAR2 DETERMINISTIC IS BEGIN RETURN First || Second; END;");

                    context.GetService <IRelationalDatabaseCreator>().CreateTables();
                }

                using (var context = new BlogContextComputedColumnWithFunction(testStore.Name))
                {
                    var blog = context.Add(new FullNameBlog {
                        FirstName = "One", LastName = "Unicorn"
                    }).Entity;

                    context.SaveChanges();

                    Assert.Equal("OneUnicorn", blog.FullName);
                }

                using (var context = new BlogContextComputedColumnWithFunction(testStore.Name))
                {
                    var blog = context.FullNameBlogs.Single();

                    Assert.Equal("OneUnicorn", blog.FullName);

                    blog.LastName = "Pegasus";

                    context.SaveChanges();

                    Assert.Equal("OnePegasus", blog.FullName);
                }
            }
        }
        private static async Task Deletes_database_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateInitialized("DeleteBlogging"))
            {
                testDatabase.CloseConnection();

                var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);

                Assert.True(async ? await creator.ExistsAsync() : creator.Exists());

                if (async)
                {
                    await creator.DeleteAsync();
                }
                else
                {
                    creator.Delete();
                }

                Assert.False(async ? await creator.ExistsAsync() : creator.Exists());
            }
        }
        public void Insert_with_explicit_default_keys()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContext(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    context.AddRange(new Blog {
                        Id = 0, Name = "One Unicorn"
                    }, new Blog {
                        Id = 1, Name = "Two Unicorns"
                    });

                    // DbUpdateException : An error occurred while updating the entries. See the
                    // inner exception for details.
                    // SqlException : Cannot insert explicit value for identity column in table
                    // 'Blog' when IDENTITY_INSERT is set to OFF.
                    Assert.Throws <DbUpdateException>(() => context.SaveChanges());
                }
            }
        }
        public void Insert_explicit_value_throws_when_readonly_sequence_before_save()
        {
            using (var testStore = OracleTestStore.CreateInitialized(DatabaseName))
            {
                using (var context = new BlogContextReadOnlySequenceKeyColumnWithDefaultValue(testStore.Name))
                {
                    context.Database.EnsureCreated();

                    context.AddRange(new Blog {
                        Id = 1, Name = "One Unicorn"
                    }, new Blog {
                        Name = "Two Unicorns"
                    });

                    // The property 'Id' on entity type 'Blog' is defined to be read-only before it is
                    // saved, but its value has been set to something other than a temporary or default value.
                    Assert.Equal(
                        CoreStrings.PropertyReadOnlyBeforeSave("Id", "Blog"),
                        Assert.Throws <InvalidOperationException>(() => context.SaveChanges()).Message);
                }
            }
        }
 public ComputedColumnTest()
 {
     TestStore = OracleTestStore.CreateInitialized("ComputedColumnTest");
 }
        public async Task Can_save_changes()
        {
            using (var testDatabase = OracleTestStore.CreateInitialized(DatabaseName))
            {
                var options = Fixture.CreateOptions(testDatabase);
                using (var db = new BloggingContext(options))
                {
                    await CreateBlogDatabaseAsync <Blog>(db);
                }

                Fixture.TestSqlLoggerFactory.Clear();

                using (var db = new BloggingContext(options))
                {
                    var toUpdate = db.Blogs.Single(b => b.Name == "Blog1");
                    toUpdate.Name = "Blog is Updated";
                    var updatedId = toUpdate.Id;
                    var toDelete  = db.Blogs.Single(b => b.Name == "Blog2");
                    toDelete.Name = "Blog to delete";
                    var deletedId = toDelete.Id;

                    db.Entry(toUpdate).State = EntityState.Modified;
                    db.Entry(toDelete).State = EntityState.Deleted;

                    var toAdd = db.Add(
                        new Blog
                    {
                        Name       = "Blog to Insert",
                        George     = true,
                        TheGu      = new Guid("0456AEF1-B7FC-47AA-8102-975D6BA3A9BF"),
                        NotFigTime = new DateTime(1973, 9, 3, 0, 10, 33, 777),
                        ToEat      = 64,
                        OrNothing  = 0.123456789,
                        Fuse       = 777,
                        WayRound   = 9876543210,
                        Away       = 0.12345f,
                        AndChew    = new byte[16]
                    }).Entity;

                    await db.SaveChangesAsync();

                    var addedId = toAdd.Id;
                    Assert.NotEqual(0, addedId);

                    Assert.Equal(EntityState.Unchanged, db.Entry(toUpdate).State);
                    Assert.Equal(EntityState.Unchanged, db.Entry(toAdd).State);
                    Assert.DoesNotContain(toDelete, db.ChangeTracker.Entries().Select(e => e.Entity));

                    Assert.Equal(5, Fixture.TestSqlLoggerFactory.SqlStatements.Count);
                    Assert.Contains("SELECT", Fixture.TestSqlLoggerFactory.SqlStatements[0]);
                    Assert.Contains("SELECT", Fixture.TestSqlLoggerFactory.SqlStatements[1]);
                    Assert.Contains(":p0='" + deletedId, Fixture.TestSqlLoggerFactory.SqlStatements[2]);
                    Assert.Contains("DELETE", Fixture.TestSqlLoggerFactory.SqlStatements[2]);
                    Assert.Contains("UPDATE", Fixture.TestSqlLoggerFactory.SqlStatements[3]);
                    Assert.Contains("INSERT", Fixture.TestSqlLoggerFactory.SqlStatements[4]);

                    var rows = await testDatabase.ExecuteScalarAsync <int>(
                        $@"SELECT Count(*) FROM ""Blog"" WHERE ""Id"" = {updatedId} AND ""Name"" = 'Blog is Updated'");

                    Assert.Equal(1, rows);

                    rows = await testDatabase.ExecuteScalarAsync <int>(
                        $@"SELECT Count(*) FROM ""Blog"" WHERE ""Id"" = {deletedId}");

                    Assert.Equal(0, rows);

                    rows = await testDatabase.ExecuteScalarAsync <int>(
                        $@"SELECT Count(*) FROM ""Blog"" WHERE ""Id"" = {addedId} AND ""Name"" = 'Blog to Insert'");

                    Assert.Equal(1, rows);
                }
            }
        }
        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]);
                }
            }
        }
Example #24
0
 public CompositeKeyEndToEndTest()
 {
     TestStore = OracleTestStore.CreateInitialized("CompositeKeyEndToEndTest");
 }
Example #25
0
 public SequenceEndToEndTest()
 {
     TestStore = OracleTestStore.CreateInitialized("SequenceEndToEndTest");
 }
        private async Task RoundTripChanges <TBlog>()
            where TBlog : class, IBlog, new()
        {
            using (var testDatabase = OracleTestStore.CreateInitialized(DatabaseName))
            {
                var options = Fixture.CreateOptions(testDatabase);

                int blog1Id;
                int blog2Id;
                int blog3Id;

                using (var context = new BloggingContext <TBlog>(options))
                {
                    var blogs = await CreateBlogDatabaseAsync <TBlog>(context);

                    blog1Id = blogs[0].Id;
                    blog2Id = blogs[1].Id;

                    Assert.NotEqual(0, blog1Id);
                    Assert.NotEqual(0, blog2Id);
                    Assert.NotEqual(blog1Id, blog2Id);
                }

                using (var context = new BloggingContext <TBlog>(options))
                {
                    var blogs = context.Blogs.ToList();
                    Assert.Equal(2, blogs.Count);

                    var blog1 = blogs.Single(b => b.Name == "Blog1");
                    Assert.Equal(blog1Id, blog1.Id);

                    Assert.Equal("Blog1", blog1.Name);
                    Assert.True(blog1.George);
                    Assert.Equal(new Guid("0456AEF1-B7FC-47AA-8102-975D6BA3A9BF"), blog1.TheGu);
                    Assert.Equal(new DateTime(1973, 9, 3, 0, 10, 33, 777), blog1.NotFigTime);
                    Assert.Equal(64, blog1.ToEat);
                    Assert.Equal(0.123456789, blog1.OrNothing);
                    Assert.Equal(777, blog1.Fuse);
                    Assert.Equal(9876543210, blog1.WayRound);
                    Assert.Equal(0.12345f, blog1.Away);
                    Assert.Equal(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, blog1.AndChew);

                    blog1.Name = "New Name";

                    var blog2 = blogs.Single(b => b.Name == "Blog2");
                    Assert.Equal(blog2Id, blog2.Id);

                    blog2.Name       = null;
                    blog2.NotFigTime = new DateTime();
                    blog2.AndChew    = null;

                    var blog3 = context.Add(new TBlog()).Entity;

                    await context.SaveChangesAsync();

                    blog3Id = blog3.Id;
                    Assert.NotEqual(0, blog3Id);
                }

                using (var context = new BloggingContext <TBlog>(options))
                {
                    var blogs = context.Blogs.ToList();
                    Assert.Equal(3, blogs.Count);

                    Assert.Equal("New Name", blogs.Single(b => b.Id == blog1Id).Name);

                    var blog2 = blogs.Single(b => b.Id == blog2Id);
                    Assert.Null(blog2.Name);
                    Assert.Equal(blog2.NotFigTime, new DateTime());
                    Assert.Null(blog2.AndChew);

                    var blog3 = blogs.Single(b => b.Id == blog3Id);
                    Assert.Null(blog3.Name);
                    Assert.Equal(blog3.NotFigTime, new DateTime());
                    Assert.Null(blog3.AndChew);
                }
            }
        }
 public DefaultValuesTest()
 {
     TestStore = OracleTestStore.CreateInitialized("DefaultValuesTest");
 }