Exemple #1
0
        public void InvalidEOF()
        {
            var test = Encoding.UTF8.GetBytes(
                @"-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""field1""

value 1
-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""field2""

value 2--
");
            string boundary = null;

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Invalid EOF!");
            }
            catch (Exception e)
            {
                Conout.Write(e.ToMessageWithType());
                Aver.IsTrue(e.Message.Contains(StringConsts.MULTIPART_TERMINATOR_ISNT_FOUND_ERROR));
            }
        }
Exemple #2
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");
        }
Exemple #3
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);
        }
Exemple #4
0
        public void DuplicatedNames()
        {
            var test = Encoding.UTF8.GetBytes(
                @"-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""name""

value 1
-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""name""

value 2
-----------------------------7de23d3b1d07fe--
");
            string boundary = null;

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Repeated name!");
            }
            catch (Exception e)
            {
                Conout.Write(e.ToMessageWithType());
                Aver.IsTrue(e.Message.Contains("is already registered."));
            }
        }
Exemple #5
0
        public void InvalidBoundaryFromOutside()
        {
            var test = Encoding.UTF8.GetBytes(
                @"--7de23d3b1d07fe
Content-Disposition: form-data; name=""name1""

value 1
--7de23d3b1d07fe
Content-Disposition: form-data; name=""name2""

value 2
--7de23d3b1d07fe--
");
            string boundary = "8asd56sge";

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Invalid explicit boundary");
            }
            catch (Exception ex)
            {
                Conout.Write(ex.ToMessageWithType());
                Aver.IsTrue(ex.Message.Contains(StringConsts.MULTIPART_SPECIFIED_BOUNDARY_ISNT_FOUND_ERROR));
            }
        }
        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());
        }
Exemple #7
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);
        }
Exemple #8
0
 public void TryCreatePart_NullName()
 {
     try
     {
         var part = new Multipart.Part(null);
         Aver.Fail("Invalid name!");
     }
     catch (Exception e)
     {
         Conout.Write(e.ToMessageWithType());
         Aver.IsTrue(e.Message.Contains(StringConsts.MULTIPART_PART_EMPTY_NAME_ERROR));
     }
 }
Exemple #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);
        }
Exemple #10
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);
        }
Exemple #11
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);
        }
Exemple #12
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);
        }
        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());
        }
        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());
        }
Exemple #15
0
 public void TryCreateMultipart_NullParts()
 {
     try
     {
         var part = new Multipart(null);
         Aver.Fail("Invalid parts!");
     }
     catch (Exception e)
     {
         Conout.Write(e.ToMessageWithType());
         Aver.IsTrue(e.Message.Contains(StringConsts.MULTIPART_PARTS_COULDNT_BE_EMPTY_ERROR));
     }
 }
Exemple #16
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);
        }
Exemple #17
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");
 }
 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);
 }
        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());
        }
Exemple #20
0
        public void Perf(int cnt)
        {
            var got = JsonReader.ToDoc <DocWithArray>(JSON1);
            var sw  = System.Diagnostics.Stopwatch.StartNew();

            System.Threading.Tasks.Parallel.For(0, cnt, i => //  for (var i=0; i<cnt; i++)
            {
                got = JsonReader.ToDoc <DocWithArray>(JSON1);
                Aver.IsNotNull(got);
            });

            var el = sw.ElapsedMilliseconds;

            Conout.SeeArgs("Did {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(cnt, el, cnt / (el / 1000d)));
        }
Exemple #21
0
        public void EmptyPart()
        {
            var test = Encoding.UTF8.GetBytes(
                @"-----------------------------7de23d3b1d07fe
-----------------------------7de23d3b1d07fe--
");
            string boundary = null;

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Empty part!");
            }
            catch (Exception e)
            {
                Conout.Write(e.ToMessageWithType());
                Aver.IsTrue(e.Message.Contains(StringConsts.MULTIPART_PART_COULDNT_BE_EMPTY_ERROR));
            }
        }
Exemple #22
0
        public void InvalidEOL()
        {
            var test = Encoding.UTF8.GetBytes(
                @"-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""name""

value-----------------------------7de23d3b1d07fe--
");
            string boundary = null;

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Invalid end of part!");
            }
            catch (Exception e)
            {
                Conout.Write(e.ToMessageWithType());
                Aver.IsTrue(e.Message.Contains(StringConsts.MULTIPART_PART_MUST_BE_ENDED_WITH_EOL_ERROR));
            }
        }
Exemple #23
0
        public void NoDoubleEOLAfterHeader()
        {
            var test = Encoding.UTF8.GetBytes(
                @"-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""name""
value
-----------------------------7de23d3b1d07fe--
");
            string boundary = null;

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("No double EOL after header!");
            }
            catch (Exception e)
            {
                Conout.Write(e.ToMessageWithType());
                Aver.IsTrue(e.Message.Contains(StringConsts.MULTIPART_DOUBLE_EOL_ISNT_FOUND_AFTER_HEADER_ERROR));
            }
        }
Exemple #24
0
        public void EmptyName()
        {
            var test = Encoding.UTF8.GetBytes(
                @"-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""""

value
-----------------------------7de23d3b1d07fe--
");
            string boundary = null;

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Empty name!");
            }
            catch (Exception e)
            {
                Conout.Write(e.ToMessageWithType());
                Aver.IsTrue(e.Message.Contains(StringConsts.MULTIPART_PART_EMPTY_NAME_ERROR));
            }
        }
Exemple #25
0
        public void TooShortBoundary()
        {
            var test = Encoding.UTF8.GetBytes(
                @"--
Content-Disposition: form-data; name=""name""

value 1
----
");
            string boundary = null;

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Invalid boundary");
            }
            catch (Exception e)
            {
                Conout.Write(e.ToMessageWithType());
                Aver.IsTrue(e.Message.Contains(StringConsts.MULTIPART_BOUNDARY_IS_TOO_SHORT));
            }
        }
Exemple #26
0
        public void FullBoundaryNotStartWithHyphens()
        {
            var test = Encoding.UTF8.GetBytes(
                @"7de23d3b1d07fe
Content-Disposition: form-data; name=""name""

value 1
7de23d3b1d07fe--
");
            string boundary = null;

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Invalid boundary");
            }
            catch (Exception e)
            {
                Conout.Write(e.ToMessageWithType());
                Aver.IsTrue(e.Message.Contains(StringConsts.MULTIPART_BOUNDARY_SHOULD_START_WITH_HYPHENS));
            }
        }