Beispiel #1
0
        public override void Setup()
        {
            base.Setup();

            this._person     = RandomData.GeneratePerson <PersonProper>();
            this._peopleJson = this._person.ToJson();
        }
Beispiel #2
0
        public void AddIfNotExists()
        {
            var                  people       = RandomData.GeneratePersonCollection <PersonProper>(10);
            var                  person       = RandomData.GeneratePerson <PersonProper>();
            PersonProper         nullPerson   = null;
            var                  comparer     = new PersonProperComparer();
            PersonProperComparer nullComparer = null;
            List <PersonProper>  nullList     = null;

            // Test Parameters
            _ = Assert.ThrowsException <ArgumentReadOnlyException>(() => people.AsReadOnly().AddIfNotExists(person));

            // TEST
            Assert.IsFalse(people.AddIfNotExists(nullPerson));

            Assert.IsTrue(nullList.AddIfNotExists(person));

            Assert.IsFalse(people.AddIfNotExists(nullPerson, nullComparer));

            Assert.IsTrue(people.AddIfNotExists(person));

            Assert.IsFalse(people.AddIfNotExists(nullPerson));

            Assert.IsTrue(people.AddIfNotExists(RandomData.GeneratePerson <PersonProper>(), comparer));

            Assert.IsFalse(people.AddIfNotExists(nullPerson, comparer));
        }
        public void AddLastTest()
        {
            var          peopleList  = RandomData.GeneratePersonCollection <PersonProper>(10);
            var          peopleArray = peopleList.ToArray();
            var          person      = RandomData.GeneratePerson <PersonProper>();
            PersonProper nullPerson  = null;

            //Test Parameters
            _ = Assert.ThrowsException <ArgumentReadOnlyException>(() => peopleList.ToReadOnlyCollection()
                                                                   .AddLast(person));

            // Test List
            Assert.IsFalse(peopleList.AddLast(nullPerson));
            Assert.IsTrue(peopleList.Count() == peopleList.Count);

            Assert.IsTrue(peopleList.AddLast(person));
            Assert.IsTrue(peopleList.Last().Equals(person));


            // Test Array
            var result2 = peopleArray.AddLast(person);

            Assert.IsTrue(result2.Last().Equals(person));
            Assert.IsTrue(peopleArray.AddLast(null).Length == peopleArray.Length);
        }
Beispiel #4
0
        public void StripNullTest()
        {
            var          person     = RandomData.GenerateRefPerson <PersonProper>();
            PersonProper nullPerson = null;

            Assert.IsFalse(string.IsNullOrEmpty(person.StripNull()));
            Assert.IsTrue(string.IsNullOrEmpty(nullPerson.StripNull()));
        }
        public override void Setup()
        {
            base.Setup();

            this._personProper = RandomData.GenerateRefPerson <PersonProper>();
            this._personRecord = RandomData.GeneratePersonRecordCollection(count: 1, addressCount: 1).First();
            this._peopleJson   = this._personProper.ToJson();
        }
Beispiel #6
0
        public void ConditionCheckTest()
        {
            var personProper = RandomData.GenerateRefPerson <PersonProper>();

            Assert.IsTrue(personProper.CheckIsCondition(personProper.Id.IsNotEmpty(), errorMessage: "Should be true."));
            Assert.IsFalse(personProper.CheckIsCondition(personProper.Id.IsEmpty(), errorMessage: "Should be false."));

            PersonProper nullPerson = null;

            Assert.ThrowsException <InvalidValueException <object> >(() => nullPerson.CheckIsCondition(personProper.Id.IsNotEmpty(), true));
        }
Beispiel #7
0
        public void NullObjectTest()
        {
            var          person     = RandomData.GenerateRefPerson <PersonProper>();
            PersonProper nullPerson = null;

            Assert.IsFalse(person.IsNull());
            Assert.IsTrue(nullPerson.IsNull());

            Assert.IsTrue(person.IsNotNull());
            Assert.IsFalse(nullPerson.IsNotNull());
        }
Beispiel #8
0
        public void CheckIsNotNullObjectTest()
        {
            var          testPerson   = RandomData.GenerateRefPerson <PersonProper>();
            PersonProper invalidValue = null;

            Assert.IsTrue(testPerson.CheckIsNotNull());

            Assert.IsFalse(invalidValue.CheckIsNotNull());

            // Test Exception
            _ = Assert.ThrowsException <InvalidValueException <PersonProper> >(() => invalidValue.CheckIsNotNull(true));
        }
Beispiel #9
0
        public void AddIfNotExistsSingleItemTest()
        {
            var          people     = RandomData.GeneratePersonCollection <PersonProper>(10);
            PersonProper nullPerson = null;

            // TEST
            Assert.IsFalse(people.AddIfNotExists(nullPerson));

            var testPerson = RandomData.GeneratePerson <PersonProper>();

            Assert.IsTrue(people.AddIfNotExists(testPerson));

            Assert.IsFalse(people.AddIfNotExists(testPerson));
        }
Beispiel #10
0
        public void TryValidateNullTest()
        {
            PersonProper personProper = null;

            _ = Assert.ThrowsException <InvalidValueException <object> >(() => Validate.TryValidateNull(value: personProper, throwException: true));

            try
            {
                personProper = RandomData.GeneratePerson <PersonProper>();
                _            = Validate.TryValidateNull(personProper, throwException: true);
            }
            catch
            {
                Assert.Fail();
            }
        }
Beispiel #11
0
        public void ArgumentNotNullObjectWithDefaultTest()
        {
            PersonProper nullPerson    = null;
            var          defaultPerson = RandomData.GenerateRefPerson <PersonProper>();

            try
            {
                var result = nullPerson.ArgumentNotNull(defaultPerson);

                Assert.AreEqual(result, defaultPerson);
            }
            catch
            {
                Assert.Fail();
            }
        }
        public void GetOrAddTest()
        {
            var          people     = RandomData.GeneratePersonCollection <PersonProper>(10).ToDictionary(p => p.Id);
            var          newPerson  = RandomData.GeneratePerson <PersonProper>();
            PersonProper nullPerson = null;

            // Test Parameters
            _ = Assert.ThrowsException <ArgumentNullException>(() => people.GetOrAdd(null, newPerson));
            _ = Assert.ThrowsException <ArgumentNullException>(() => people.GetOrAdd(newPerson.Id, nullPerson));

            // TEST
            _ = people.GetOrAdd(newPerson.Id, newPerson);
            Assert.IsTrue(people.Count == 11);

            _ = people.GetOrAdd(newPerson.Id, newPerson);
            Assert.IsTrue(people.Count == 11);
        }
        public void AddIfNotExistsSingleItemTest()
        {
            var          people     = RandomData.GeneratePersonCollection <PersonProper>(10);
            PersonProper nullPerson = null;

            // Test Parameters
            _ = Assert.ThrowsException <ArgumentReadOnlyException>(() => people.AsReadOnly().AddIfNotExists(RandomData.GeneratePerson <PersonProper>()));

            // TEST
            Assert.IsFalse(people.AddIfNotExists(nullPerson));

            var testPerson = RandomData.GeneratePerson <PersonProper>();

            Assert.IsTrue(people.AddIfNotExists(testPerson));

            Assert.IsFalse(people.AddIfNotExists(testPerson));
        }
Beispiel #14
0
        public void ArgumentNotNullObjectTest()
        {
            var testPerson = RandomData.GenerateRefPerson <PersonProper>();

            try
            {
                testPerson.ArgumentNotNull();
            }
            catch
            {
                Assert.Fail();
            }

            PersonProper nullPerson = null;

            _ = Assert.ThrowsException <ArgumentNullException>(() => nullPerson.ArgumentNotNull());
        }
Beispiel #15
0
        public void AddIfNotExistsComparerTest()
        {
            var                  people       = RandomData.GeneratePersonCollection <PersonProper>(10);
            var                  person       = RandomData.GeneratePerson <PersonProper>();
            PersonProper         nullPerson   = null;
            var                  comparer     = new PersonProperComparer();
            PersonProperComparer nullComparer = null;

            // Test Parameters
            _ = Assert.ThrowsException <ArgumentException>(() => people.AsReadOnly().AddIfNotExists(person, nullComparer));
            _ = Assert.ThrowsException <ArgumentNullException>(() => people.AddIfNotExists(nullPerson, comparer));
            _ = Assert.ThrowsException <ArgumentException>(() => people.ToReadOnlyCollection().AddIfNotExists(person, comparer));

            // TEST
            people.AddIfNotExists(person, comparer);
            Assert.IsTrue(people.Count == 11);

            people.AddIfNotExists(person, comparer);
            Assert.IsTrue(people.Count == 11);
        }
        public void AddIfNotExists()
        {
            var                  people       = RandomData.GeneratePersonRefCollection <PersonProper>(10);
            var                  person       = RandomData.GenerateRefPerson <PersonProper>();
            PersonProper         nullPerson   = null;
            var                  comparer     = new PersonProperComparer();
            PersonProperComparer nullComparer = null;
            List <PersonProper>  nullList     = null;

            // TEST
            Assert.IsFalse(people.AddIfNotExists(nullPerson));

            Assert.ThrowsException <ArgumentNullException>(() => _ = nullList.AddIfNotExists(person));

            Assert.IsFalse(people.AddIfNotExists(nullPerson, nullComparer));

            Assert.IsTrue(people.AddIfNotExists(person));

            Assert.IsFalse(people.AddIfNotExists(nullPerson));

            Assert.IsTrue(people.AddIfNotExists(RandomData.GenerateRefPerson <PersonProper>(), comparer));

            Assert.IsFalse(people.AddIfNotExists(nullPerson, comparer));
        }
        public override void Setup()
        {
            base.Setup();

            this._personProper = RandomData.GeneratePerson <PersonProper>();
        }