Exemple #1
0
        public void GeneratePersonTest()
        {
            var person = RandomData.GenerateRefPerson <Models.RefTypes.Person>();

            Assert.IsNotNull(person);

            Assert.IsNotNull(person.Address1);

            Assert.IsNotNull(person.Address2);

            Assert.IsTrue(person.BornOn > DateTimeOffset.Parse("1/1/1800"));

            Assert.IsNotNull(person.CellPhone);

            Assert.IsNotNull(person.City);

            Assert.IsNotNull(person.Country);

            Assert.IsNotNull(person.Email);

            Assert.IsNotNull(person.FirstName);

            Assert.IsNotNull(person.HomePhone);

            Assert.IsNotNull(person.Id);

            Assert.IsNotNull(person.LastName);

            Assert.IsNotNull(person.PostalCode);

            Assert.IsNotNull(person.ToString());
        }
        public void AddLastTest()
        {
            var          peopleList  = RandomData.GeneratePersonRefCollection <PersonProper>(10);
            var          peopleArray = peopleList.ToArray();
            var          person      = RandomData.GenerateRefPerson <PersonProper>();
            PersonProper nullPerson  = null;

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

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

            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);
        }
        public void GetTypeDisplayNameTest()
        {
            var person = RandomData.GenerateRefPerson <PersonProper>();

            var result = TypeHelper.GetTypeDisplayName(person);

            Assert.IsTrue(string.Compare(result, "DotNetTips.Spargine.Tester.Models.RefTypes.PersonProper", StringComparison.Ordinal) == 0);

            result = TypeHelper.GetTypeDisplayName(person, true);

            Assert.IsTrue(string.Compare(result, "DotNetTips.Spargine.Tester.Models.RefTypes.PersonProper", StringComparison.Ordinal) == 0);

            result = TypeHelper.GetTypeDisplayName(typeof(int), true, true, true, '-');

            Assert.IsTrue(string.Compare(result, "int", StringComparison.Ordinal) == 0);

            var people = RandomData.GeneratePersonRefCollection <PersonProper>(5);

            result = TypeHelper.GetTypeDisplayName(people);

            Assert.IsTrue(result.Length > 0);

            result = TypeHelper.GetTypeDisplayName(RandomData.GenerateRefPerson <Person>());

            Assert.IsTrue(result.Length > 0);
        }
        public void DoesObjectEqualInstance02()
        {
            var person     = RandomData.GenerateRefPerson <PersonProper>();
            var testPerson = RandomData.GenerateRefPerson <PersonProper>();

            Assert.IsFalse(TypeHelper.DoesObjectEqualInstance(person, testPerson));
        }
        public void FromJson01()
        {
            var person = RandomData.GenerateRefPerson <PersonProper>();
            var json   = person.ToJson();

            Assert.IsNotNull(TypeHelper.FromJson <PersonProper>(json));
        }
Exemple #6
0
        public void HasPropertyTest()
        {
            var person = RandomData.GenerateRefPerson <PersonProper>();

            Assert.IsTrue(person.HasProperty("Id"));

            Assert.IsFalse(person.HasProperty("XXXXXXXXXXXXX"));
        }
        public void GetPropertyValues01()
        {
            var person = RandomData.GenerateRefPerson <PersonProper>();

            var result = TypeHelper.GetPropertyValues(person);

            base.Consumer.Consume(result);
        }
        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();
        }
Exemple #9
0
        public void StripNullTest()
        {
            var          person     = RandomData.GenerateRefPerson <PersonProper>();
            PersonProper nullPerson = null;

            Assert.IsFalse(string.IsNullOrEmpty(person.StripNull()));
            Assert.IsTrue(string.IsNullOrEmpty(nullPerson.StripNull()));
        }
Exemple #10
0
        public void IsNumericTest()
        {
            var people = RandomData.GeneratePersonRefCollection <PersonProper>(10).AsEnumerable();
            var person = RandomData.GenerateRefPerson <PersonProper>();

            Assert.IsTrue(people.GetType().IsEnumerable());
            Assert.IsFalse(person.GetType().IsEnumerable());
        }
        public void AddTest()
        {
            var people = RandomData.GeneratePersonRefCollection <PersonProper>(10).ToArray();
            var person = RandomData.GenerateRefPerson <PersonProper>();

            var result = people.Add(person);

            Assert.IsTrue(result.FastCount() == 11);
        }
Exemple #12
0
        public void AddTest()
        {
            var people = new ConcurrentHashSet <PersonProper>(RandomData.GeneratePersonRefCollection <PersonProper>(100));

            var result = people.Add(RandomData.GenerateRefPerson <PersonProper>());

            Assert.IsTrue(result);
            Assert.IsTrue(people.Count == 101);
        }
Exemple #13
0
        public void PropertiesToStringTest()
        {
            var personRecord = RandomData.GeneratePersonRecordCollection(1).First();

            var propertiesTest = new PropertiesTest
            {
                Id           = RandomData.GenerateKey(),
                PersonProper = RandomData.GenerateRefPerson <PersonProper>(),
                PersonRecord = RandomData.GeneratePersonRecordCollection(1).First(),
                Today        = DateTimeOffset.Now,
                ClosedOn     = DateTimeOffset.Now,
            };

            var result = personRecord.PropertiesToString(
                header: "PersonRecord",
                keyValueSeparator: ':',
                sequenceSeparator: ", ",
                ignoreNulls: true);

            Assert.IsTrue(result.Length > 1300);
            Assert.IsTrue(result.Contains("Addresses"));
            PrintResult(result, nameof(this.PropertiesToStringTest));

            result = propertiesTest.PropertiesToString(
                header: "PersonRecord",
                keyValueSeparator: ':',
                sequenceSeparator: ", ",
                ignoreNulls: true,
                includeMemberName: false);

            Assert.IsTrue(result.Length > 1300);
            Assert.IsTrue(result.Contains("Addresses"));
            PrintResult(result, nameof(this.PropertiesToStringTest));

            var person = RandomData.GenerateRefPerson <PersonProper>();

            result = person.PropertiesToString(header: person.Id);

            Assert.IsTrue(result.Length > 500);
            Assert.IsTrue(result.Contains("Address1"));
            PrintResult(result, nameof(this.PropertiesToStringTest));

            var coordinate = RandomData.GenerateCoordinate <CoordinateProper>();

            result = coordinate.PropertiesToString();

            Assert.IsTrue(result.Length > 50);
            Assert.IsTrue(result.Contains("X"));
            PrintResult(result, nameof(this.PropertiesToStringTest));

            var personCollection = RandomData.GeneratePersonRecordCollection(5);

            result = personCollection.PropertiesToString();
            Assert.IsTrue(result.Contains("LastName"));
            Assert.IsTrue(result.Length > 6000);
        }
        public void AddIfTest()
        {
            var people = RandomData.GeneratePersonRefCollection <PersonProper>(10);
            var person = RandomData.GenerateRefPerson <PersonProper>();

            // TEST
            people.AddIf(person, people.FastCount() == 10);

            Assert.IsTrue(people.FastCount() == 11);
        }
        public void CountTest()
        {
            var result = InMemoryCache.Instance;

            var person = RandomData.GenerateRefPerson <PersonProper>();

            result.AddCacheItem(person.Id, person);

            Assert.IsTrue(result.Cache.Count == 1);
        }
Exemple #16
0
        public void ComputeSha256HashTest()
        {
            var person = RandomData.GenerateRefPerson <PersonProper>();

            var result = person.ComputeSha256Hash();

            PrintResult(result, nameof(this.ComputeSha256HashTest));

            Assert.IsFalse(string.IsNullOrEmpty(result));
        }
        public async Task WriteAsyncTest01()
        {
            var channel = new ChannelQueue <PersonProper>();
            var person  = RandomData.GenerateRefPerson <PersonProper>();
            var token   = CancellationToken.None;

            await channel.WriteAsync(person, cancellationToken : token).ConfigureAwait(false);

            Assert.IsTrue(channel.Count == 1);
        }
        public void StringToXDocumentTest()
        {
            var person = RandomData.GenerateRefPerson <PersonProper>();

            //Serialize
            var xml = XmlSerialization.Serialize(person);

            var result = XmlSerialization.StringToXDocument(xml);

            Assert.IsNotNull(result);
        }
Exemple #19
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));
        }
        public void FromJsonFile01()
        {
            var person   = RandomData.GenerateRefPerson <PersonProper>();
            var fileName = Path.Combine(App.ExecutingFolder(), "testjson.json");

            person.ToJsonFile(fileName);

            Assert.IsNotNull(TypeHelper.FromJsonFile <PersonProper>(fileName));

            File.Delete(fileName);
        }
        public void AddLastTest()
        {
            var people     = RandomData.GeneratePersonRefCollection <PersonProper>(10);
            var collection = Collection <PersonProper> .Create(people);

            var person = RandomData.GenerateRefPerson <PersonProper>();

            collection.AddLast(person);

            Assert.IsTrue(collection.Last() == person);
        }
Exemple #22
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());
        }
Exemple #23
0
        public void ContainsTest()
        {
            var people = new ConcurrentHashSet <PersonProper>(RandomData.GeneratePersonRefCollection <PersonProper>(100));
            var person = people.Shuffle(1).First();

            var result = people.Contains(person);

            Assert.IsTrue(result);

            Assert.IsFalse(people.Contains(RandomData.GenerateRefPerson <PersonProper>()));
        }
Exemple #24
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));
        }
Exemple #25
0
 public void IsNotNullCheckTest()
 {
     try
     {
         var personProper = RandomData.GenerateRefPerson <PersonProper>();
         personProper.CheckIsNotNull(throwException: true);
     }
     catch
     {
         Assert.Fail();
     }
 }
        public void GetCashedItemTest()
        {
            var result = InMemoryCache.Instance;

            var person = RandomData.GenerateRefPerson <PersonProper>();

            result.AddCacheItem(person.Id, person);

            var item = result.GetCacheItem <PersonProper>(person.Id);

            Assert.IsNotNull(item);
        }
Exemple #27
0
        public void ArgumentEqualsTest()
        {
            var person = RandomData.GenerateRefPerson <PersonProper>();

            //Good Test
            var result = person.GetType().ArgumentEquals(typeof(PersonProper));

            Assert.IsNotNull(result);

            //Bad test
            Assert.ThrowsException <ArgumentInvalidException>(() => typeof(PersonProper).ArgumentEquals(typeof(Person)));
        }
        public void FirstOrDefaultTest()
        {
            var people  = RandomData.GeneratePersonRefCollection <PersonProper>(10);
            var person1 = RandomData.GenerateRefPerson <PersonProper>();

            people.Add(person1);

            //Test Finding item in collection
            Assert.IsNotNull(people.FirstOrDefault(person1) == person1);
            Assert.IsNotNull(people.FirstOrDefault(p => p.Age.TotalDays > 100, person1).Equals(person1));
            Assert.IsNotNull(people.FirstOrDefault(p => p.Age.TotalDays > 50000, person1).Equals(person1));
        }
        public void ContainsAnyTest()
        {
            var people = RandomData.GeneratePersonRefCollection <PersonProper>(10).ToArray();
            var person = RandomData.GenerateRefPerson <PersonProper>();

            Assert.IsFalse(people.ContainsAny(person));

            Assert.IsTrue(people.ContainsAny(people.Last()));

            //PersonProper[] nullPerson = default;

            //Assert.IsFalse(people.ContainsAny(nullPerson));
        }
Exemple #30
0
        public void AddIfTest()
        {
            var people = RandomData.GeneratePersonRefCollection <PersonProper>(10).ToHashSet();
            var person = RandomData.GenerateRefPerson <PersonProper>();

            people.AddIf(person, true);

            Assert.IsTrue(people.FastCount() == 11);

            people.AddIf(person, false);

            Assert.IsTrue(people.FastCount() == 11);
        }