public LogicTest() : base(LogicOf <ILogic> .New((x) => { //TESTS HERE })) { }
public StoreOfTest() : base(LogicOf <IStore> .New((x) => { x.Clear(); var store = x.IsOf <BaseThing>(); BaseThing thing1 = new BaseThing() { Data = "data", Id = "thing1" }; DerivedThing thing2 = new DerivedThing() { Data = "data", Data1 = "data1", Id = "thing2" }; DerivedDerivedThing thing3 = new DerivedDerivedThing() { Data = "data", Data1 = "data1", Data2 = "data2", Id = "thing3" }; var thing4 = AsId <string> .New("asId1"); store.SaveItem(thing1); store.SaveItem(thing2); store.SaveItem(thing3); Assert.Throws <InvalidOperationException>(() => { store.SaveItem(thing4); }); store.DeleteItems(thing1.GetStoredObjectId(), thing2.GetStoredObjectId(), thing3.GetStoredObjectId()); })) { }
public IdentifyingTest() : base(LogicOf <IHasId> .New((x) => { //try out all the decorations var guid = Guid.NewGuid(); var hasGuid = x.HasGUID(guid); Condition.Requires(hasGuid.GUID).IsEqualTo(guid); var now = DateTime.Now; var hasDateCreated = hasGuid.HasDateCreated(now); Condition.Requires(hasDateCreated.DateCreated).IsEqualTo(now); var lastTouchedDate = DateTime.Now; var hasLastTouched = hasDateCreated.HasDateLastTouched(lastTouchedDate); Condition.Requires(hasLastTouched.DateLastTouched).IsEqualTo(lastTouchedDate); var localMachineName = NetUtil.GetLocalMachineName(); var hasLM = hasLastTouched.HasLocalMachineName(); Condition.Requires(hasLM.MachineName).IsEqualTo(localMachineName); var ip = NetUtil.GetLocalIPAddresses().First(); var hasIP = hasLM.HasIP(ip); Condition.Requires(hasIP.IPAddress.ToString()).IsEqualTo(ip.ToString()); var hasRS = hasIP.HasRandomString("blah"); Condition.Requires(hasRS.RandomString).IsEqualTo("blah"); var hasV = hasRS.HasVersion("v"); Condition.Requires(hasV.Version).IsEqualTo("v"); })) { }
/// <summary> /// builds up the arg as a ValueOf with a bunch of adjustments and observers /// </summary> private void BuildArgDecoration() { this.Logger.Do((x) => x.LogVerbose("BuildArgDecoration started", null)); var intercepts = this.Layers; //decorate the argument IValueOf <TArg> argOf = null; if (this.Arg != null) { argOf = this.Arg.AsNaturalValue(); //decorate the adjustments intercepts.WithEach((intercept) => { if (intercept.ArgDecorator != null) { argOf = argOf.Adjust(intercept.ArgDecorator); } }); //decorate the observations intercepts.WithEach((intercept) => { if (intercept.ArgValidator != null) { argOf = argOf.Observe(null, LogicOf <IValueOf <TArg> > .New((x) => { intercept.ArgValidator.Perform(argOf); })); } }); this.DecoratedArg = argOf; } this.Logger.Do((x) => x.LogVerbose("BuildArgDecoration completed", null)); }
public ThrottleTest() : base(LogicOf <Nothing> .New((x) => { NaturalThrottle.New(1); int count = 0; var logic = Logic.New(() => { count++; Thread.Sleep(2000); }); var throttled = logic.Throttle(1); Action act1 = new Action(() => { throttled.Perform(); }); Action act2 = new Action(() => { throttled.Perform(); }); act1.EnqueueToThreadPool(); act2.EnqueueToThreadPool(); Thread.Sleep(1000); Condition.Requires(count).IsEqualTo(1); Thread.Sleep(1000); Condition.Requires(count).IsEqualTo(1); Thread.Sleep(2000); Condition.Requires(count).IsEqualTo(2); })) { }
public HTTPHostTest() : base(LogicOf <Nothing> .New((x) => { var ep = EndPoint.NewFreeLocalEndPointSpecifyingPort(80); var host = HTTPHost.New(ep, (req) => { StringBuilder sb = new StringBuilder(); sb.AppendLine("<HTML><BODY>"); var lines = HTTPHost.DumpHTTPRequest(req); foreach (var eachline in lines) { sb.AppendLine(eachline + "<BR>"); } sb.AppendLine("</BODY></HTML>"); return(sb.ToString()); }, "test/"); host.Initialize(); host.Start(); string uri = "http://" + ep.IPAddress + ":" + ep.Port + "/test/"; //Console.ReadLine(); //now hit it with some requests using (var client = new HttpClient()) { var getdat = HTTPClient.Get(client, uri); HTTPClient.Delete(client, uri); var postdat = HTTPClient.Post(client, new StringContent("yo"), uri); var putdat = HTTPClient.Put(client, new StringContent("yo"), uri); } })) { }
public Test() : base(LogicOf <IStore> .New((x) => { x.Clear(); var thing = AsId <string> .New("asId1"); var soid = thing.GetStoredObjectId(); var store = x.BasicAudit(NamedNaturalInMemoryStore.New("auditstore").IsOf <StoredItemAuditPoint>()); //do some stuff..all of this should be tracked store.SaveItem(thing); var auditItems = store.AuditStore.GetAll(); Assert.True(auditItems[0].Mode == StoredItemAccessMode.Save && auditItems[0].ObjRef.Equals(soid)); var clone = store.Get <AsId <string> >("asId1"); auditItems = store.AuditStore.GetAll(); Assert.True(auditItems[1].Mode == StoredItemAccessMode.Read && auditItems[1].ObjRef.Equals(soid)); var list = store.SearchOf <AsId <string> >(LogicOfTo <AsId <string>, bool> .New((o) => { return(o.Id.Equals("asId1")); })); auditItems = store.AuditStore.GetAll(); Assert.True(auditItems[2].Mode == StoredItemAccessMode.Read && auditItems[2].ObjRef.Equals(soid)); var list2 = store.GetAll(); auditItems = store.AuditStore.GetAll(); Assert.True(auditItems[3].Mode == StoredItemAccessMode.Read && auditItems[3].ObjRef.Equals(soid)); store.DeleteItem(soid); auditItems = store.AuditStore.GetAll(); Assert.True(auditItems[4].Mode == StoredItemAccessMode.Delete && auditItems[4].ObjRef.Equals(soid)); store.Dispose(); })) { }
public Test() : base(LogicOf <IStore> .New((x) => { x.Clear(); var store = x.HasFactory(LogicOfTo <IStoredObjectId, IHasId> .New((soId) => { //the factory produces AsId<string> only if (soId.ObjectType.Equals(typeof(AsId <string>))) { return(AsId <string> .New(soId.ObjectId.ToString())); } return(null); })); //pull from the store, which is empty. it should factory the item up var item = store.Get <AsId <string> >("asId1"); Assert.True(item != null); //delete it store.DeleteItem(item.GetStoredObjectId()); item = store.Get <AsId <string> >("asId1"); Assert.True(item != null); //cleanup store.Dispose(); })) { }
public ConditionTest() : base(LogicOf <ICondition> .New((x) => { //tests "adjustment" idiom for Conditions //we adjust by ANDing a switch that we turn off and on //get the old eval. we'll be expecting this value with the switch on var oldEval = x.Evaluate(); //the adjustment is an AND with a conditional bool that we switch on and off var switchCond = StrategizedConditionOf <bool> .New((cond) => { return(new bool?(cond)); }).AddContext(false); //apply the adjustment var newX = x.Adjust((cond) => { return(cond.And(switchCond)); }); //if we evaluate the adjusted condition it should eval to false due to the switch condition var adjustedEval = newX.Evaluate(); Condition.Requires(adjustedEval).IsEqualTo(false); //switch on switchCond.Context = true; adjustedEval = newX.Evaluate(); Condition.Requires(adjustedEval).IsEqualTo(oldEval); })) { }
public FileableTest() : base(LogicOf <IStringable> .New((x) => { //get the string value var val = x.GetValue(); //back to a file var fileable = x.Fileable().Filing("test.test"); fileable.Write(); var readVal = fileable.GetValue(); Condition.Requires(readVal).IsEqualTo(val); fileable.Parse("a"); fileable.Write(); readVal = fileable.GetValue(); Condition.Requires(readVal).IsEqualTo("a"); //back to a locked file var lockfileable = x.Fileable().LockingFiling("test.test"); lockfileable.Read(); readVal = lockfileable.GetValue(); Condition.Requires(readVal).IsEqualTo("a"); //test the locking fileable = x.Fileable().Filing("test.test"); try { fileable.Read(); } catch { } })) { }
public ValueOfTest() : base(LogicOf <IValueOf <string> > .New((x) => { //TESTS HERE })) { }
public LogicTest() : base(LogicOf <ILogic> .New((x) => { var pf = x.Polyfacing <ILogic>(); var face = pf.As <ILogic>(); var decorated = face.GetDecorated(); Condition.Requires(object.ReferenceEquals(decorated, x)).IsTrue(); })) { }
public WaiterTest() : base(LogicOf <Nothing> .New((x) => { var flagDate = DateTime.Now.AddSeconds(5); ICondition cond = StrategizedCondition.New(() => { return(DateTime.Now < flagDate); }); ICondition expCond = StrategizedCondition.New(() => { return(DateTime.Now > flagDate.AddSeconds(1)); }); var waiter = ConditionalWaiter.New(cond, expCond); waiter.WaitAround(); })) { }
public static ILogger GetFileLogger(string path) { var logger = StoreLogger.New(NaturalInMemoryStore.New().Polls()); logger.Store.GetPoll().SetBackgroundAction(LogicOf <IStore> .New((store) => { var dat = StoreSerializer.SerializeStore(store, ValueManagerChainOfResponsibility.NewDefault()); Debug.WriteLine(dat); dat.MakeStringable().Fileable().Filing(path).Write(); }), 100); return(logger); }
public LogicTest() : base(LogicOf <ILogic> .New((x) => { var flagDate = DateTime.Now.AddSeconds(5); ICondition cond = StrategizedCondition.New(() => { return(DateTime.Now < flagDate); }); ICondition expCond = StrategizedCondition.New(() => { return(DateTime.Now > flagDate.AddSeconds(1)); }); var newX = x.WaitUntil(cond, expCond); newX.Perform(); })) { }
public HTTPSHostTest() : base(LogicOf <Nothing> .New((x) => { var ep = EndPoint.NewFreeLocalEndPointSpecifyingPort(80); var host = HTTPSHost.New(ep, (req) => { StringBuilder sb = new StringBuilder(); sb.AppendLine("<HTML><BODY>"); var lines = HTTPSHost.DumpHTTPRequest(req); foreach (var eachline in lines) { sb.AppendLine(eachline + "<BR>"); } sb.AppendLine("</BODY></HTML>"); return(sb.ToString()); }, "test/"); using (host) { host.Initialize(); host.Start(); string uri = "https://" + ep.IPAddress + ":" + ep.Port; //Console.ReadLine(); ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; //using (WebClient webClient = new WebClient()) //{ // var stream = webClient.OpenRead(uri); // using (StreamReader sr = new StreamReader(stream)) // { // var page = sr.ReadToEnd(); // } //} //now hit it with some requests using (var client = new HttpClient()) { var getdat = HTTPClient.Get(client, uri); HTTPClient.Delete(client, uri); var postdat = HTTPClient.Post(client, new StringContent("yo"), uri); var putdat = HTTPClient.Put(client, new StringContent("yo"), uri); } } })) { }
public OperationProtocolHostDecoration(IEndPointHost decorated, ValueManagerChainOfResponsibility valueManager = null) : base(decorated.StoreProtocoling(null, valueManager)) { this.OperationManager = OperationManager.New(); //replace the store protocol logic this.As <StoreProtocolHostDecoration>(true).HasStoreProtocolLogic( LogicOf <Tuple <IStore, IStore> > .New((uow) => { this.OperationManager.HandleOperations(uow.Item1, uow.Item2); })); }
/// <summary> /// invokes the arg decorations, then the logic decorations, then invokes the logic /// </summary> private TResult InvokeDecoratedArgAndLogic() { this.Logger.Do((x) => x.LogVerbose("InvokeDecoratedArgAndLogic started", null)); this.Logger.Do((x) => x.LogVerbose("Arg", this.Arg)); this.ProcessedArg = this.DecoratedArg.GetValue(); //invoke arg decoration chain (adjusters and observers) this.Logger.Do((x) => x.LogVerbose("ProcessedArg", this.ProcessedArg)); ILogicOf <TArg> logicOf = (ILogicOf <TArg>) this.DecoratedLogic; var logicResults = logicOf.Perform(this.ProcessedArg) as LogicOfTo <TArg, TResult>; this.Logger.Do((x) => x.LogVerbose("Logic performed", null)); this.Result = logicResults.Result; this.Logger.Do((x) => x.LogVerbose("Result", this.Result)); //decorate the result this.Logger.Do((x) => x.LogVerbose("Decorate result started", null)); var intercepts = this.Layers; if (this.Result != null) { IValueOf <TResult> resultOf = this.Result.AsNaturalValue(); //decorate the adjustments intercepts.WithEach((intercept) => { if (intercept.ResultDecorator != null) { resultOf = resultOf.Adjust(intercept.ResultDecorator); } }); //decorate the observations intercepts.WithEach((intercept) => { if (intercept.ResultValidator != null) { resultOf = resultOf.Observe(null, LogicOf <IValueOf <TResult> > .New((x) => { intercept.ResultValidator.Perform(resultOf); })); } }); this.Logger.Do((x) => x.LogVerbose("Decorate result completed", null)); this.DecoratedResult = resultOf; this.ProcessedResult = resultOf.GetValue(); //invoke the decorations this.Logger.Do((x) => x.LogVerbose("ProcessedResult", this.ProcessedResult)); } return(this.ProcessedResult); }
public DPCParseTest() : base(LogicOf <Nothing> .New((x) => { string commandtoparse = ".dosomething(11.0,15,asdkljlkjmjh,).dosomethingelse(aaadsfasdf)"; var cmds = commandtoparse.TokenizeToDPCOperations(); Condition.Requires(cmds).HasLength(2); Condition.Requires(cmds[1].OperationToken.TokenString).IsEqualTo("dosomethingelse"); Condition.Requires(cmds[0].ArgTokens[3].TokenString).IsEqualTo(""); Debug.WriteLine(""); })) { }
public static IExpirable BuildTouchLimitExpirable(int limit) { //fluently build something that Counts, and has a condition on that count, and is touchable var pf = Polyface.New(); pf.IsCounter(); pf.IsConditionalExpirable(StrategizedConditionOf <Polyface> .New((pf1) => { return(pf1.AsCounter().Current > limit); })); pf.IsStrategizedTouchable(LogicOf <Polyface> .New((pf1) => { pf1.AsCounter().Increment(); })); //var expire = NaturalFalseExpirable.New().ExpiresWhen( .InWindow(startDate, endDate); // return expire; return(pf.AsConditionalExpirable()); }
public ValueOfTest() : base(LogicOf <IValueOf <string> > .New((x) => { var flagDate = DateTime.Now.AddSeconds(5); ICondition cond = StrategizedCondition.New(() => { return(DateTime.Now < flagDate); }); ICondition expCond = StrategizedCondition.New(() => { return(DateTime.Now > flagDate.AddSeconds(1)); }); var newX = x.WaitUntil(cond, expCond); var oldVal = x.GetValue().GraphSerializeWithDefaults(); var newVal = newX.GetValue().GraphSerializeWithDefaults(); Condition.Requires(oldVal).IsEqualTo(newVal); })) { }
public ConditionTest() : base(LogicOf <ICondition> .New((x) => { var flagDate = DateTime.Now.AddSeconds(5); ICondition cond = StrategizedCondition.New(() => { return(DateTime.Now < flagDate); }); ICondition expCond = StrategizedCondition.New(() => { return(DateTime.Now > flagDate.AddSeconds(1)); }); var newX = x.WaitUntil(cond, expCond); var oldVal = x.Evaluate(); var newVal = newX.Evaluate(); Condition.Requires(oldVal).IsEqualTo(newVal); })) { }
public StringableListTest() : base(LogicOf <IStringableList> .New((x) => { var oldVal = x.GetValue(); var lengthstringable = x.DecorateListWithLength(); var newVal = lengthstringable.GetValue(); lengthstringable.Parse(newVal); Condition.Requires(oldVal).IsNotEqualTo(newVal); var decVal = lengthstringable.Decorated.GetValue(); Condition.Requires(decVal).IsEqualTo(oldVal); })) { }
public Test() : base(LogicOf <IStore> .New((x) => { x.Clear(); var store = x.Intercepting(FileLoggerUtil.GetFileLogger("storeinttest.txt")); //build a commit interception that: //decorates the arg by appending the character A to the id //validates the arg by checking for the A store.CommitOperationIntercept.AddNextIntercept("intercept1", (o) => { CommitBag newBag = new CommitBag(); var oldBag = o; oldBag.ItemsToSave.WithEach(saveItem => { if (saveItem is AsId <string> ) { var newItem = AsId <string> .New(saveItem.Id.ToString() + "A"); newBag.MarkItemSaved(newItem); } }); return(newBag); }, (o) => { var oldBag = o; oldBag.ItemsToSave.WithEach(saveItem => { if (saveItem is AsId <string> ) { var id = saveItem.Id.ToString(); Assert.True(id.EndsWith("A")); } }); }, null, null, null); var thing = AsId <string> .New("asId1"); store.SaveItem(thing); //pull from the store, which is empty. it should factory the item up var clone = store.Get <AsId <string> >("asId1A"); Assert.True(clone != null); //TODO: test all intercepts, not just Commit store.Dispose(); })) { }
public LogicTest() : base(LogicOf <ILogic> .New((x) => { var expiry = DateTime.Now.AddSeconds(5); var newX = x.HasExpirable(); newX.ExpiresWhen(StrategizedCondition.New(() => { return(DateTime.Now > expiry); })); newX.Perform(); Thread.Sleep(6000); var trapX = newX.Traps(); trapX.Perform(); })) { }
public ValueOfTest() : base(LogicOf <IValueOf <string> > .New((x) => { bool checkVal = false; var newX = x.Eventing(); newX.Evaluated += delegate(object sender, EventArgOf <IValueOf <string> > e) { checkVal = true; }; newX.GetValue(); Thread.Sleep(50); Condition.Requires(checkVal).IsTrue(); })) { }
public LogicTest() : base(LogicOf <ILogic> .New((x) => { bool checkVal = false; var newX = x.Eventing(); newX.Performed += delegate(object sender, EventArgOf <ILogic> e) { checkVal = true; }; newX.Perform(); Thread.Sleep(50); Condition.Requires(checkVal).IsTrue(); })) { }
public ConditionTest() : base(LogicOf <ICondition> .New((x) => { var expiry = DateTime.Now.AddSeconds(5); var newX = x.HasExpirable(); newX.ExpiresWhen(StrategizedCondition.New(() => { return(DateTime.Now > expiry); })); newX.Evaluate(); Thread.Sleep(6000); var trapX = newX.Traps(); var trapVal = trapX.Evaluate(); Condition.Requires(trapVal).IsEqualTo(false); })) { }
public BasicStoreTest() : base(LogicOf <Tuple <IStore, IHasId> > .New((tuple) => { CompareLogic compareLogic = new CompareLogic(); //build function to compare objects a bunch of diff ways Func <object, object, bool> equivTest = (thing1, thing2) => { //try comparelogic first if (!thing1.IsDeepEqual(thing2)) return(false); //try objectgraphing compare var dat1 = thing1.GraphSerializeWithDefaults(); var dat2 = thing2.GraphSerializeWithDefaults(); return(dat1.Equals(dat2)); }; var store = tuple.Item1; var item = tuple.Item2; var itemId = item.GetStoredObjectId(); //save it store.SaveItem(item); //load it & compare it IHasId item2 = store.Get(itemId); Assert.NotNull(item2); Assert.True(equivTest(item, item2)); //search for it & compare it var filter = LogicOfTo <IHasId, bool> .New((x) => { return(x.GetStoredObjectId().Equals(itemId)); }); var items = store.Search(filter); Assert.True(items.Count == 1); //delete it store.DeleteItem(items.First().GetStoredObjectId()); item2 = store.Get(itemId); Assert.True(item2 == null); })) { }
public LogicTest() : base(LogicOf <ILogic> .New((x) => { var data = "data"; var observer = x.Observe(LogicOf <ILogic> .New((o) => { data = "data1"; }), null); Condition.Requires(data).IsEqualTo("data"); observer.Perform(); Condition.Requires(data).IsEqualTo("data1"); })) { }