public void MiddlewareShouldBeCalledOnDispatch() { var count = 0; // This middleware just simply increase count variable // whenever Dispatch is count MiddlewareDelegate <int> countingMiddleware = _ => { return(dispatcher => action => { ++count; dispatcher.Invoke(action); return action; }); }; var store = new SimpleStore(0, countingMiddleware); store.Dispatch(new CountAction()); Assert.AreEqual(1, count); store.Dispatch(new AddAction() { amount = 5 }); Assert.AreEqual(2, count); store.Dispatch(new CountAction()); Assert.AreEqual(3, count); }
public void TextTooLong(string variable, int characters) { var builder = new StringBuilder(); var store = new SimpleStore(); string input; // Add some variables in the text to test a use case where we don't have only text if (!string.IsNullOrEmpty(variable)) { builder.Append(variable); } builder.Append('a', characters); // Add some variables in the text to test a use case where we don't have only text if (!string.IsNullOrEmpty(variable)) { builder.Append(variable); } input = builder.ToString(); store["foo"] = "{foo}"; var document = new SimpleDocument(input); var output = document.Render(store); Assert.AreEqual(input, output); }
public void StoreShouldUseMiddlewareModifiedAction() { // This is an evil middleware that basically replace all actions // to CountAction instead. MiddlewareDelegate <int> replaceAllActionToCountMiddleware = _ => { return(dispatcher => action => { var newAction = new CountAction(); dispatcher.Invoke(newAction); return newAction; }); }; var store = new SimpleStore(0, replaceAllActionToCountMiddleware); Assert.AreEqual(0, store.GetState()); store.Dispatch(new CountAction()); Assert.AreEqual(1, store.GetState()); store.Dispatch(new AddAction() { amount = 5 }); Assert.AreEqual(2, store.GetState()); // Even on actions that normally not recognized store.Dispatch(new UnrecognizedAction()); Assert.AreEqual(3, store.GetState()); }
/// <summary> /// Get an instance of SslCertificateProviderService /// </summary> public SslCertificateProviderService( ILoggerInterface logger, string appId, EnvironmentSettings globalSettings, Deployment deployment) { this.AppPoolUtils = new UtilsAppPool(logger); this.UtilsHosts = new UtilsHosts(logger); this.MockEnvironment = UtilsSystem.RunningInContinuousIntegration() || UnitTestDetector.IsRunningInTests || Debugger.IsAttached; // Everything performed against the staging API needs to be kept apart, including signer, etc... this.StoragePath = Path.Combine(globalSettings.GetDefaultContentStorage().path, "letsencrypt" + (this.MockEnvironment ? "_mock" : null)); UtilsSystem.EnsureDirectoryExists(this.StoragePath, true); // If CCS is available, use that, otherwise use the central content storage string sslRenewalStateStorePath = UtilsIis.CentralStoreEnabled() ? UtilsIis.CentralStorePath(logger) : globalSettings.GetDefaultContentStorage().path; this.SimpleStoreRenewalStatus = new SimpleStore(Path.Combine(sslRenewalStateStorePath, "_ssl_renewal_state_store"), true); this.Logger = logger; this.AppId = appId; this.Deployment = deployment; this.GlobalSettings = globalSettings; }
public void TooLongStringsTest(string variable) { var sb = new StringBuilder(); string input; // Add some variables in the text to test a use case where we don't have only text if (!string.IsNullOrEmpty(variable)) { sb.Append(variable); } sb.Append('a', 45000); // Add some variables in the text to test a use case where we don't have only text if (!string.IsNullOrEmpty(variable)) { sb.Append(variable); } input = sb.ToString(); IStore store = new SimpleStore(); store["foo"] = "{foo}"; var doc = new SimpleDocument(input); var res = doc.Render(store); Assert.AreEqual(input, res); }
public void StageShouldNotChangeAfterUnrecognizedAction() { var store = new SimpleStore(); store.Dispatch(new UnrecognizedAction()); Assert.AreEqual(0, store.GetState()); store.Dispatch(new UnrecognizedAction()); Assert.AreEqual(0, store.GetState()); }
public void StageShouldChangeAfterCountAction() { var store = new SimpleStore(); store.Dispatch(new CountAction()); Assert.AreEqual(1, store.GetState()); store.Dispatch(new CountAction()); Assert.AreEqual(2, store.GetState()); }
/// <summary> /// Get an instance of AppVeyorClient /// </summary> /// <param name="token">API Token</param> /// <param name="baseUri">Base URI</param> /// <param name="logger"></param> /// <param name="tempDir"></param> public Client( string token, string baseUri, ILoggerInterface logger, string tempDir) { string apiTempDir = UtilsSystem.EnsureDirectoryExists(UtilsSystem.CombinePaths(tempDir, "_appveyor", "api"), true); this.TempDir = tempDir; this.Token = token; this.Logger = logger; this.BaseUri = baseUri; this.SimpleStore = new SimpleStore(apiTempDir); }
private void AssertRender(string source, string expected, ISetting setting, Action <IStore> populate, Action <IDocument> listen) { IDocument document; IStore store; foreach (Func <string, ISetting, IDocument> constructor in DocumentTester.constructors) { document = constructor(source, setting); listen(document); store = new SimpleStore(); populate(store); Assert.AreEqual(expected, document.Render(store), "Invalid rendered output for document type '{0}'", document.GetType()); } }
public void TestSimpleStore() { var simpleStore = new SimpleStore(UtilsSystem.GetTempPath("samplestore")); simpleStore.Clear(); Assert.False(simpleStore.Get <string>("itemA", out _)); simpleStore.Set("itemA", "testdataA", 50); Assert.True(simpleStore.Get <string>("itemA", out var itemA)); Assert.Equal("testdataA", itemA.Data); Assert.False(simpleStore.Get <string>("itemB", out _)); simpleStore.Set("itemB", "testdataB", 50); Assert.True(simpleStore.Get <string>("itemA", out itemA)); Assert.Equal("testdataA", itemA.Data); Assert.True(simpleStore.Get <string>("itemB", out var itemB)); Assert.Equal("testdataB", itemB.Data); }
public void MiddlewareEffectsShouldCompound() { MiddlewareDelegate <int> addOneMiddleware = _ => { return(dispatcher => action => { if (action is AddAction) { var addAction = (AddAction)action; var newAction = new AddAction() { amount = addAction.amount + 1 }; dispatcher.Invoke(newAction); return newAction as IAction; } else { dispatcher.Invoke(action); return action as IAction; } }); }; MiddlewareDelegate <int> doubleMiddleware = _ => { return(dispatcher => action => { if (action is AddAction) { var addAction = (AddAction)action; var newAction = new AddAction() { amount = addAction.amount * 2 }; dispatcher.Invoke(newAction); return newAction as IAction; } else { dispatcher.Invoke(action); return action as IAction; } }); }; MiddlewareDelegate <int> logMiddleware = _ => { return(dispatcher => action => { Debug.Log(JsonUtility.ToJson(action)); dispatcher.Invoke(action); return action; }); }; var store = new SimpleStore(0, addOneMiddleware, doubleMiddleware, logMiddleware); Assert.AreEqual(0, store.GetState()); store.Dispatch(new CountAction()); Assert.AreEqual(1, store.GetState()); // AddAction +5 would be modified as +1 then x2, therefore ultimately become AddAction +12 store.Dispatch(new AddAction() { amount = 5 }); Assert.AreEqual(13, store.GetState()); // These middlewares only target AddActions store.Dispatch(new UnrecognizedAction()); Assert.AreEqual(13, store.GetState()); }
public void StoreShouldHaveDefaultState() { var store = new SimpleStore(); Assert.AreEqual(0, store.GetState()); }
public void StoreShouldHaveInitialState() { var store = new SimpleStore(5); Assert.AreEqual(5, store.GetState()); }
private void AssertReturn(string source, string expected, ISetting setting, Action<IStore> populate, Action<IDocument> listen) { IDocument document; IStore store; Value value; foreach (Func<string, ISetting, IDocument> constructor in DocumentTester.constructors) { document = constructor (source, setting); listen (document); store = new SimpleStore (); populate (store); value = document.Render (store, new StringWriter ()); Assert.AreEqual (expected, value.ToString (), "Invalid return value for document type '{0}'", document.GetType ()); } }