public void GetCodeDescription_FillsCache()
        {
            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"
            });
            ct.Add(new CaseType {
                Code = "C2", Description = "D2"
            });
            api.Setup(a => a.FindCaseTypes(It.IsAny <string>(), null)).Returns(ct);


            List <CaseType> singleItemList = new List <CaseType>();

            singleItemList.Add(new CaseType()
            {
                Code = "C", Description = "D"
            });

            cache.Setup(c => c.QueryCacheCodeTable <CaseType>(It.IsAny <string>())).Returns(singleItemList);
            cache.Setup(c => c.IsCodeTableCached <CaseType>()).Returns(false);

            CodeLookupHelper helper      = new CodeLookupHelper(api.Object, cache.Object);
            string           description = helper.GetCodeDescription <CaseType>("C");

            Assert.AreEqual("D", description, "The correct caseType was not returned");
            api.Verify(a => a.FindCaseTypes(It.Is <string>(s => s == CodeLookupHelper.ALL_CODES_QUERY), null), Times.Once(), "FindCaseTypes was not called correctly");
            cache.Verify(c => c.AddToDictionary(It.Is <List <CaseType> >(l => l.Count() == 2)), Times.Once(), "Full CodeTable was not cached.");
        }
        public void GetCodeDescriptionTest()
        {
            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);

            string description = helper.GetCodeDescription<CaseType>("C");
            Assert.AreEqual("D", description, "The correct caseType was not returned");
            api.Verify(a => a.FindCaseTypes(It.Is<string>(s => s == "Code == \"C\""), null), Times.Once(), "FindCaseTypes was not called correctly");
        }
        public void GetCodeDescriptionTest()
        {
            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);

            string description = helper.GetCodeDescription <CaseType>("C");

            Assert.AreEqual("D", description, "The correct caseType was not returned");
            api.Verify(a => a.FindCaseTypes(It.Is <string>(s => s == "Code == \"C\""), null), Times.Once(), "FindCaseTypes was not called correctly");
        }
        public void GetCodeDescription_FillsCache()
        {
            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" });
            ct.Add(new CaseType { Code = "C2", Description = "D2" });
            api.Setup(a => a.FindCaseTypes(It.IsAny<string>(), null)).Returns(ct);

            List<CaseType> singleItemList = new List<CaseType>();
            singleItemList.Add(new CaseType(){Code = "C", Description = "D"});

            cache.Setup(c => c.QueryCacheCodeTable<CaseType>(It.IsAny<string>())).Returns(singleItemList);
            cache.Setup(c => c.IsCodeTableCached<CaseType>()).Returns(false);

            CodeLookupHelper helper = new CodeLookupHelper(api.Object, cache.Object);
            string description = helper.GetCodeDescription<CaseType>("C");

            Assert.AreEqual("D", description, "The correct caseType was not returned");
            api.Verify(a => a.FindCaseTypes(It.Is<string>(s => s == CodeLookupHelper.ALL_CODES_QUERY), null), Times.Once(), "FindCaseTypes was not called correctly");
            cache.Verify(c=>c.AddToDictionary(It.Is<List<CaseType>>(l=>l.Count() == 2)), Times.Once(), "Full CodeTable was not cached.");
        }