Пример #1
0
 public void SetScopeContext(ScopeContext scopeContext)
 {
     if (scopeContext == null)
     {
         throw new ArgumentNullException(nameof(scopeContext));
     }
     Contexts[scopeContext.ScopeId] = scopeContext;
 }
Пример #2
0
        public void GetItemAs_Convert_ShouldOK()
        {
            ScopeContext.Resolve = () => new MockScopeService(true);
            var scopeContext = ScopeContext.GetScopeContext("001", false);

            scopeContext.GetItemAs("isFoo", false).ShouldTrue();
            scopeContext.GetItemAs("isFooX", false).ShouldFalse();
        }
Пример #3
0
        public void GetItem_NotExistKey_ShouldOK()
        {
            ScopeContext.Resolve = () => new MockScopeService(true);
            var scopeContext = ScopeContext.GetScopeContext("001", false);

            scopeContext.GetItem("NotExist", null).ShouldNull();
            scopeContext.GetItem("NotExist", "A").ShouldEqual("A");
        }
Пример #4
0
        public void GetItem_ExistKey_ShouldOK()
        {
            ScopeContext.Resolve = () => new MockScopeService(true);
            var scopeContext = ScopeContext.GetScopeContext("001", false);

            scopeContext.GetItem("foo").ShouldEqual("FOO");
            scopeContext.GetItem("FoO").ShouldEqual("FOO");
        }
Пример #5
0
        public void SetItem_ExistKey_ShouldReplace()
        {
            ScopeContext.Resolve = () => new MockScopeService(true);
            var scopeContext = ScopeContext.GetScopeContext("001", false);

            scopeContext.SetItem("foo", "BAR");
            scopeContext.GetItem("foo", null).ShouldEqual("BAR");
        }
Пример #6
0
        public void GetScopeContext_ReplaceResolve_ShouldOK()
        {
            ScopeContext.Resolve = () => new MockScopeService(true);
            ScopeContext.GetScopeContext("001", false).ShouldNotNull();

            //replace repos
            ScopeContext.Resolve = () => new MockScopeService(false);
            ScopeContext.GetScopeContext("001", false).ShouldNull();
        }
Пример #7
0
 public MockScopeService(bool seed)
 {
     if (seed)
     {
         var scopeContext = new ScopeContext();
         Contexts["001"]             = scopeContext;
         scopeContext.Items["foo"]   = "FOO";
         scopeContext.Items["isFoo"] = true;
     }
 }
Пример #8
0
        public ScopeContext GetScopeContext(string scopeId, bool createIfNotExist)
        {
            if (!Contexts.ContainsKey(scopeId))
            {
                if (!createIfNotExist)
                {
                    return(null);
                }

                var scopeContext = new ScopeContext {
                    ScopeId = scopeId
                };
                Contexts[scopeId] = scopeContext;
            }
            return(Contexts[scopeId]);
        }
Пример #9
0
        public static T GetItemAs <T>(this ScopeContext ctx, string key, T defaultValue = default(T))
        {
            var value = ctx.GetItem(key, defaultValue);

            return((T)Convert.ChangeType(value, typeof(T)));
        }
Пример #10
0
 public void GetScopeContext_NotExist_ShouldOK()
 {
     ScopeContext.Resolve = () => new MockScopeService(true);
     ScopeContext.GetScopeContext("NotExist", false).ShouldNull();
 }