public void GetLogsQueryError() { var mockAdapter = new Mock <IStorageAdapter>(); mockAdapter.Setup( a => a.GetAsync(It.IsAny <PredType>(), It.IsAny <int>())) .Returns(TaskExtension.GetFaultedTask <List <Microsoft.AppCenter.Storage.Storage.LogEntry> >(new StorageException())); var fakeStorage = new Microsoft.AppCenter.Storage.Storage(mockAdapter.Object); var logs = new List <Log>(); Assert.ThrowsException <StorageException>(() => fakeStorage.GetLogsAsync(StorageTestChannelName, 1, logs).RunNotAsync()); }
public void ShutdownSucceed() { var mockConnection = new Mock <IStorageAdapter>(); mockConnection.Setup( c => c.InsertAsync(It.IsAny <Microsoft.AppCenter.Storage.Storage.LogEntry>())) .Callback(() => Task.Delay(TimeSpan.FromSeconds(2)).Wait()) .Returns(TaskExtension.GetCompletedTask(1)); var storage = new Microsoft.AppCenter.Storage.Storage(mockConnection.Object); // Ignore warnings because we just want to "fire and forget" #pragma warning disable 4014 storage.PutLog(StorageTestChannelName, new TestLog()); storage.PutLog(StorageTestChannelName, new TestLog()); #pragma warning restore 4014 var result = storage.ShutdownAsync(TimeSpan.FromSeconds(100)).RunNotAsync(); Assert.IsTrue(result); }
public void StorageThrowsStorageException() { var mockAdapter = new Mock <IStorageAdapter>(); mockAdapter.Setup( a => a.GetAsync(It.IsAny <PredType>(), It.IsAny <int>())) .Returns(TaskExtension.GetFaultedTask <List <Microsoft.AppCenter.Storage.Storage.LogEntry> >(new StorageException())); mockAdapter.Setup(c => c.InsertAsync(It.IsAny <Microsoft.AppCenter.Storage.Storage.LogEntry>())) .Returns(TaskExtension.GetFaultedTask <int>(new StorageException())); mockAdapter.Setup(c => c.DeleteAsync(It.IsAny <Expression <Func <Microsoft.AppCenter.Storage.Storage.LogEntry, bool> > >())) .Returns(TaskExtension.GetFaultedTask <int>(new StorageException())); mockAdapter.Setup(c => c.CountAsync(It.IsAny <Expression <Func <Microsoft.AppCenter.Storage.Storage.LogEntry, bool> > >())) .Returns(TaskExtension.GetFaultedTask <int>(new StorageException())); var fakeStorage = new Microsoft.AppCenter.Storage.Storage(mockAdapter.Object); Assert.ThrowsException <StorageException>(() => fakeStorage.PutLog("channel_name", new TestLog()).RunNotAsync()); Assert.ThrowsException <StorageException>(() => fakeStorage.DeleteLogs("channel_name", string.Empty).RunNotAsync()); Assert.ThrowsException <StorageException>(() => fakeStorage.CountLogsAsync("channel_name").RunNotAsync()); Assert.ThrowsException <StorageException>(() => fakeStorage.GetLogsAsync("channel_name", 1, new List <Log>()).RunNotAsync()); }
public Task ExecuteCallAsync(IServiceCall call) { return(CallShouldSucceed ? TaskExtension.GetCompletedTask() : TaskExtension.GetFaultedTask(TaskError)); }