Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        /// <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;
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
        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());
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        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());
            }
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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());
        }
Ejemplo n.º 12
0
        public void StoreShouldHaveDefaultState()
        {
            var store = new SimpleStore();

            Assert.AreEqual(0, store.GetState());
        }
Ejemplo n.º 13
0
        public void StoreShouldHaveInitialState()
        {
            var store = new SimpleStore(5);

            Assert.AreEqual(5, store.GetState());
        }
Ejemplo n.º 14
0
        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 ());
            }
        }