예제 #1
0
        public void TestUpdateRemoteProxyWithUserState()
        {
            Csla.DataPortal.ProxyTypeName = typeof(SynchronizedWcfProxy).AssemblyQualifiedName;

            UnitTestContext context   = GetContext();
            object          userState = "user state";

            DataPortal.BeginCreate <Customer>(new SingleCriteria <Customer, int>(2), (o, e) =>
            {
                Customer actual = e.Object;
                actual.Name     = "new name";
                DataPortal.BeginUpdate <Customer>(actual, (o1, e1) =>
                {
                    context.Assert.IsNull(e.Error);
                    context.Assert.IsNotNull(actual);
                    context.Assert.AreEqual(2, actual.Id);
                    context.Assert.IsTrue(actual.IsNew);
                    context.Assert.IsTrue(actual.IsDirty);
                    context.Assert.IsFalse(actual.IsDeleted);
                    context.Assert.AreEqual("user state", e.UserState.ToString());
                    context.Assert.Success();
                }, userState);
            }, userState);

            context.Complete();
        }
예제 #2
0
        public async Task ConsumerProcessMessages()
        {
            int expectedCount = 5;
            int count         = 0;

            var greeting = Greeting.Factory.CreateDefault();
            var ctx      = new UnitTestContext();

            var hostedService = new GreetingConsumerWorker(ctx.GreetingManager.Object, ctx.GreetingQueue.Object, ctx.GetLoggerMock <GreetingConsumerWorker>().Object);

            //Cancel after X calls
            ctx.GreetingQueue
            .Setup(x => x.ReceiveAsync())
            .ReturnsAsync(greeting)
            .Callback(async() =>
            {
                count++;
                if (count == expectedCount)
                {
                    await hostedService.StopAsync(CancellationToken.None);
                }
            });

            //act
            await hostedService.StartAsync(CancellationToken.None);

            await Task.Delay(1000); //Time to execute

            ctx.GreetingQueue.Verify(x => x.ReceiveAsync(), Times.Exactly(expectedCount));
            ctx.GreetingManager.Verify(x => x.ReceiveAsync(greeting), Times.Exactly(expectedCount));
        }
 public void Roundtrip()
 {
     using (var context = new UnitTestContext(this))
     {
         VerifyRoundtrip(context, new LocalDate(2003, 5, 1));
     }
 }
예제 #4
0
        public void TestSaveWhileBusy()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#endif
            UnitTestContext    context = GetContext();
            ItemWithAsynchRule item;
            ItemWithAsynchRule.GetItemWithAsynchRule("an id", (o, e) =>
            {
                item = e.Object;
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(item);


                item.RuleField = "some value";
                context.Assert.IsTrue(item.IsBusy);
                context.Assert.IsFalse(item.IsSavable);

                item.BeginSave((o1, e1) =>
                {
                    var error = e1.Error as InvalidOperationException;
                    context.Assert.IsNotNull(error);
                    if (error != null)
                    {
                        context.Assert.IsTrue(error.Message.ToLower().Contains("busy"));
                    }
                    context.Assert.IsTrue(error.Message.ToLower().Contains("save"));
                    context.Assert.Success();
                });
            });
            context.Complete();
        }
예제 #5
0
        public void OneToManyWhereTheOneAlreadyExists()
        {
            using (var db = new UnitTestContext())
            {
                var now = DateTime.Now;

                Parity even = new Parity {
                    Name = "Even", UpdatedAt = now, UpdatedBy = "Måns"
                };
                Parity odd = new Parity {
                    Name = "Odd", UpdatedAt = now, UpdatedBy = "Måns"
                };
                db.BulkInsertAll(new[] { even, odd });

                var numbers = GenerateNumbers(1, 100, even, odd, now).ToArray();
                db.BulkInsertAll(numbers);

                Assert.AreEqual(100, db.Numbers.Count());

                var dbNumbers = db.Numbers.Include(n => n.Parity).ToArray();
                foreach (var number in dbNumbers.Where(n => n.Value % 2 == 0))
                {
                    Assert.AreEqual("Even", number.Parity.Name);
                    Assert.AreEqual(now.ToString("yyyyMMddHHmmss"), number.UpdatedAt.ToString("yyyyMMddHHmmss"));
                }

                foreach (var number in dbNumbers.Where(n => n.Value % 2 != 0))
                {
                    Assert.AreEqual("Odd", number.Parity.Name);
                    Assert.AreEqual(now.ToString("yyyyMMddHHmmss"), number.UpdatedAt.ToString("yyyyMMddHHmmss"));
                }
            }
        }
예제 #6
0
        public void ListTestSaveWhileBusyNetOnly()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#else
            System.Configuration.ConfigurationManager.AppSettings["CslaAutoCloneOnUpdate"] = "false";
#endif
            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems();

            items[0].RuleField = "some value";
            context.Assert.IsTrue(items.IsBusy);
            context.Assert.IsFalse(items.IsSavable);
            bool gotError = false;
            try
            {
                items.Save();
            }
            catch (InvalidOperationException EX)
            {
                gotError = true;
            }
            context.Assert.IsTrue(gotError);
            context.Assert.Success();

            context.Complete();
        }
예제 #7
0
        public void TestSaveWhileNotBusyNetOnly()
        {
            UnitTestContext context = GetContext();

            System.Configuration.ConfigurationManager.AppSettings["CslaAutoCloneOnUpdate"] = "false";
            ItemWithAsynchRule item;

            ItemWithAsynchRule.GetItemWithAsynchRule("an id", (o, e) =>
            {
                item = e.Object;
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(item);


                item.RuleField = "some value";
                context.Assert.IsTrue(item.IsBusy);
                context.Assert.IsFalse(item.IsSavable);
                item.ValidationComplete += (o2, e2) =>
                {
                    context.Assert.IsFalse(item.IsBusy);
                    context.Assert.IsTrue(item.IsSavable);
                    item = item.Save();
                    context.Assert.AreEqual("DataPortal_Update", item.OperationResult);
                    context.Assert.Success();
                };
            });
            context.Complete();
        }
예제 #8
0
        public void ListTestSaveWhileBusyNetOnly()
        {
            IDataPortal <ItemWithAsynchRuleList> dataPortal = _noCloneOnUpdateDIContext.CreateDataPortal <ItemWithAsynchRuleList>();

            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems(dataPortal);

            items[0].RuleField = "some value";
            context.Assert.IsTrue(items.IsBusy);
            context.Assert.IsFalse(items.IsSavable);
            bool gotError = false;

            try
            {
                items.Save();
            }
            catch (InvalidOperationException)
            {
                gotError = true;
            }
            context.Assert.IsTrue(gotError);
            context.Assert.Success();

            context.Complete();
        }
예제 #9
0
        public async Task TestSaveWhileBusy()
        {
            IDataPortal <ItemWithAsynchRule> dataPortal = _testDIContext.CreateDataPortal <ItemWithAsynchRule>();

            UnitTestContext context = GetContext();
            var             item    = await dataPortal.FetchAsync("an id");

            item.RuleField = "some value";
            context.Assert.IsTrue(item.IsBusy);
            context.Assert.IsFalse(item.IsSavable);

            try
            {
                await item.SaveAsync();
            }
            catch (Exception ex)
            {
                var error = ex as InvalidOperationException;
                context.Assert.IsNotNull(error);
                context.Assert.IsTrue(error.Message.ToLower().Contains("busy"));
                context.Assert.IsTrue(error.Message.ToLower().Contains("save"));
                context.Assert.Success();
            }
            context.Complete();
        }
예제 #10
0
        public void TestCoerseValue()
        {
            UnitTestContext     context = GetContext();
            UtilitiesTestHelper helper  = new UtilitiesTestHelper();

            helper.IntProperty    = 0;
            helper.StringProperty = "1";
            helper.IntProperty    = (int)Csla.Utilities.CoerceValue(typeof(int), typeof(string), null, helper.StringProperty);
            context.Assert.AreEqual(1, helper.IntProperty, "Should have converted to int");

            helper.IntProperty    = 2;
            helper.StringProperty = "";
            helper.StringProperty = (string)Csla.Utilities.CoerceValue(typeof(string), typeof(int), null, helper.IntProperty);
            context.Assert.AreEqual("2", helper.StringProperty, "Should have converted to string");


            helper.StringProperty         = "1";
            helper.NullableStringProperty = null;
            object convertedValue = Csla.Utilities.CoerceValue(typeof(string), typeof(string), null, helper.NullableStringProperty);

            context.Assert.IsNull(helper.NullableStringProperty);
            context.Assert.IsNull(convertedValue);

            context.Assert.AreEqual(UtilitiesTestHelper.ToStringValue, (string)Csla.Utilities.CoerceValue(typeof(string), typeof(UtilitiesTestHelper), null, helper), "Should have issued ToString()");
            context.Assert.Success();
            context.Complete();
        }
예제 #11
0
        public async Task ListTestSaveWhileBusy()
        {
            IDataPortal <ItemWithAsynchRuleList> dataPortal = _noCloneOnUpdateDIContext.CreateDataPortal <ItemWithAsynchRuleList>();

            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems(dataPortal);

            items[0].RuleField = "some value";
            context.Assert.IsTrue(items.IsBusy);
            context.Assert.IsFalse(items.IsSavable);

            try
            {
                await items.SaveAsync();
            }
            catch (Exception ex)
            {
                var error = ex as InvalidOperationException;
                context.Assert.IsNotNull(error);
                context.Assert.IsTrue(error.Message.ToLower().Contains("busy"));
                context.Assert.IsTrue(error.Message.ToLower().Contains("save"));
                context.Assert.Success();
            }
            context.Complete();
        }
예제 #12
0
        public void UndoChildSuccess()
        {
            UnitTestContext context = GetContext();
            Person          p       = new Person();

            p.Addresses = new AddressList();
            Address a = new Address();

            p.Addresses.Add(a);

            int    age1  = p.Age = 1;
            string city1 = a.City = "one";

            p.BeginEdit();

            int    age2  = p.Age = 2;
            string city2 = a.City = "two";

            a.BeginEdit();

            string city3 = a.City = "three";

            a.CancelEdit();

            context.Assert.AreEqual(age2, p.Age);
            context.Assert.AreEqual(city2, a.City);
            p.CancelEdit();

            context.Assert.AreEqual(age1, p.Age);
            context.Assert.AreEqual(city1, a.City);
            context.Assert.Success();
            context.Complete();
        }
예제 #13
0
        public void BackgroundWorker_CancelAsync_ThrowsInvalidOperationExceptionWhenWorkerSupportsCancellationIsFalse()
        {
            using (UnitTestContext context = GetContext())
            {
                BackgroundWorker target = new BackgroundWorker();
                target.DoWork += (o, e) =>
                {
                    for (int i = 1; i < 11; i++)
                    {
                        Thread.Sleep(10);
                    }
                };
                target.WorkerSupportsCancellation = false;
                target.RunWorkerAsync(null);

                try
                {
                    target.CancelAsync(); // this call throws exception
                }
                catch (InvalidOperationException ex)
                {
                    context.Assert.Fail(ex);
                }
                context.Complete();
            }
        }
예제 #14
0
        public void BackgroundWorker_CancelAsync_ReportsCancelledWhenWorkerSupportsCancellationIsTrue()
        {
            UnitTestContext context = GetContext();

            BackgroundWorker target = new BackgroundWorker();

            target.DoWork += (o, e) =>
            {
                // report progress changed 10 times
                for (int i = 1; i < 11; i++)
                {
                    Thread.Sleep(100);
                    if (target.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            };
            target.WorkerSupportsCancellation = true;
            target.RunWorkerCompleted        += (o, e) =>
            {
                //  target does not support ReportProgress we shold get a System.InvalidOperationException from DoWork
                context.Assert.IsNull(e.Error);
                context.Assert.IsTrue(e.Cancelled);
                context.Assert.Success();
            };
            target.RunWorkerAsync(null);
            target.CancelAsync();
            context.Complete();
        }
예제 #15
0
        public void BackgroundWorker_DoWork_ThrowsInvalidOperationExcpetionWhenWorkerReportsProgressIsFalse()
        {
            UnitTestContext context = GetContext();

            int numTimesProgressCalled = 0;

            BackgroundWorker target = new BackgroundWorker();

            target.DoWork += (o, e) =>
            {
                // report progress changed 10 times
                for (int i = 1; i < 11; i++)
                {
                    target.ReportProgress(i * 10);
                }
            };
            target.WorkerReportsProgress = false;
            target.ProgressChanged      += (o, e) =>
            {
                numTimesProgressCalled++;
            };
            target.RunWorkerCompleted += (o, e) =>
            {
                //  target does not support ReportProgress we shold get a System.InvalidOperationException from DoWork
                context.Assert.IsTrue(e.Error is System.InvalidOperationException);
                context.Assert.Success();
            };
            target.RunWorkerAsync(null);
            context.Complete();
        }
예제 #16
0
        public void LimitBuy()
        {
            UnitTestContext context = new UnitTestContext();

            context.Login();

            OrderViewModel vm = new OrderViewModel(context.App, new FIXApplication.NullFixStrategy());

            vm.OrderType        = FIXApplication.Enums.OrderType.Limit;
            vm.Symbol           = "LIM";
            vm.OrderQtyString   = "9";
            vm.LimitPriceString = "3.45";
            vm.SendBuyCommand.Execute(null);

            // messaging of sent order
            Assert.AreEqual(1, context.Session.MsgLookup[QuickFix.FIX42.NewOrderSingle.MsgType].Count);
            QuickFix.FIX42.NewOrderSingle msg = context.Session.MsgLookup[QuickFix.FIX42.NewOrderSingle.MsgType][0] as QuickFix.FIX42.NewOrderSingle;
            Assert.AreEqual("LIM", msg.Symbol.Obj);
            Assert.AreEqual(9, msg.OrderQty.Obj);
            Assert.AreEqual(3.45m, msg.Price.Obj);
            Assert.AreEqual(QuickFix.Fields.OrdType.LIMIT, msg.OrdType.Obj);
            Assert.AreEqual(QuickFix.Fields.Side.BUY, msg.Side.Obj);

            // what's in the grid
            Assert.AreEqual(1, vm.Orders.Count);
            OrderRecord o = vm.Orders.First();

            Assert.AreEqual("LIM", o.Symbol);
            Assert.AreEqual(3.45m, o.Price);
            Assert.AreEqual("Limit", o.OrdType);
            Assert.AreEqual("Buy", o.Side);
        }
예제 #17
0
        public void TestSaveWhileBusyNetOnly()
        {
            UnitTestContext    context = GetContext();
            ItemWithAsynchRule item;

            ItemWithAsynchRule.GetItemWithAsynchRule("an id", (o, e) =>
            {
                item = e.Object;
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(item);


                item.RuleField = "some value";
                context.Assert.IsTrue(item.IsBusy);
                context.Assert.IsFalse(item.IsSavable);
                bool gotError = false;
                try
                {
                    item.Save();
                }
                catch (InvalidOperationException EX)
                {
                    gotError = true;
                }
                context.Assert.IsTrue(gotError);
                context.Assert.Success();
            });
            context.Complete();
        }
예제 #18
0
        public void DefaultBuyOrder()
        {
            UnitTestContext context = new UnitTestContext();

            context.Login();

            OrderViewModel vm = new OrderViewModel(context.App, new FIXApplication.NullFixStrategy());

            vm.SendBuyCommand.Execute(null);

            // messaging of sent order
            Assert.AreEqual(1, context.Session.MsgLookup[QuickFix.FIX42.NewOrderSingle.MsgType].Count);
            QuickFix.FIX42.NewOrderSingle msg = context.Session.MsgLookup[QuickFix.FIX42.NewOrderSingle.MsgType][0] as QuickFix.FIX42.NewOrderSingle;
            Assert.AreEqual("IBM", msg.Symbol.Obj);
            Assert.AreEqual(5, msg.OrderQty.Obj);
            Assert.AreEqual(QuickFix.Fields.OrdType.MARKET, msg.OrdType.Obj);
            Assert.AreEqual(QuickFix.Fields.Side.BUY, msg.Side.Obj);

            // what's in the grid
            Assert.AreEqual(1, vm.Orders.Count);
            OrderRecord o = vm.Orders.First();

            Assert.AreEqual("IBM", o.Symbol);
            Assert.AreEqual(-1, o.Price);
            Assert.AreEqual("Market", o.OrdType);
            Assert.AreEqual("Buy", o.Side);
        }
예제 #19
0
        public void TestBusy()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#else
            System.Configuration.ConfigurationManager.AppSettings["CslaAutoCloneOnUpdate"] = "false";
#endif
            UnitTestContext    context = GetContext();
            ItemWithAsynchRule item;
            ItemWithAsynchRule.GetItemWithAsynchRule("an id", (o, e) =>
            {
                try
                {
                    item = e.Object;
                    context.Assert.IsNull(e.Error, "Error should be null");
                    context.Assert.IsNotNull(item, "item should not be null");

                    item.RuleField = "some value";
                    context.Assert.IsTrue(item.IsBusy, "Should be busy");
                    context.Assert.IsFalse(item.IsSavable, "Should not be savable");
                }
                catch (Exception ex)
                {
                    context.Assert.Fail(ex.ToString());
                }
                context.Assert.Success();
            });
            context.Complete();
        }
예제 #20
0
        public void MarketSell()
        {
            UnitTestContext context = new UnitTestContext();

            context.Login();

            OrderViewModel vm = new OrderViewModel(context.App, new FIXApplication.NullFixStrategy());

            vm.Symbol         = "pants";
            vm.OrderQtyString = "999";
            vm.SendSellCommand.Execute(null);

            // messaging of sent order
            Assert.AreEqual(1, context.Session.MsgLookup[QuickFix.FIX42.NewOrderSingle.MsgType].Count);
            QuickFix.FIX42.NewOrderSingle msg = context.Session.MsgLookup[QuickFix.FIX42.NewOrderSingle.MsgType][0] as QuickFix.FIX42.NewOrderSingle;
            Assert.AreEqual("pants", msg.Symbol.Obj);
            Assert.AreEqual(999, msg.OrderQty.Obj);
            Assert.AreEqual(QuickFix.Fields.Side.SELL, msg.Side.Obj);

            // what's in the grid
            Assert.AreEqual(1, vm.Orders.Count);
            OrderRecord o = vm.Orders.First();

            Assert.AreEqual("pants", o.Symbol);
            Assert.AreEqual(-1, o.Price);
            Assert.AreEqual("Market", o.OrdType);
            Assert.AreEqual("Sell", o.Side);
        }
예제 #21
0
        public void ListTestSaveWhileNotBusyNetOnly()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#else
            System.Configuration.ConfigurationManager.AppSettings["CslaAutoCloneOnUpdate"] = "false";
#endif
            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems();



            items[0].ValidationComplete += (o2, e2) =>
            {
                context.Assert.IsFalse(items.IsBusy);
                context.Assert.IsTrue(items.IsSavable);
                items = items.Save();
                context.Assert.AreEqual("DataPortal_Update", items[0].OperationResult);
                context.Assert.Success();
            };

            items[0].RuleField = "some value";
            context.Assert.IsTrue(items.IsBusy);
            context.Assert.IsFalse(items.IsSavable);

            context.Complete();
        }
예제 #22
0
        public void AddingEmployeeWithCompany()

        {
            var employee = new Employee
            {
                Name = "John",
            };
            var Company = new Company
            {
                Name = "World Inc",
            };

            Company.ParentCompany = Company;
            employee.Company      = Company;

            using (var db = new UnitTestContext())
            {
                var request = new BulkInsertRequest <Employee>
                {
                    Entities = new List <Employee> {
                        employee
                    },
                    EnableRecursiveInsert      = EnableRecursiveInsert.Yes,
                    AllowNotNullSelfReferences = AllowNotNullSelfReferences.Yes
                };
                db.BulkInsertAll(request);

                var actual = db.Companies.Include(e => e.Employees).Single();
                Assert.AreEqual("World Inc", actual.Name);
                Assert.AreSame(actual, actual.ParentCompany);
                Assert.AreEqual("John", actual.Employees.Single().Name);
            }
        }
예제 #23
0
        public void SetUp()
        {
            unitTestContext = new UnitTestContext();

            mtgStore = new MtgStore(
                testConfig.Url,
                testConfig.Database,
                unitTestContext.QueryStatisticsStoreMock.Object,
                unitTestContext.LoggingServiceMock.Object,
                unitTestContext.SearchUtilityMock.Object);

            unitTestContext.BotServicesMock.SetupGet(b => b.Store)
            .Returns(mtgStore);

            httpClient = new SimpleHttpClient(unitTestContext.LoggingServiceMock.Object);

            unitTestContext.BotServicesMock.SetupGet(b => b.HttpClient)
            .Returns(httpClient);

            plugin = new GiphyPlugin(
                unitTestContext.BotServicesMock.Object,
                unitTestContext.BotConfig);

            plugin.LoggingService = unitTestContext.LoggingServiceMock.Object;
        }
예제 #24
0
        public void AddingMotherWithChild()
        {
            var child = new Person
            {
                FirstName = "Arvid",
                LastName  = "Andersson",
                BirthDate = new DateTime(2018, 1, 1),
            };
            var mother = new Person
            {
                FirstName = "Anna",
                LastName  = "Andersson",
                BirthDate = new DateTime(1980, 1, 1),
            };

            mother.People.Add(child);

            using (var db = new UnitTestContext())
            {
                var request = new BulkInsertRequest <Person>
                {
                    Entities = new List <Person> {
                        mother
                    },
                    EnableRecursiveInsert = EnableRecursiveInsert.Yes,
                };
                db.BulkInsertAll(request);

                var people = db.People.ToArray();
                Assert.AreEqual(2, people.Length);
            }
        }
예제 #25
0
        public void OneToManyWhereAllIsNew()
        {
            using (var db = new UnitTestContext())
            {
                var now = DateTime.Now;

                var numbers = GenerateNumbers(1, 100, now).ToArray();
                var request = new BulkInsertRequest <Number>
                {
                    Entities = numbers,
                    EnableRecursiveInsert = EnableRecursiveInsert.Yes,
                };
                db.BulkInsertAll(request);

                Assert.AreEqual(100, db.Numbers.Count());

                var dbNumbers = db.Numbers.Include(n => n.Parity).ToArray();
                foreach (var number in dbNumbers.Where(n => n.Value % 2 == 0))
                {
                    Assert.AreEqual("Even", number.Parity.Name);
                    Assert.AreEqual(now.ToString("yyyyMMddHHmmss"), number.UpdatedAt.ToString("yyyyMMddHHmmss"));
                }

                foreach (var number in dbNumbers.Where(n => n.Value % 2 != 0))
                {
                    Assert.AreEqual("Odd", number.Parity.Name);
                    Assert.AreEqual(now.ToString("yyyyMMddHHmmss"), number.UpdatedAt.ToString("yyyyMMddHHmmss"));
                }
            }
        }
예제 #26
0
        public void ValidateMultipleObjectsSimultaneously()
        {
            UnitTestContext context = GetContext();

            context.Assert.Try(() =>
            {
                int iterations = 20;
                int completed  = 0;
                for (int x = 0; x < iterations; x++)
                {
                    HasAsyncRule har        = new HasAsyncRule();
                    har.ValidationComplete += (o, e) =>
                    {
                        context.Assert.AreEqual("error", har.Name);
                        context.Assert.AreEqual(1, har.BrokenRulesCollection.Count);
                        System.Diagnostics.Debug.WriteLine(har.BrokenRulesCollection.Count);
                        completed++;
                        if (completed == iterations)
                        {
                            context.Assert.Success();
                        }
                    };

                    // set this to error so we can verify that all 6 rules get run for
                    // each object. This is essentially the only way to communicate back
                    // with the object except byref properties.
                    har.Name = "error";
                }
            });

            context.Complete();
        }
예제 #27
0
        public void ExistingEntitiesShouldBeSelectedUsingRuntimeTypes()
        {
            using (var db = new UnitTestContext())
            {
                var now = DateTime.Now;

                // Save 200 numbers (1 to 200) to the database.
                var numbers = GenerateNumbers(1, 200, now).ToArray();
                db.BulkInsertAll(new BulkInsertRequest <Number>
                {
                    Entities = numbers,
                    EnableRecursiveInsert = EnableRecursiveInsert.Yes
                });

                // Create a list of 100 numbers with values 151 to 250
                numbers = GenerateNumbers(151, 100, now).ToArray();

                // Numbers 151 to 200 out of 151 to 250 should be selected.
                var request = typeof(BulkSelectRequest <>).MakeGenericType(typeof(Number));
                var r       = Activator.CreateInstance(request, new[] { "Value" }, numbers.ToList(), null);

                Type       ex              = typeof(DbContextExtensions);
                MethodInfo mi              = ex.GetMethod("BulkSelectExisting");
                MethodInfo miGeneric       = mi.MakeGenericMethod(new[] { typeof(Number), typeof(Number) });
                object[]   args            = { db, r };
                var        existingNumbers = (List <Number>)miGeneric.Invoke(null, args);

                Assert.AreEqual(50, existingNumbers.Count);
                for (int i = 0; i < 50; i++)
                {
                    Assert.AreSame(numbers[i], existingNumbers[i]);
                }
            }
        }
예제 #28
0
        public void ListTestSaveWhileBusy()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#else
            System.Configuration.ConfigurationManager.AppSettings["CslaAutoCloneOnUpdate"] = "false";
#endif
            UnitTestContext        context = GetContext();
            ItemWithAsynchRuleList items   = ItemWithAsynchRuleList.GetListWithItems();
            items[0].RuleField = "some value";
            context.Assert.IsTrue(items.IsBusy);
            context.Assert.IsFalse(items.IsSavable);

            items.BeginSave((o1, e1) =>
            {
                var error = e1.Error as InvalidOperationException;
                context.Assert.IsNotNull(error);
                if (error != null)
                {
                    context.Assert.IsTrue(error.Message.ToLower().Contains("busy"));
                }
                context.Assert.IsTrue(error.Message.ToLower().Contains("save"));
                context.Assert.Success();
            });

            context.Complete();
        }
예제 #29
0
        public void TestSaveRemoteProxyWithoutUserState()
        {
            Csla.DataPortal.ProxyTypeName = typeof(SynchronizedWcfProxy).AssemblyQualifiedName;

            UnitTestContext context = GetContext();

            DataPortal.BeginCreate <Customer>(new SingleCriteria <Customer, int>(2), (o, e) =>
            {
                Customer actual = e.Object;
                actual.Name     = "new name";
                actual.BeginSave((o1, e1) =>
                {
                    context.Assert.IsNull(e.Error);
                    context.Assert.IsNotNull(actual);
                    Customer actual2 = (Customer)e1.NewObject;
                    context.Assert.IsNotNull(actual2);
                    if (actual2 != null)
                    {
                        context.Assert.AreEqual(2, actual2.Id);
                        context.Assert.IsFalse(actual2.IsNew);
                        context.Assert.IsFalse(actual2.IsDirty);
                        context.Assert.IsFalse(actual2.IsDeleted);
                        context.Assert.IsNull(e.UserState);
                        context.Assert.Success();
                    }
                });
            });

            context.Complete();
        }
예제 #30
0
        public void TestNotBusy()
        {
#if SILVERLIGHT
            DataPortal.ProxyTypeName = "Local";
#endif
            UnitTestContext    context = GetContext();
            ItemWithAsynchRule item;
            ItemWithAsynchRule.GetItemWithAsynchRule("an id", (o, e) =>
            {
                item = e.Object;
                context.Assert.IsNull(e.Error);
                context.Assert.IsNotNull(item);


                item.RuleField = "some value";
                context.Assert.IsTrue(item.IsBusy);
                context.Assert.IsFalse(item.IsSavable);
                item.ValidationComplete += (o2, e2) =>
                {
                    context.Assert.IsFalse(item.IsBusy);
                    context.Assert.IsTrue(item.IsSavable);
                    context.Assert.Success();
                };
            });
            context.Complete();
        }
예제 #31
0
 public void SetUp()
 {
     _context = GetContext();
 }
예제 #32
0
 public SettingsBehaviour(UnitTestContext context)
 {
     Context = context;
 }