public void QueryCodeTableTest_NoCache()
        {
            Mock <IJustWareApi> api = new Mock <IJustWareApi>();
            List <CaseType>     ct  = new List <CaseType>();

            ct.Add(new CaseType {
                Code = "C", Description = "D"
            });
            api.Setup(a => a.FindCaseTypes(It.IsAny <string>(), null)).Returns(ct);

            CodeLookupHelper helper = new CodeLookupHelper(api.Object);

            List <CaseType> returned = helper.QueryCodeTable <CaseType>("1==1");

            Assert.AreSame(ct, returned, "CaseTypes not returned correctly.");
            api.Verify(a => a.FindCaseTypes(It.IsAny <string>(), null), Times.Once(), "Api FindCaseTypes not called.");
        }
        public void QueryCodeTableTest_QueriesFromCache()
        {
            Mock <IJustWareApi>    api   = new Mock <IJustWareApi>();
            Mock <ICodeTableCache> cache = new Mock <ICodeTableCache>();
            List <CaseType>        ct    = new List <CaseType>();

            ct.Add(new CaseType {
                Code = "C", Description = "D"
            });
            cache.Setup(c => c.IsCodeTableCached <CaseType>()).Returns(true);
            cache.Setup(c => c.QueryCacheCodeTable <CaseType>(It.IsAny <string>())).Returns(ct);

            CodeLookupHelper helper = new CodeLookupHelper(api.Object, cache.Object);

            string          QUERY    = "1==1";
            List <CaseType> returned = helper.QueryCodeTable <CaseType>(QUERY);

            Assert.AreSame(ct, returned, "CaseTypes not returned correctly.");
            api.Verify(a => a.FindCaseTypes(It.IsAny <string>(), null), Times.Never(), "Api FindCaseTypes called when it should not have been.");
            cache.Verify(c => c.AddToDictionary(It.IsAny <List <CaseType> >()), Times.Never(), "AddToDictionary was called when it should not have been.");
            cache.Verify(c => c.QueryCacheCodeTable <CaseType>(QUERY), Times.Once(), "QueryCachedCodeTable was not called");
        }
        public void QueryCodeTableTest_QueriesFromCache()
        {
            Mock<IJustWareApi> api = new Mock<IJustWareApi>();
            Mock<ICodeTableCache> cache = new Mock<ICodeTableCache>();
            List<CaseType> ct = new List<CaseType>();
            ct.Add(new CaseType { Code = "C", Description = "D" });
            cache.Setup(c => c.IsCodeTableCached<CaseType>()).Returns(true);
            cache.Setup(c => c.QueryCacheCodeTable<CaseType>(It.IsAny<string>())).Returns(ct);

            CodeLookupHelper helper = new CodeLookupHelper(api.Object, cache.Object);

            string QUERY = "1==1";
            List<CaseType> returned = helper.QueryCodeTable<CaseType>(QUERY);
            Assert.AreSame(ct, returned, "CaseTypes not returned correctly.");
            api.Verify(a => a.FindCaseTypes(It.IsAny<string>(), null), Times.Never(), "Api FindCaseTypes called when it should not have been.");
            cache.Verify(c => c.AddToDictionary(It.IsAny<List<CaseType>>()), Times.Never(), "AddToDictionary was called when it should not have been.");
            cache.Verify(c => c.QueryCacheCodeTable<CaseType>(QUERY), Times.Once(), "QueryCachedCodeTable was not called");
        }
        public void QueryCodeTableTest_NoCache()
        {
            Mock<IJustWareApi> api = new Mock<IJustWareApi>();
            List<CaseType> ct = new List<CaseType>();
            ct.Add(new CaseType {Code = "C", Description = "D"});
            api.Setup(a => a.FindCaseTypes(It.IsAny<string>(), null)).Returns(ct);

            CodeLookupHelper helper = new CodeLookupHelper(api.Object);

            List<CaseType> returned = helper.QueryCodeTable<CaseType>("1==1");
            Assert.AreSame(ct, returned, "CaseTypes not returned correctly.");
            api.Verify(a=>a.FindCaseTypes(It.IsAny<string>(), null), Times.Once(), "Api FindCaseTypes not called.");
        }