public void ErlParserMFAFailTest() { var tests = new Dictionary <string, object[]> { { "a:b(1,%comment\n", (object[])null }, { "a:b(1,%comment 2).", (object[])null }, { "(", (object[])null }, { ")", (object[])null }, { ".", (object[])null }, { "aa", (object[])null }, { "a(", (object[])null }, { "a:b(", (object[])null }, { "a.b()", (object[])null }, { "a:b(10 20)", (object[])null }, { "a:b(10. 20)", (object[])null }, { "a:b(10.(20)", (object[])null }, { "a:b(~w,~w)", new object[] { 10 } }, { "a:b([~w,20],~w)", new object[] { 10 } }, }; foreach (var t in tests) { Aver.Throws <ErlException>( () => ErlObject.ParseMFA(t.Key, t.Value), "Errorneously parsing term: {0}".Args(t.Key)); } }
public void TestGeoStrategy_SisterCities() { using (var app = new AzosApplication(null, BASE_CONF)) { //Get the binder which will make and bind strategy instances for the requested contract and context data var binder = app.ModuleRoot.Get <IStrategyBinder>(); //NOTICE: We allocate a different strategy context type (compare with the above test) var ctx = new GeoSisterContext { Location = new LatLng("41.500136,-81.7005492", "Cleveland") }; var got = binder.Bind <IGeoStrat, IGeoStratContext>(ctx); //We get LA strategy implementation, because LA is a sister city of Cleveland per GeoSisterContext Aver.IsTrue(got is LosAngelesStrat); Aver.AreEqual("LA California customers in Cleveland", got.RunStrategyWork()); //Now try Washington DC ctx.Location = new LatLng("38.9079407,-77.0355777", "Washington"); got = binder.Bind <IGeoStrat, IGeoStratContext>(ctx); //SF is a sister of Washington Aver.IsTrue(got is SanFranciscoStrat); Aver.AreEqual("San Francisco California customers in Washington", got.RunStrategyWork()); //Now Sacramento is going to throw because you cant bind it using this matching (no sister exists for it) ctx.Location = new LatLng("38.5755851,-121.4925168", "Sacramento"); //can't bind it Aver.Throws <AzosException>(() => binder.Bind <IGeoStrat, IGeoStratContext>(ctx)); } }
public void Laconic_09() { var conf = "root{ a{ b=null } }".AsLaconicConfig(); Aver.Throws <ConfigException>(() => conf.Navigate("!/a/$doesnotexist")); Aver.IsNull(conf.Navigate("!/a/$b").Value); }
public void Test_ModuleInjectionAndAccess() { using (var app = new AzosApplication(null, BASE_CONF)) { Aver.AreEqual(6, app.ModuleRoot.ChildModules.Count); var logic = app.ModuleRoot.TryGet <IMyLogic>("Module1"); Aver.IsNotNull(logic); Aver.AreEqual(1000, logic.Key); logic = app.ModuleRoot.TryGet <IMyLogic>("Module2"); Aver.IsNotNull(logic); Aver.AreEqual(2200, logic.Key); logic = app.ModuleRoot.TryGet <IMyLogic>("Module3"); Aver.IsNull(logic); logic = app.ModuleRoot.TryGet <IMyLogic>("Module4"); Aver.IsNotNull(logic); Aver.AreEqual(4000, logic.Key); logic = app.ModuleRoot.TryGet <IMyLogic>("s1"); Aver.IsNull(logic); Aver.Throws <AzosException>(() => app.ModuleRoot.Get <IMyLogic>("s1")); var svc = app.ModuleRoot.TryGet <IMyService>("s1"); Aver.IsNotNull(svc); Aver.IsTrue(svc is MyServiceA); svc = app.ModuleRoot.TryGet <IMyService>("s2"); Aver.IsNotNull(svc); Aver.IsTrue(svc is MyServiceB); } }
public void MulripleEnumerable() { var enumerator = "+-".AsLookAheadEnumerable().GetLookAheadEnumerator(); Aver.IsTrue(enumerator.HasNext); Aver.AreEqual(enumerator.Next, '+'); Aver.Throws <InvalidOperationException>(() => { var current = enumerator.Current; }); Aver.IsTrue(enumerator.MoveNext()); Aver.IsTrue(enumerator.HasNext); Aver.AreEqual(enumerator.Next, '-'); Aver.AreEqual(enumerator.Current, '+'); Aver.IsTrue(enumerator.MoveNext()); Aver.IsFalse(enumerator.HasNext); Aver.Throws <NFXException>(() => { var next = enumerator.Next; }, StringConsts.OPERATION_NOT_SUPPORTED_ERROR + "{0}.Next(!HasNext)".Args(typeof(LookAheadEnumerator <char>).FullName)); Aver.AreEqual(enumerator.Current, '-'); Aver.IsFalse(enumerator.MoveNext()); enumerator.Reset(); Aver.IsTrue(enumerator.HasNext); Aver.AreEqual(enumerator.Next, '+'); Aver.Throws <InvalidOperationException>(() => { var current = enumerator.Current; }); Aver.IsTrue(enumerator.MoveNext()); }
public void Laconic_Vars() { var cfg = @"root { v1=$(sub-1/$b) v2=$(sub-1/$c) v3=$(sub-1/[0]/a[800]/$message) v4=$($v44) v44=$(sub-1/$bad) v5=$(/$absent|$none|$v3|$never-existed) a=1 b=2 sub-1{ a=100 b=$(/$a) //1 c=$($a)$($b) //1001 sub-1-1=12345{ a=1{v=1} a=2{v=2} a=3{v=3} a=800{message=kuku}} bad=$(/$v44) } }".AsLaconicConfig(); Aver.AreEqual("1", cfg.AttrByName("v1").Value); Aver.AreEqual("1001", cfg.AttrByName("v2").Value); Aver.AreEqual("kuku", cfg.AttrByName("v3").Value); Aver.Throws <ConfigException>(() => { var hang = cfg.AttrByName("v4").Value; }); Aver.AreEqual("$($v44)", cfg.AttrByName("v4").VerbatimValue);//does not throw Aver.AreEqual("kuku", cfg.AttrByName("v5").Value); }
public void Laconic_Navigation() { var cfg = @"root{ a=1 b=2 sub-1{ a=100 b=true sub-1-1=12345{ a=1{v=1} a=2{v=2} a=3{v=3} a=800{message=kuku}} } }".AsLaconicConfig(); //Console.WriteLine(cfg.ToLaconicString()); Aver.AreEqual("root", cfg.Name); Aver.IsTrue(cfg["sub-1"].Exists); Aver.IsFalse(cfg["absent"].Exists); Aver.IsTrue(cfg["absent", "sub-1"].Exists); Aver.AreEqual("sub-1", cfg["sub-1"].Name); Aver.AreEqual("sub-1", cfg["pizza", "absent", "sub-1"].Name); Aver.AreEqual("sub-1", cfg["pizza", "sub-1", "absent"].Name); Aver.AreEqual("sub-1-1", cfg["pizza", "sub-1", "absent"]["none", "sub-1-1"].Name); Aver.IsFalse(cfg.Navigate("/absent").Exists); Aver.Throws <ConfigException>(() => cfg.Navigate("!/absent"));//! denotes requires path Aver.IsTrue(cfg.Navigate("/").Exists); Aver.AreEqual("root", cfg.Navigate("/").Name); Aver.AreEqual("root", cfg.Navigate("/").Name); Aver.IsTrue(cfg.Navigate("/absent;/").Exists); // /absent OR / Aver.IsTrue(cfg.Navigate("/absent|/").Exists); // /absent OR / Aver.IsTrue(cfg.Navigate("/absent ; /").Exists); // /absent OR / Aver.IsTrue(cfg.Navigate("/absent | /").Exists); // /absent OR / Aver.AreEqual("sub-1", cfg.Navigate("/sub-1").Name); Aver.AreEqual("sub-1", cfg.Navigate(" /sub-1").Name); Aver.AreEqual("sub-1", cfg.Navigate("/ sub-1").Name); Aver.IsFalse(cfg.Navigate("/ sub- 1").Exists); Aver.AreEqual("a", cfg.Navigate("/sub-1/sub-1-1/a").Name); Aver.AreEqual("1", cfg.Navigate("/sub-1/sub-1-1/a").Value); Aver.AreEqual("a", cfg.Navigate("/sub-1/sub-1-1/[1]").Name); Aver.AreEqual("2", cfg.Navigate("/sub-1/sub-1-1/[1]").Value); Aver.AreEqual("a", cfg.Navigate("/sub-1/sub-1-1/[2]").Name); Aver.AreEqual("3", cfg.Navigate("/sub-1/sub-1-1/[2]").Value); Aver.AreEqual("3", cfg.Navigate("/sub-1/sub-1-1/a[3]").Value); //a section with value 3 Aver.AreEqual("800", cfg.Navigate("/sub-1/sub-1-1/a[message=kuku]").Value); //a section with attribute message="kuku" Aver.AreEqual("12345", cfg.Navigate("/sub-z;/sub-1/hhh;/sub-1/sub-1-1;/").Value); //coalescing Aver.AreEqual("2", cfg.Navigate("/sub-1/sub-1-1/a/../ .. /../$b").Value);//../$attribute }
public void ErlBinaryTest() { { var tt = new byte[] { 10, 11, 12 }; var t1 = new ErlBinary(tt, false); tt[0] = 20; Aver.AreEqual(20, t1.Value[0]); var bb = new byte[] { 10, 11, 12 }; var t2 = new ErlBinary(bb); bb[0] = 20; Aver.AreEqual(10, t2.Value[0]); } var tb = new byte[] { 1, 2, 3 }; var t = new ErlBinary(tb); Aver.IsTrue(t.Equals(new ErlBinary(new byte[] { 1, 2, 3 }))); Aver.AreObjectsEqual(t, new ErlBinary(tb)); Aver.IsTrue(new ErlBinary(new byte[] { 1, 2 }).CompareTo(t) < 0); Aver.IsTrue(tb.MemBufferEquals(t.Value)); Aver.IsTrue(t.ValueAsBool); Aver.IsFalse(new ErlBinary(new byte[] { }).ValueAsBool); Aver.AreEqual("<<1,2,3>>", t.ToString()); Aver.AreEqual("<<1,2,3>>", t.ToBinaryString()); Aver.IsFalse(t.IsScalar); Aver.IsTrue(ErlTypeOrder.ErlBinary == t.TypeOrder); var bbb = new ErlBinary(new byte[] { 97, 98, 99, 10, 49, 50, 51 }); Aver.AreEqual("<<\"abc\n123\">>", bbb.ToString()); Aver.AreEqual("<<\"abc\n123\">>", bbb.ToPrintableString()); Aver.AreEqual("<<\"abc...\">>", bbb.ToPrintableString(6)); Aver.AreEqual("<<97,98,99,10,49,50,51>>", bbb.ToBinaryString()); Aver.AreEqual("<<97,98...>>", bbb.ToBinaryString(10)); Aver.IsTrue(t.Matches(new ErlBinary(new byte[] { 1, 2, 3 }))); Aver.IsTrue(new ErlVarBind().SequenceEqual(t.Match(new ErlBinary(new byte[] { 1, 2, 3 })))); doesNotThrow(() => { var x = t.ValueAsObject; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsInt; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsLong; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDecimal; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDateTime; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsTimeSpan; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDouble; }); doesNotThrow(() => { var x = t.ValueAsString; }); doesNotThrow(() => { var x = t.ValueAsBool; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsChar; }); doesNotThrow(() => { var x = t.ValueAsByteArray; }); IErlObject temp = null; Aver.IsFalse(t.Subst(ref temp, new ErlVarBind())); Aver.AreEqual(3, t.Visit(0, (acc, o) => acc + ((ErlBinary)o).Length)); byte[] b = t; Aver.IsTrue(tb.MemBufferEquals(b)); }
public void Nullable_NonNull() { int?x = 123; Aver.AreEqual(123, x.NonNull()); x = null; Aver.Throws <CallGuardException>(() => x.NonNull()); }
public void NonNull() { object x = 1; Aver.AreEqual(1, (int)(x.NonNull())); x = null; Aver.Throws <CallGuardException>(() => x.NonNull()); }
public void NonBlank() { string x = "abc"; Aver.AreEqual("abc", x.NonBlank()); x = null; Aver.Throws <CallGuardException>(() => x.NonBlank()); }
public void MinMaxTest() { Aver.AreEqual(1, IntMath.MinMax(-1, 1, 3)); Aver.AreEqual(2, IntMath.MinMax(2, 2, 3)); Aver.AreEqual(3, IntMath.MinMax(2, 3, 3)); Aver.AreEqual(-1, IntMath.MinMax(-1, -10, 3)); Aver.AreEqual(3, IntMath.MinMax(-1, 5, 3)); Aver.Throws <NFXException>(() => IntMath.MinMax(10, 5, 3)); }
public void NonBlankMin() { string x = "abc"; Aver.AreEqual("abc", x.NonBlankMin(3)); Aver.Throws <AzosException>(() => x.NonBlankMin(4)); x = null; Aver.Throws <AzosException>(() => x.NonBlankMin(4)); }
public void Uri() { Aver.IsNull(new { _ = "" }.AsUri()); Aver.Throws <AzosException>(() => Azos.Data.GDID.Zero.AsUri(handling: ConvertErrorHandling.Throw), "GDID.AsUri"); object obj = "https://example.com"; Aver.AreObjectsEqual(new Uri("https://example.com"), obj.AsUri()); }
public void EmptyEnumerable_AsEnumerable() { var enumerator = string.Empty.AsLookAheadEnumerable().GetEnumerator(); Aver.Throws <InvalidOperationException>(() => { var current = enumerator.Current; }); Aver.IsFalse(enumerator.MoveNext()); }
public void T7() { var arr = new byte[] { 1, 2, 3, 4, 5 }; var s = new BufferSegmentReadingStream(); Aver.Throws <AzosIOException>(() => s.BindBuffer(arr, 22, 3)); Aver.Throws <AzosIOException>(() => s.BindBuffer(arr, 0, 23)); Aver.Throws <AzosIOException>(() => s.BindBuffer(arr, -1, 1)); Aver.Throws <AzosIOException>(() => s.BindBuffer(arr, 0, -1)); }
public void NonBlankMinMax() { string x = "abc"; Aver.AreEqual("abc", x.NonBlankMinMax(1, 3)); Aver.Throws <CallGuardException>(() => x.NonBlankMinMax(4, 64)); Aver.Throws <CallGuardException>(() => x.NonBlankMinMax(1, 2)); x = null; Aver.Throws <CallGuardException>(() => x.NonBlankMinMax(1, 4)); }
public void ErlRefTest() { var ids = new int[] { 5, 6, 7 }; var t = new ErlRef("test", 5, 6, 7, 1); var t1 = new ErlRef("test", ids, 1); Aver.AreObjectsEqual(t, t1); Aver.IsTrue(t.Equals(new ErlRef("test", ids, 1))); Aver.AreObjectsEqual(t, new ErlRef("test", ids, 1)); Aver.AreEqual(1, new ErlRef("tesu", new int[] { 5, 6, 7 }, 1).CompareTo(t)); Aver.AreEqual(-1, new ErlRef("tess", new int[] { 5, 6, 7 }, 1).CompareTo(t)); Aver.AreEqual(-1, new ErlRef("test", new int[] { 4, 6, 7 }, 1).CompareTo(t)); Aver.AreEqual(1, new ErlRef("test", new int[] { 8, 6, 7 }, 1).CompareTo(t)); Aver.AreEqual(-1, new ErlRef("test", new int[] { 5, 4, 7 }, 1).CompareTo(t)); Aver.AreEqual(1, new ErlRef("test", new int[] { 5, 8, 7 }, 1).CompareTo(t)); Aver.AreEqual(-1, new ErlRef("test", new int[] { 5, 6, 4 }, 1).CompareTo(t)); Aver.AreEqual(1, new ErlRef("test", new int[] { 5, 6, 9 }, 1).CompareTo(t)); Aver.AreEqual(-1, new ErlRef("test", new int[] { 5, 6, 7 }, 0).CompareTo(t)); Aver.AreEqual(1, new ErlRef("test", new int[] { 5, 6, 7 }, 2).CompareTo(t)); Aver.AreEqual("#Ref<test.5.6.7.1>", t.ToString()); Aver.AreEqual("#Ref<test.5.6.7.1>", t.ValueAsString); Aver.IsTrue(t.IsScalar); Aver.IsTrue(ErlTypeOrder.ErlRef == t.TypeOrder); Aver.IsTrue(t.Matches(t1)); Aver.IsTrue(new ErlVarBind().SequenceEqual(t.Match(t1))); doesNotThrow(() => { var x = t.ValueAsObject; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsInt; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsLong; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDecimal; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDateTime; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsTimeSpan; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDouble; }); Aver.AreEqual("#Ref<test.5.6.7.1>", t.ValueAsString); var r = ErlRef.Parse("#Ref<test.5.6.7.1>"); Aver.AreObjectsEqual(new ErlAtom("test"), r.Node); Aver.IsTrue(5 == r.Ids[0]); Aver.IsTrue(6 == r.Ids[1]); Aver.IsTrue(7 == r.Ids[2]); Aver.IsTrue(1 == r.Creation); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsBool; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsChar; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsByteArray; }); IErlObject temp = null; Aver.IsFalse(t.Subst(ref temp, new ErlVarBind())); Aver.IsTrue(t.Visit(false, (acc, o) => acc |= o is ErlRef)); }
public void IsValid() { var x = new Atom(0); Aver.IsTrue(x.IsZero); Aver.IsTrue(x.IsValid); x = new Atom(0xffff); Aver.IsFalse(x.IsValid); Aver.Throws <AzosException>(() => x.Value.ToLower()); }
public void ErlPidTest() { var t = new ErlPid("test", 10, 3, 1); Aver.AreEqual("test", t.Node.Value); Aver.IsTrue(t.Equals(new ErlPid("test", 10, 3, 1))); Aver.AreObjectsEqual(t, new ErlPid("test", 10, 3, 1)); Aver.AreEqual(1, new ErlPid("tesu", 10, 3, 1).CompareTo(t)); Aver.AreEqual(-1, new ErlPid("tess", 10, 3, 1).CompareTo(t)); Aver.AreEqual(-1, new ErlPid("test", 9, 3, 1).CompareTo(t)); Aver.AreEqual(1, new ErlPid("test", 12, 4, 1).CompareTo(t)); Aver.AreEqual(-1, new ErlPid("test", 10, 2, 1).CompareTo(t)); Aver.AreEqual(1, new ErlPid("test", 10, 4, 1).CompareTo(t)); Aver.AreEqual(-1, new ErlPid("test", 10, 3, 0).CompareTo(t)); Aver.AreEqual(1, new ErlPid("test", 10, 3, 2).CompareTo(t)); Aver.AreEqual("#Pid<test.10.3.1>", t.ToString()); Aver.AreEqual("#Pid<test.10.3.1>", t.ValueAsString); Aver.IsTrue(t.IsScalar); Aver.IsTrue(ErlTypeOrder.ErlPid == t.TypeOrder); Aver.IsTrue(t.Matches(new ErlPid("test", 10, 3, 1))); Aver.IsTrue(new ErlVarBind().SequenceEqual(t.Match(new ErlPid("test", 10, 3, 1)))); doesNotThrow(() => { var x = t.ValueAsObject; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsInt; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsLong; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDecimal; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDateTime; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsTimeSpan; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDouble; }); Aver.AreEqual("#Pid<test.10.3.1>", t.ValueAsString); var r = ErlPid.Parse("#Pid<test.10.3.1>"); Aver.AreObjectsEqual(new ErlAtom("test"), r.Node); Aver.AreEqual(10, r.Id); Aver.AreEqual(3, r.Serial); Aver.AreEqual(1, r.Creation); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsBool; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsChar; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsByteArray; }); Aver.IsTrue(new ErlPid("test", 0, 0, 0).Empty); IErlObject temp = null; Aver.IsFalse(t.Subst(ref temp, new ErlVarBind())); Aver.AreEqual(true, t.Visit(false, (acc, o) => acc |= o is ErlPid)); }
public void EmptyEnumerable() { var enumerator = string.Empty.AsLookAheadEnumerable().GetLookAheadEnumerator(); Aver.IsFalse(enumerator.HasNext); Aver.Throws <NFXException>(() => { var next = enumerator.Next; }, StringConsts.OPERATION_NOT_SUPPORTED_ERROR + "{0}.Next(!HasNext)".Args(typeof(LookAheadEnumerator <char>).FullName)); Aver.Throws <InvalidOperationException>(() => { var current = enumerator.Current; }); Aver.IsFalse(enumerator.MoveNext()); }
public void ErlLongTest() { var t = new ErlLong(10); Aver.IsTrue(t.Equals(new ErlLong(10))); Aver.AreObjectsEqual(t, new ErlLong(10)); Aver.AreEqual(-1, new ErlAtom("ok").CompareTo(t)); Aver.IsTrue(10 == t); Aver.IsTrue((byte)10 == t); Aver.IsTrue((long)10 == t); Aver.AreEqual(10, t.Value); Aver.AreEqual(10, t.ValueAsInt); Aver.AreEqual(10, t.ValueAsLong); Aver.AreEqual("10", t.ToString()); Aver.IsTrue(t.IsScalar); Aver.IsTrue(ErlTypeOrder.ErlLong == t.TypeOrder); Aver.IsTrue(t.Matches(new ErlLong(10))); Aver.IsTrue(new ErlVarBind().SequenceEqual(t.Match(new ErlLong(10)))); doesNotThrow(() => { var x = t.ValueAsObject; }); Aver.AreEqual(10, t.ValueAsInt); Aver.AreEqual(10, t.ValueAsLong); Aver.AreEqual(10, t.ValueAsDecimal); Aver.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0) + new TimeSpan(10 * 10), t.ValueAsDateTime); Aver.AreEqual(new TimeSpan(0, 0, 10), t.ValueAsTimeSpan); Aver.AreEqual(10.0, t.ValueAsDouble); Aver.AreEqual("10", t.ValueAsString); Aver.AreEqual(true, t.ValueAsBool); Aver.AreEqual('\n', t.ValueAsChar); Aver.Throws <ErlException>(() => { var x = new ErlLong(256).ValueAsChar; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsByteArray; }); IErlObject temp = null; Aver.IsFalse(t.Subst(ref temp, new ErlVarBind())); Aver.AreEqual(10, t.Visit(0, (acc, o) => acc + o.ValueAsInt)); int n = (int)t; Aver.AreEqual(10, n); long m = t; Aver.AreEqual(10, m); ErlLong a = 100; // Implicit conversion Aver.AreEqual(100, a.Value); Aver.AreObjectsEqual(new ErlByte(127), new ErlLong(127)); Aver.AreObjectsEqual(new ErlByte(255), new ErlLong(255)); Aver.AreObjectsEqual(new ErlByte(0), new ErlLong(0)); }
public void ErlByteTest() { var t = new ErlByte(10); Aver.IsTrue(t.Equals(new ErlByte(10))); Aver.AreObjectsEqual(t, new ErlByte(10)); Aver.IsTrue(new ErlByte(1).CompareTo(t) < 0); Aver.AreEqual(10, t.Value); Aver.AreEqual(10, t.ValueAsInt); Aver.AreEqual(10, t.ValueAsLong); Aver.AreEqual("10", t.ToString()); Aver.IsTrue(t.IsScalar); Aver.IsTrue(ErlTypeOrder.ErlByte == t.TypeOrder); Aver.IsTrue(t.Matches(new ErlByte(10))); Aver.IsTrue(new ErlVarBind().SequenceEqual(t.Match(new ErlByte(10)))); doesNotThrow(() => { var x = t.ValueAsObject; }); Aver.AreEqual(10, t.ValueAsInt); Aver.AreEqual(10, t.ValueAsLong); Aver.AreEqual(10, t.ValueAsDecimal); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDateTime; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsTimeSpan; }); Aver.AreEqual(10.0, t.ValueAsDouble); Aver.AreEqual("10", t.ValueAsString); Aver.AreEqual(true, t.ValueAsBool); Aver.AreEqual('\n', t.ValueAsChar); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsByteArray; }); IErlObject temp = null; Aver.IsFalse(t.Subst(ref temp, new ErlVarBind())); Aver.AreEqual(10, t.Visit(0, (acc, o) => o.ValueAsInt)); char n = (char)t; Aver.AreEqual('\n', n); byte m = t; Aver.AreEqual(10, m); ErlByte b = 10; Aver.AreEqual(10, b.Value); ErlByte k = (ErlByte)10; Aver.AreEqual(10, k.Value); ErlByte z = (ErlByte)'\n'; Aver.AreEqual(10, k.Value); { var bind = new ErlVarBind(); Aver.IsTrue(b.Match(new ErlLong(10), bind)); Aver.IsTrue(new ErlLong(10).Match(b, bind)); b = 111; Aver.IsTrue(b.Match(new ErlLong(111), bind)); Aver.IsTrue(new ErlLong(111).Match(b, bind)); } }
public void CreateByCodeOwnDaemon() { using (var logger = new LogDaemon(NOPApplication.Instance)) { logger.WriteInterval = 0; //set the minimum flush period Aver.Throws <AzosException>(() => logger.Start()); //can not start daemon with no sinks Aver.IsFalse(logger.Running); Aver.IsFalse(logger.Sinks.Any()); using (var sink = new MemoryBufferSink(logger)) { sink.Name.See(); Aver.IsTrue(sink.Name.StartsWith("MemoryBufferSink.")); //anonymous sinks get their name from their: 'type.fid' logger.Start(); //now it can start Aver.IsTrue(logger.Running); Aver.AreSameRef(sink, logger.Sinks.First()); //now there is a sink registered which is this one Aver.IsTrue(sink.Running); //it was auto-started by the logger logger.Write(new Message { Type = MessageType.DebugB, Text = "This is a message #1" }); //so this messages goes in it Thread.Sleep(DAEMON_FLUSH_WAIT_MS); //make sure async flush happens Aver.IsTrue(sink.Buffered.Any()); //because sink was active var logged = sink.Buffered.FirstOrDefault(); // we get the first message buffered Aver.AreEqual("This is a message #1", logged.Text); Aver.IsTrue(MessageType.DebugB == logged.Type); sink.WaitForCompleteStop();//stop the sink Aver.IsFalse(sink.Running); logger.Write(new Message { Type = MessageType.Debug, Text = "This is a message #2" }); Thread.Sleep(DAEMON_FLUSH_WAIT_MS); //make sure async flush happens Aver.AreEqual(1, sink.Buffered.Count()); //because sink was not turned on for 2nd, only the first message got in, 2nd got lost } Aver.IsFalse(logger.Sinks.Any());//again, no sinks left } }
public void Parse() { Aver.IsFalse(SysAuthToken.Parse(null).Assigned); Aver.IsFalse(SysAuthToken.Parse("").Assigned); var v = SysAuthToken.Parse("frog::toad"); Aver.AreEqual("frog", v.Realm); Aver.AreEqual("toad", v.Data); Aver.Throws <SecurityException>(() => SysAuthToken.Parse("::toad")); Aver.Throws <SecurityException>(() => SysAuthToken.Parse("frog::")); Aver.Throws <SecurityException>(() => SysAuthToken.Parse("frogtoad")); Aver.Throws <SecurityException>(() => SysAuthToken.Parse("frog:toad")); }
public void ErlDoubleTest() { var t = new ErlDouble(10.128d); Aver.IsTrue(t.Equals(new ErlDouble(10.128d))); Aver.AreEqual(1, t.CompareTo(new ErlDouble(-1.1))); Aver.AreObjectsEqual(t, new ErlDouble(10.128d)); Aver.AreEqual(0, t.CompareTo(new ErlDouble(10.128d))); Aver.IsTrue(10.128d == t); Aver.IsTrue(t == 10.128d); Aver.AreEqual(10.128d, t.Value); Aver.AreEqual(10, t.ValueAsInt); Aver.AreEqual(10, t.ValueAsLong); Aver.AreEqual(10.128d, t.ValueAsDouble); Aver.AreEqual("10.128", t.ToString()); Aver.AreEqual("1.1", new ErlDouble(1.1).ToString()); Aver.IsTrue(t.IsScalar); Aver.IsTrue(ErlTypeOrder.ErlDouble == t.TypeOrder); Aver.IsTrue(t.Matches(new ErlDouble(10.128d))); Aver.IsTrue(new ErlVarBind().SequenceEqual(t.Match(new ErlDouble(10.128d)))); doesNotThrow(() => { var x = t.ValueAsObject; }); Aver.AreEqual(10, t.ValueAsInt); Aver.AreEqual(10, t.ValueAsLong); Aver.AreEqual(10.128m, t.ValueAsDecimal); doesNotThrow(() => { var x = t.ValueAsDateTime; }); doesNotThrow(() => { var x = t.ValueAsTimeSpan; }); Aver.AreEqual(10.128d, t.ValueAsDouble); Aver.AreEqual("10.128", t.ValueAsString); Aver.AreEqual(true, t.ValueAsBool); Aver.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0) + new TimeSpan(10 * 10), t.ValueAsDateTime); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsChar; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsByteArray; }); IErlObject temp = null; Aver.IsFalse(t.Subst(ref temp, new ErlVarBind())); Aver.AreEqual(10.128d, t.Visit(0.0, (acc, o) => o.ValueAsDouble)); double n = t; // Implicit conversion Aver.AreEqual(10.128d, n); ErlDouble a = 10.128d; // Implicit conversion Aver.AreEqual(10.128d, a.Value); }
public void IntMathLog() { Aver.AreEqual(10, IntMath.Log(1024, 2)); Aver.AreEqual(2, IntMath.Log(9, 3)); Aver.AreEqual(2, IntMath.Log(11, 3)); Aver.AreEqual(1, IntMath.Log(2, 2)); Aver.AreEqual(0, IntMath.Log(1, 2)); Aver.Throws <NFXException>(() => IntMath.Log(0, 2)); Aver.AreEqual(62, IntMath.Log(1L << 62, 2)); Aver.AreEqual(32, IntMath.Log(1L << 32, 2)); Aver.AreEqual(10, IntMath.Log(1024, 2)); Aver.AreEqual(4, IntMath.Log(16, 2)); Aver.AreEqual(3, IntMath.Log(8, 2)); Aver.AreEqual(1, IntMath.Log(2, 2)); Aver.AreEqual(0, IntMath.Log(1, 2)); }
public void ErlAtomTest() { var am_test = new ErlAtom("test"); Aver.IsTrue(am_test.Equals(new ErlAtom("test"))); Aver.AreObjectsEqual(am_test, new ErlAtom("test")); Aver.AreEqual("test", am_test.Value); Aver.AreEqual("test", am_test.ToString()); Aver.IsTrue(am_test.IsScalar); Aver.IsTrue(ErlTypeOrder.ErlAtom == am_test.TypeOrder); Aver.IsTrue(am_test.Matches(new ErlAtom("test"))); Aver.IsTrue(new ErlVarBind().SequenceEqual(am_test.Match(new ErlAtom("test")))); var am_Test = new ErlAtom("Test"); Aver.AreEqual("'Test'", am_Test.ToString()); Aver.AreEqual(4, am_Test.Length); Aver.AreObjectsNotEqual(am_test, am_Test); IErlObject temp = null; Aver.IsFalse(am_test.Subst(ref temp, new ErlVarBind())); Aver.IsTrue(am_Test.Visit(true, (acc, o) => acc)); doesNotThrow(() => { var x = am_test.ValueAsObject; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsInt; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsLong; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsDecimal; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsDateTime; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsTimeSpan; }); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsDouble; }); doesNotThrow(() => { var x = am_test.ValueAsString; }); doesNotThrow(() => { var x = am_test.ValueAsBool; }); Aver.AreEqual('a', new ErlAtom("a").ValueAsChar); Aver.Throws <ErlIncompatibleTypesException>(() => { var x = am_test.ValueAsByteArray; }); string s = am_test; // Implicit conversion Aver.AreEqual("test", s); ErlAtom a = "abc"; // Implicit conversion Aver.AreEqual("abc", a.Value); }
public void List_Readonly() { var lst = new EventedList <string, string>("CONTEXT", false); var ro = false; lst.GetReadOnlyEvent = (l) => ro; lst.Add("a"); lst.Add("b"); lst.Add("c"); Aver.AreEqual(3, lst.Count); ro = true; Aver.Throws <NFXException>(() => lst.Add("d")); }
public void Dict_Readonly() { var dict = new EventedDictionary <int, string, string>("CONTEXT", false); var ro = false; dict.GetReadOnlyEvent = (l) => ro; dict.Add(1, "a"); dict.Add(2, "b"); dict.Add(3, "c"); Aver.AreEqual(3, dict.Count); ro = true; Aver.Throws <AzosException>(() => dict.Add(4, "d")); }