public void SHOULD_RETURN_TYPE_STRING_AS_LOGGER_NAME() { //Arrange var typeMapper = new CachedDictionaryLoggerMapper(); var type = typeof(InjectableClass); //Act var loggerName = typeMapper.GetLoggerName(type); //Assert loggerName.Should().Be(type.ToString()); }
public void SHOULD_RETURN_LOGGER_NAME_FROM_TYPE_MAPPING(string expectedLoggerName) { //Arrange var typeMapper = new CachedDictionaryLoggerMapper(); var type = typeof(InjectableClass); typeMapper.MapTypeToLoggerName(type, expectedLoggerName); //Act var loggerName = typeMapper.GetLoggerName(type); //Assert loggerName.Should().Be(expectedLoggerName); }
public void SHOULD_CLEAR_CACHE_WHEN_ADDING_NAMESPACE_MAPPING() { //Arrange var mappingDictionary = new Dictionary <Type, string>(); var emptyDictionary = new Dictionary <string, string>(); var cache = Substitute.For <IKeyValueCache <Type, string> >(); var typeMapper = new CachedDictionaryLoggerMapper(mappingDictionary, emptyDictionary, cache); //Act typeMapper.MapNamespaceToLoggerName("namespace", "Logger1"); //Assert cache.Received().Clear(); }
public void SHOULD_ATTEMPT_USING_CACHE_FOR_EACH_INJECTION(Type type) { //Arrange var mappingDictionary = new Dictionary <Type, string>(); var emptyDictionary = new Dictionary <string, string>(); var cache = Substitute.For <IKeyValueCache <Type, string> >(); var typeMapper = new CachedDictionaryLoggerMapper(mappingDictionary, emptyDictionary, cache); //Act typeMapper.GetLoggerName(type); //Assert cache.Received().ContainsKey(type); }
public void SHOULD_NOT_GET_LOGGER_NAME_FROM_CACHE_WHEN_DOES_NOT_EXIST(Type type) { //Arrange var mappingDictionary = new Dictionary <Type, string>(); var emptyDictionary = new Dictionary <string, string>(); var cache = Substitute.For <IKeyValueCache <Type, string> >(); cache.ContainsKey(type).Returns(false); var typeMapper = new CachedDictionaryLoggerMapper(mappingDictionary, emptyDictionary, cache); //Act typeMapper.GetLoggerName(type); //Assert cache.DidNotReceive().GetEntryValue(type); }
public void SHOULD_NOT_ADD_LOGGER_NAME_TO_CACHE_WHEN_EXISTS(Type type) { //Arrange var mappingDictionary = new Dictionary <Type, string>(); var emptyDictionary = new Dictionary <string, string>(); var cache = Substitute.For <IKeyValueCache <Type, string> >(); cache.ContainsKey(type).Returns(true); var typeMapper = new CachedDictionaryLoggerMapper(mappingDictionary, emptyDictionary, cache); //Act var loggerName = typeMapper.GetLoggerName(type); //Assert cache.DidNotReceive().AddEntry(type, loggerName); }
public void SHOULD_NOT_RETURN_LOGGER_NAME_FROM_CACHE_WHEN_DOES_NOT_EXIST(Type type) { //Arrange var mappingDictionary = new Dictionary <Type, string>(); var emptyDictionary = new Dictionary <string, string>(); var cache = Substitute.For <IKeyValueCache <Type, string> >(); cache.ContainsKey(type).Returns(false); cache.GetEntryValue(type).Returns("CachedLogger"); var typeMapper = new CachedDictionaryLoggerMapper(mappingDictionary, emptyDictionary, cache); //Act var loggerName = typeMapper.GetLoggerName(type); //Assert loggerName.Should().NotBe("CachedLogger"); }
public void SHOULD_RETURN_LOGGER_NAME_FROM_INITIAL_NAMESPACE_MAPPING(string expectedLoggerName) { //Arrange var type = typeof(InjectableClass); var mappingDictionary = new Dictionary <string, string> { { type.Namespace, expectedLoggerName } }; var emptyDictionary = new Dictionary <Type, string>(); var dummyCache = Substitute.For <IKeyValueCache <Type, string> >(); var typeMapper = new CachedDictionaryLoggerMapper(emptyDictionary, mappingDictionary, dummyCache); //Act var loggerName = typeMapper.GetLoggerName(type); //Assert loggerName.Should().Be(expectedLoggerName); }
public void SHOULD_USE_WIDER_NAMESPACE_MAPPING_IF_EXISTS() { //Arrange var generalNameSpace = "Autofac.log4net"; var type = typeof(InjectableClass); var mappingDictionary = new Dictionary <string, string> { { generalNameSpace, "GeneralLogger" }, }; var emptyDictionary = new Dictionary <Type, string>(); var dummyCache = Substitute.For <IKeyValueCache <Type, string> >(); var typeMapper = new CachedDictionaryLoggerMapper(emptyDictionary, mappingDictionary, dummyCache); //Act var loggerName = typeMapper.GetLoggerName(type); //Assert loggerName.Should().Be("GeneralLogger"); }