public void GetCodeTable_NoCache_DoesntBlowup() { 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.GetCodeTable <CaseType>(); Assert.AreSame(ct, returned, "CaseTypes not returned correctly."); api.Verify(a => a.FindCaseTypes(It.Is <string>(s => s == CodeLookupHelper.ALL_CODES_QUERY), null), Times.Once(), "FindCaseTypes was not called correctly"); }
public void GetCodeTableTest() { 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" }); api.Setup(a => a.FindCaseTypes(It.IsAny <string>(), null)).Returns(ct); cache.Setup(c => c.QueryCacheCodeTable <CaseType>(It.IsAny <string>())).Returns(new List <CaseType>()); CodeLookupHelper helper = new CodeLookupHelper(api.Object, cache.Object); List <CaseType> returned = helper.GetCodeTable <CaseType>(); Assert.AreSame(ct, returned, "CaseTypes not returned correctly."); 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 == ct)), Times.Once(), "Code Table was not cached"); }
public void GetCodeTable_NoCache_DoesntBlowup() { 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.GetCodeTable<CaseType>(); Assert.AreSame(ct, returned, "CaseTypes not returned correctly."); api.Verify(a => a.FindCaseTypes(It.Is<string>(s => s == CodeLookupHelper.ALL_CODES_QUERY), null), Times.Once(), "FindCaseTypes was not called correctly"); }
public void GetCodeTable_GetsFromCacheIfThere() { 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.QueryCacheCodeTable<CaseType>(It.IsAny<string>())).Returns(ct); api.Setup(a => a.FindCaseTypes(It.IsAny<string>(), null)).Returns(ct); CodeLookupHelper helper = new CodeLookupHelper(api.Object, cache.Object); List<CaseType> returned = helper.GetCodeTable<CaseType>(); Assert.AreSame(ct, returned, "CaseTypes not returned correctly."); api.Verify(a => a.FindCaseTypes(It.Is<string>(s => s == CodeLookupHelper.ALL_CODES_QUERY), null), Times.Never(), "FindCaseTypes was called when it should not have been"); cache.Verify(c => c.QueryCacheCodeTable<CaseType>(It.Is<string>(s => s == CodeLookupHelper.ALL_CODES_QUERY)), Times.Once(), "Code Table was not cached"); }