Inheritance: Tests.EntityWithTracking, ITriggerable
        public void WhenDefaultClassValueProvidedForMissingKey()
        {
            var @default = new Person { Age = 25 };

            var person = new AppConfig().Value().For("jon", @default);

            Assert.That(person.Age, Is.EqualTo(@default.Age));
        }
 private void AddHandlers(Person person)
 {
     person.Inserting += e => ++insertingFiredCount;
     person.Updating += e => ++updatingFiredCount;
     person.Deleting += e => ++deletingFiredCount;
     person.Inserted += e => ++insertedFiredCount;
     person.Updated += e => ++updatedFiredCount;
     person.Deleted += e => ++deletedFiredCount;
 }
示例#3
0
        public void Automatic()
        {
            var person = new Person() { Age = 54, FirstName = "bob" };

            person.Address.Add("101 some road");
            person.Address.Add("Unit 501");
            person.Contact.Email = "*****@*****.**";
            person.Contact.Phone = "123-456-7890";
            Console.WriteLine(person.ToJson()); //Was missing a using to get the .ToJson() method
        }
示例#4
0
        static void Main()
        {
            Person gosho = new Person("Gosheto", 18);
            gosho.AddGrade(5);
            gosho.AddGrade(12);
            gosho.AddGrade(23);
            gosho.AddGrade(45);

            for (int i = 0; i < gosho.GradeList.Count; i++)
            {
                Console.WriteLine(gosho.GradeList[i]);
            }
        }
示例#5
0
        public void Automatic()
        {
            var person = new Person
            {
                Age = 54,
                FirstName = "bob"
            };

            person.Address.Add("101 Some Road");
            person.Address.Add("Unit 501");

            person.Contact.Email = "*****@*****.**";
            person.Contact.Phone = "123-456-7890";

            Console.WriteLine(person.ToJson());
        }
示例#6
0
        public void AddPoco()
        {
            var person = new Person
            {
                Age = 46,
                FirstName = "Yannis",
                NetValue = 100.5,
                Date = DateTime.Now,
            };
            person.Address = new List<string>();
            person.Address.AddRange(new[] { "Irakleous 7", "Proodou 5" });
            person.Contact.Name = "Manolis";
            person.Contact.PhoneNumber = "123456789";

            Console.WriteLine(person.ToJson());
        }
示例#7
0
        public void SerializationAttributes()
        {
            var person = new Person();
            person.NetWorth = 100.5m;
            person.BirthTime = new DateTime(2014, 1, 2, 11, 30, 0);
            person.BirthTimeLocal = new DateTime(2014, 1, 2, 11, 30, 0);

            person.BirthDate = new DateTime(2014, 1, 2);
            person.BirthDateOnly = new DateTime(2014, 1, 2);

            var personJson = person.ToJson();
            Console.WriteLine(personJson);

            var personObject = BsonSerializer.Deserialize<Person>(personJson);
            Console.WriteLine(personObject.BirthTime);
            Console.WriteLine(personObject.BirthTimeLocal);
        }
示例#8
0
        public void Test()
        {
            var p = new Person
                        {
                            Name = "a",
                            Age = 3,
                            Children = new[]
                                           {
                                               new Person { Age = 1 },
                                               new Person { Age = 2 },
                                               new Person { Age = 3 }
                                           }
                        };

            var pwm = new PersonViewModel();

            pwm.InjectFrom(p);
            pwm.Children = p.Children.Select(c => new PersonViewModel().InjectFrom(c)).Cast<PersonViewModel>();

            pwm.Name.IsEqualTo(p.Name);
            pwm.Age.IsEqualTo(p.Age);
            pwm.Children.Count().IsEqualTo(3);
            pwm.Children.ToArray()[0].Age.IsEqualTo(1);
        }
        public void TrySelectFirstNotNullOrEmpty_WithDates()
        {
            //arrange
            DateTime dt = DateTime.UtcNow;
            var person1 = new Person
            {
                DateOfDeath = dt
            };
            var person2 = new Person();

            //act
            var randoms = new List<Person>
            {
                person1,
                person2
            }.Shuffle();

            //assert
            Assert.That(randoms.TrySelectFirstNotNullOrEmpty(x => x.DateOfDeath).Value, Is.EqualTo(dt));
        }
        private void AddHandlers(Person person) {
			person.Triggers().Inserting += e => ((Context)e.Context).Things.Add(new Thing { Value = "Insert trigger fired for " + e.Entity.FirstName });
			person.Triggers().Inserting += e => ++insertingFiredCount;
			person.Triggers().Inserting += e => e.Entity.LastName = "asdf";
            person.Triggers().Updating += e => ++updatingFiredCount;
            person.Triggers().Deleting += e => ++deletingFiredCount;
            person.Triggers().Inserted += e => ++insertedFiredCount;
            person.Triggers().Updated += e => ++updatedFiredCount;
            person.Triggers().Deleted += e => ++deletedFiredCount;
			person.Triggers().InsertFailed += e => ((Context)e.Context).Things.Add(new Thing { Value = "Insert failed for " + e.Entity.FirstName + " with exception message: " + e.Exception.Message });
			person.Triggers().InsertFailed += e => ++insertFailedFiredCount;
			person.Triggers().UpdateFailed += e => ((Context)e.Context).Things.Add(new Thing { Value = updateFailedThingValue = "Update failed for " + e.Entity.FirstName + " with exception message: " + e.Exception.Message });
			person.Triggers().UpdateFailed += e => ++updateFailedFiredCount;
			person.Triggers().DeleteFailed += e => ((Context)e.Context).Things.Add(new Thing { Value = "Delete failed for " + e.Entity.FirstName + " with exception message: " + e.Exception.Message });
			person.Triggers().DeleteFailed += e => ++deleteFailedFiredCount;
        }
示例#11
0
        private void TestEvents(Func<Context, Int32> saveChangesAction)
        {
            insertingFiredCount = 0;
            updatingFiredCount = 0;
            deletingFiredCount = 0;
            insertedFiredCount = 0;
            updatedFiredCount = 0;
            deletedFiredCount = 0;
            using (var context = new Context()) {
                var nickStrupat = new Person {
                                                 FirstName = "Nick",
                                                 LastName = "Strupat",
                                             };
                AddHandlers(nickStrupat);
                context.People.Add(nickStrupat);

                var johnSmith = new Person {
                                               FirstName = "John",
                                               LastName = "Smith"
                                           };
                AddHandlers(johnSmith);
                context.People.Add(johnSmith);
                AssertNoEventsHaveFired();

                saveChangesAction(context);
                AssertInsertEventsHaveFired();

                nickStrupat.FirstName = "Nicholas";
                saveChangesAction(context);
                AssertUpdateEventsHaveFired();

                context.People.Remove(nickStrupat);
                context.People.Remove(johnSmith);
                saveChangesAction(context);
                AssertAllEventsHaveFired();

                context.Database.Delete();
            }
        }
示例#12
0
        public void SingletonShouldReturnSameValues()
        {
            Person p = new Person {
                Age = 21,
                Name = "John"
            };

            Injector.Mappings.Add<IEntity>(() => {
                return p;
            });

            Person p1 = (Person)Injector.Build<IEntity>();
            Person p2 = (Person)Injector.Build<IEntity>();

            p2.Age = 22;
            p2.Name = "Bill";

            Assert.AreSame(p1, p2);
        }
示例#13
0
 public void SerializationAttributes()
 {
     var person = new Person();
     Console.WriteLine(person.ToJson());
 }
示例#14
0
 public void Setup()
 {
     Martin = new Person("Martin Perciante", "5.216.698-7");
 }
示例#15
0
        public void Nombre_Vacio()
        {
            Person Jorge = new Person("", "5.302.011-2");

            Assert.AreEqual(null, Jorge.Name);
        }
示例#16
0
        public void Cedula_Invalida()
        {
            Person Jorge = new Person("Jorge Rial", "5.302.011-1");

            Assert.AreEqual(null, Jorge.ID);
        }
示例#17
0
        public void Cedula_Correcta()
        {
            Person Jorge = new Person("Jorge Rial", "5.302.011-2");

            Assert.AreEqual("5.302.011-2", Jorge.ID);
        }
        public void ConditionalAccess_ManOrBoy3()
        {
            var p1 = new Person { Name = "Bart" };
            var p2 = new Person { Name = "Bart", DOB = new DateTime(1983, 2, 11) };

            var p = Expression.Parameter(typeof(Person));

            var name = PropertyInfoOf((Person x) => x.Name);
            var dob = PropertyInfoOf((Person x) => x.DOB);
            var length = PropertyInfoOf((string s) => s.Length);
            var year = PropertyInfoOf((DateTime x) => x.Year);
            var toUpper = MethodInfoOf((string s) => s.ToUpper());

            var e1 = CSharpExpression.ConditionalProperty(CSharpExpression.ConditionalProperty(p, name), length);
            var f1 = Expression.Lambda<Func<Person, int?>>(e1, p).Compile();

            Assert.IsNull(f1(null));
            Assert.AreEqual(4, f1(p1).Value);

            var e2 = CSharpExpression.ConditionalCall(CSharpExpression.ConditionalProperty(p, name), toUpper);
            var f2 = Expression.Lambda<Func<Person, string>>(e2, p).Compile();

            Assert.IsNull(f2(null));
            Assert.AreEqual("BART", f2(p1));

            var e3 = CSharpExpression.ConditionalProperty(CSharpExpression.ConditionalProperty(p, dob), year);
            var f3 = Expression.Lambda<Func<Person, int?>>(e3, p).Compile();

            Assert.IsNull(f3(null));
            Assert.IsNull(f3(p1));
            Assert.AreEqual(1983, f3(p2));
        }
 public void Setup()
 {
     person           = new Person(100000000L, "Ivan");
     extendedDatabase = new ExtendedDatabase.ExtendedDatabase();
 }
        private void TestEvents(Func<Context, Int32> saveChangesAction) {
            insertingFiredCount = 0;
            updatingFiredCount = 0;
            deletingFiredCount = 0;
			insertFailedFiredCount = 0;
			updateFailedFiredCount = 0;
			deleteFailedFiredCount = 0;
            insertedFiredCount = 0;
            updatedFiredCount = 0;
			deletedFiredCount = 0;
			updateFailedThingValue = null;
            using (var context = new Context()) {
                var nickStrupat = new Person {
                                                 FirstName = "Nick",
                                                 LastName = "Strupat",
                                             };
                AddHandlers(nickStrupat);
				nickStrupat.Triggers().Deleting += e => {
					e.Entity.IsMarkedDeleted = true;
					e.Cancel();
				};
                context.People.Add(nickStrupat);

	            var johnSmith = new Person {
                                               FirstName = "John",
                                               LastName = "Smith"
                                           };
                AddHandlers(johnSmith);
                context.People.Add(johnSmith);
                AssertNoEventsHaveFired();

                saveChangesAction(context);
				Assert.IsTrue(nickStrupat.Number == 42);
                AssertInsertEventsHaveFired();
				Assert.IsTrue(context.Things.First().Value == "Insert trigger fired for Nick");

                nickStrupat.FirstName = "Nicholas";
                saveChangesAction(context);
				AssertUpdateEventsHaveFired();

				nickStrupat.LastName = null;
				try {
					context.SaveChanges();
				}
				catch (DbEntityValidationException ex) {
					nickStrupat.LastName = "Strupat";
				}
				catch (Exception ex) {
					Assert.Fail(ex.GetType().Name + " exception caught");
				}
				context.SaveChanges();
				Assert.AreEqual(updateFailedFiredCount, 1);
				Assert.IsTrue(context.Things.OrderByDescending(x => x.Id).First().Value == updateFailedThingValue);

                context.People.Remove(nickStrupat);
                context.People.Remove(johnSmith);
                saveChangesAction(context);
				AssertAllEventsHaveFired();

                context.Database.Delete();
            }
        }
 private void TestOrder(Func<Context, Int32> saveChangesAction) {
     var list = new List<Int32>();
     using (var context = new Context()) {
         var janeDoe = new Person {
             FirstName = "Jane",
             LastName = "Doe",
         };
         janeDoe.Triggers().Inserted += e => list.Add(0);
         ((EntityWithInsertTracking)janeDoe).Triggers().Inserted += e => list.Add(1);
         ((EntityWithTracking)janeDoe).Triggers().Inserted += e => list.Add(2);
         context.People.Add(janeDoe);
         saveChangesAction(context);
     }
     Assert.IsTrue(list.SequenceEqual(new [] {0, 1, 2}));
 }
示例#22
0
文件: Samples.cs 项目: stemarie/CLAP
 public void Foo(Person p)
 {
     Person = p;
 }
示例#23
0
        public void Nombre_Correcto()
        {
            Person Jorge = new Person("Jorge Rial", "5.302.011-2");

            Assert.AreEqual("Jorge Rial", Jorge.Name);
        }