예제 #1
0
        public void SetCountLimit_Throw()
        {
            var sut = new CappedQueue <MyItem>(i => i == null ? 0 : i.Name == null ? 0 : i.Name.Length);

            sut.CountLimit = 3;
            sut.Handling   = QueueLimitHandling.Throw;

            Aver.IsTrue(sut.TryEnqueue(new MyItem {
                Name = "Cat"
            }));
            Aver.AreEqual(1, sut.Count);

            Aver.IsTrue(sut.TryEnqueue(new MyItem {
                Name = "Dog"
            }));
            Aver.AreEqual(2, sut.Count);

            Aver.IsTrue(sut.TryEnqueue(null));
            Aver.AreEqual(3, sut.Count);

            try
            {
                //Rabbit will not fit - will throw
                Aver.IsFalse(sut.TryEnqueue(new MyItem {
                    Name = "Rabbit"
                }));
            }
            catch (AzosException error)
            {
                Aver.IsTrue(error.Message.Contains("limit is reached"));
                Conout.WriteLine("Expected and got: " + error.ToMessageWithType());
                return;
            }
            Aver.Fail("No expected exception");
        }
예제 #2
0
        public void SeeConsoleDump()
        {
            Conout.NewLine();
            Conout.Write("A"); Conout.Write("B");
            Conout.WriteLine();
            Conout.WriteLine("This is on another line");
            "This is on another line".In("general_info").WriteLine();


            "Message without parameters".See();
            "Message with parameter {0}".SeeArgs(1);
            "".SeeArgs(1, 2, 3, 4, 5);

            new { x = 10 }.In("objects").See();
            new { x = 10 }.In("objects").See("Header is shown in 'objects'");
            "Name is: {0}".In("people").SeeArgs("Jack");

            new { a = 1, b = 2 }.See();
            new { a = 1, b = 2 }.See("With header");
            new [] { 1, 2, 3 }.See();
            "Info text".Info();
            "Info text line".Info(5);

            "Warning text".Warning();
            "Warning text line".Warning(5);

            "Error text".Error();
            "Error text line".Error(5);
        }
        public void TryMany(bool p, int cnt, int block, int delay)
        {
            var lst = new List <GDID>();

            void body()
            {
                var gdids = m_Gen.TryGenerateManyConsecutiveGdids("scopeA", "seqA", block);

                if (!p)
                {
                    gdids.See($"Size is: {gdids.Length}");
                }
                lock (lst) lst.AddRange(gdids);
                if (!p)
                {
                    m_Gen.GetSequenceInfos("scopeA").See();
                }
                if (!p)
                {
                    Conout.WriteLine("--------------------------------------");
                }
                System.Threading.Thread.Sleep(delay);
                var gdid = m_Gen.GenerateOneGdid("scopeA", "seqA");

                lock (lst) lst.Add(gdid);
                if (!p)
                {
                    gdid.See();
                }
            }

            if (p)
            {
                Parallel.For(0, cnt, i => body());
            }
            else
            {
                for (var i = 0; i < cnt; i++)
                {
                    body();
                }
            }

            Conout.WriteLine("--------------------------------------");
            Conout.WriteLine("--------------------------------------");
            var gdid2 = m_Gen.GenerateOneGdid("scopeA", "seqA");

            lst.Add(gdid2);
            gdid2.See();
            m_Gen.GetSequenceInfos("scopeA").See();

            "Total: {0}".SeeArgs(lst.Count);
            Aver.AreEqual(lst.Count, lst.Distinct().Count());
        }
예제 #4
0
        public void TypedDoc_6()
        {
            var doc = new Doc1 {
                Field3 = "I can not be here"
            };                                            //NOT In list
            var ve = doc.Validate() as FieldValidationException;

            Aver.IsNotNull(ve);
            Conout.WriteLine(ve.ToMessageWithType());
            Aver.AreEqual("Field3", ve.FieldName);
            doc.Field3 = "n";//'Nancy' obtained from dynamic imperative call
            Aver.IsNull(doc.Validate());
        }
예제 #5
0
        public void TypedDoc_4()
        {
            var doc = new Doc1 {
                Field1 = "Z"
            };                            //NOT In list
            var ve = doc.Validate() as FieldValidationException;

            Aver.IsNotNull(ve);
            Conout.WriteLine(ve.ToMessageWithType());
            Aver.AreEqual("Field1", ve.FieldName);
            doc.Field1 = "c";
            Aver.IsNull(doc.Validate());
        }
예제 #6
0
        public void FromDecimalString_Distance_MOSCOW_CLE()
        {
            var cleveland = new LatLng("41.4868145,-81.6406292");
            var moscow    = new LatLng("55.7530361,37.6217305");

            Conout.WriteLine(cleveland);
            Conout.WriteLine(moscow);

            var dist = moscow.HaversineEarthDistanceKm(cleveland);

            Conout.WriteLine(dist);
            Aver.AreEqual(7786, (int)dist);
        }
예제 #7
0
        public void FromDegreeString_Distance_CLE_LA()
        {
            var cleveland  = new LatLng("41°29'13'', -81°38'26''");
            var losangeles = new LatLng("34°9'40'', -117°56'48''");

            Conout.WriteLine(cleveland);
            Conout.WriteLine(losangeles);

            var dist = cleveland.HaversineEarthDistanceKm(losangeles);

            Conout.WriteLine(dist);
            Aver.AreEqual(3265, (int)dist);
        }
예제 #8
0
        public void FromDecimalString_Distance_LA_CLE()
        {
            var cleveland  = new LatLng("41.4868145,-81.6406292");
            var losangeles = new LatLng("34.1610243,-117.9465513");

            Conout.WriteLine(cleveland);
            Conout.WriteLine(losangeles);

            var dist = losangeles.HaversineEarthDistanceKm(cleveland);

            Conout.WriteLine(dist);
            Aver.AreEqual(3265, (int)dist);
        }
예제 #9
0
        public void FromDegreeString_Distance_CLE_MELBOURNE()
        {
            var cleveland = new LatLng("41°29'13'', -81°38'26''");
            var melbourne = new LatLng("-37°31'16'', 144°44'46''");

            Conout.WriteLine(cleveland);
            Conout.WriteLine(melbourne);

            var dist = cleveland.HaversineEarthDistanceKm(melbourne);

            Conout.WriteLine(dist);
            Aver.AreEqual(16058, (int)dist);
        }
예제 #10
0
        public void FromDecimalString_Distance_CLE_MELBOURNE()
        {
            var cleveland = new LatLng("41.4868145,-81.6406292");
            var melbourne = new LatLng("-37.5210205,144.7461265");

            Conout.WriteLine(cleveland);
            Conout.WriteLine(melbourne);

            var dist = cleveland.HaversineEarthDistanceKm(melbourne);

            Conout.WriteLine(dist);
            Aver.AreEqual(16058, (int)dist);
        }
예제 #11
0
        public void FromDegreeString_Distance_CLE_MOSCOW()
        {
            var cleveland = new LatLng("41°29'13'', -81°38'26''");
            var moscow    = new LatLng("55°45'11'', 37°37'18''");

            Conout.WriteLine(cleveland);
            Conout.WriteLine(moscow);

            var dist = cleveland.HaversineEarthDistanceKm(moscow);

            Conout.WriteLine(dist);
            Aver.AreEqual(7786, (int)dist);
        }
예제 #12
0
 public void BadRefNotExists()
 {
     try
     {
         var schema = Schema.GetForTypedDoc <Bad_RefNotExistsDoc>();
     }
     catch (Exception error)
     {
         Conout.WriteLine("Expected and got: " + error.ToMessageWithType());
         Aver.IsNotNull(error.InnerException);
         Aver.IsTrue(error.InnerException.Message.Contains("no matching"));
         return;
     }
     Aver.Fail("Did not get expected exception");
 }
예제 #13
0
        public void OneByOne(int cnt)
        {
            var lst = new List <GDID>();

            for (var i = 0; i < cnt; i++)
            {
                var gdid = m_Gen.GenerateOneGdid("scopeA", "seqA");
                lst.Add(gdid);
                gdid.See();
                m_Gen.GetSequenceInfos("scopeA").See();
                Conout.WriteLine("--------------------------------------");
                System.Threading.Thread.Sleep(1000);
            }
            Aver.AreEqual(lst.Count, lst.Distinct().Count());
        }
예제 #14
0
 public void BadRecursion()
 {
     try
     {
         var schema = Schema.GetForTypedDoc <Bad_RecurseDoc>();
     }
     catch (Exception error)
     {
         Conout.WriteLine("Expected and got: " + error.ToMessageWithType());
         Aver.IsNotNull(error.InnerException);
         Aver.IsTrue(error.InnerException.Message.Contains("Cyclical"));
         return;
     }
     Aver.Fail(Constants.ERR_NOT_THROWN);
 }