예제 #1
0
        public void UpsertRangeTest2()
        {
            DataProviderSetupTearDown.TearDownAndBuildUpDbEnvironment();

            using (var DP = DIUnitTestContainer.DIContainer.Resolve<EntityFrameworkDP<EntityFrameworkEntityDP>>(WritableDataProviderName))
            {
                //string value to change
                const string ChangeStringValue = "UpdatedRecordDescription";

                //grab 2 records to change
                var NewRecord1 = DP.EFContext.Ref_Test.First();
                var NewRecord2 = DP.EFContext.Ref_Test.OrderBy(x => x.Id).Skip(1).First();

                //set the description on the first record
                NewRecord1.Description = ChangeStringValue;

                //create a list to upsert
                var RecordsToUpsert = new Ref_Test[] { NewRecord1, NewRecord2 };

                //upsert the records and save
                DP.UpsertRange(RecordsToUpsert, true);

                //make sure we have the change string on the record we wanted to change
                Assert.Equal(ChangeStringValue, DP.EFContext.Ref_Test.Single(x => x.Id == NewRecord1.Id).Description);

                //make sure we only have this record with this description
                Assert.Equal(1, DP.EFContext.Ref_Test.Count(x => x.Description == ChangeStringValue));
            }
        }
예제 #2
0
        public void TransactionTest2()
        {
            DataProviderSetupTearDown.TruncateTable();

            using (var DP = DIUnitTestContainer.DIContainer.Resolve<EntityFrameworkDP<EntityFrameworkEntityDP>>(WritableDataProviderName))
            {
                //Record to add
                var RecordToAdd = new Ref_Test() { Description = "New Record" };

                //start the transaction
                DP.StartTransaction();

                //add the record, don't save yet
                DP.Add(RecordToAdd, false);

                //make sure we still have 0 records
                Assert.Equal(0, DP.Fetch<Ref_Test>(false).Count());

                //save the changes now
                DP.SaveChanges();

                //should have 1 record
                Assert.Equal(1, DP.Fetch<Ref_Test>(false).Count());

                //commit the transaction now
                DP.CommitTransaction();

                //shold have the 1 commited record in the table now
                Assert.Equal(1, DP.Fetch<Ref_Test>(false).Count());
            }
        }
예제 #3
0
        public void UpsertRangeTest1()
        {
            DataProviderSetupTearDown.TruncateTable();

            using (var DP = DIUnitTestContainer.DIContainer.Resolve<EntityFrameworkDP<EntityFrameworkEntityDP>>(WritableDataProviderName))
            {
                //create 2 random rows to upsert
                var NewRecord1 = new Ref_Test() { Id = -1, Description = "1" };
                var NewRecord2 = new Ref_Test() { Id = -1, Description = "2" };

                //rows to upsert
                var RowsToUpsert = new Ref_Test[] { NewRecord1, NewRecord2 };

                //go upsert the rows and save it
                DP.UpsertRange(RowsToUpsert, true);

                //how many rows + the rows in the collection
                Assert.Equal(RowsToUpsert.Length, DP.Fetch<Ref_Test>(false).Count());
            }
        }