public void CacheStorageCanHandleMultipleExceptionsWhenReading() { // Arrange var stringListener = new TraceStringListener(); var cacheAccessor = Substitute.For <ICacheAccessor>(); var exception = new InvalidOperationException("some error"); cacheAccessor.Read().Throws(exception); cacheAccessor.When((x) => x.Clear()).Do(x => throw exception); _logger.Listeners.Add(stringListener); var actualLogger = new TraceSourceLogger(_logger); var storage = new Storage(s_storageCreationProperties, cacheAccessor, actualLogger); // Act byte[] result = null; try { result = storage.ReadData(); } catch (Exception ex) { // ignore Assert.IsTrue(ex is InvalidOperationException); } // Assert Assert.IsTrue(stringListener.CurrentLog.Contains("TestSource Error")); Assert.IsTrue(stringListener.CurrentLog.Contains("InvalidOperationException")); Assert.IsTrue(stringListener.CurrentLog.Contains("some error")); }
public void TestInitialize() { _logger = new TraceSource("TestSource", SourceLevels.All); _testListener = new TraceStringListener(); _logger.Listeners.Add(_testListener); }
public static (TraceSource, TraceStringListener) Create() { var logger = new TraceSource(TraceSourceName, SourceLevels.All); var listner = new TraceStringListener(); logger.Listeners.Add(listner); return(logger, listner); }
public void VerifyPersistenceThrowsIfDataReadIsEmpty() { // Arrange var stringListener = new TraceStringListener(); var actualLogger = new TraceSourceLogger(_logger); var cacheAccessor = Substitute.For <ICacheAccessor>(); cacheAccessor.CreateForPersistenceValidation().Returns(cacheAccessor); var storage = new MsalCacheStorage(s_storageCreationProperties, cacheAccessor, actualLogger); // Act var ex = AssertException.Throws <MsalCachePersistenceException>( () => storage.VerifyPersistence()); // Assert Assert.IsNull(ex.InnerException); // no more details available }
public void VerifyPersistenceThrowsInnerExceptions() { // Arrange var stringListener = new TraceStringListener(); var actualLogger = new TraceSourceLogger(_logger); var cacheAccessor = Substitute.For <ICacheAccessor>(); cacheAccessor.CreateForPersistenceValidation().Returns(cacheAccessor); var exception = new InvalidOperationException("some error"); var storage = new MsalCacheStorage(s_storageCreationProperties, cacheAccessor, actualLogger); cacheAccessor.Read().Throws(exception); // Act var ex = AssertException.Throws <MsalCachePersistenceException>( () => storage.VerifyPersistence()); // Assert Assert.AreEqual(ex.InnerException, exception); }
public void VerifyPersistenceHappyPath() { // Arrange byte[] dummyData = Encoding.UTF8.GetBytes(MsalCacheStorage.PersistenceValidationDummyData); var stringListener = new TraceStringListener(); var actualLogger = new TraceSourceLogger(_logger); var cacheAccessor = Substitute.For <ICacheAccessor>(); cacheAccessor.CreateForPersistenceValidation().Returns(cacheAccessor); var storage = new MsalCacheStorage(s_storageCreationProperties, cacheAccessor, actualLogger); cacheAccessor.Read().Returns(dummyData); // Act storage.VerifyPersistence(); // Assert Received.InOrder(() => { cacheAccessor.CreateForPersistenceValidation(); cacheAccessor.Write(Arg.Any <byte[]>()); cacheAccessor.Read(); cacheAccessor.Clear(); }); }