示例#1
0
        public void ShutdownPreventsNewTasks()
        {
            var mockConnection = new Mock <IStorageAdapter>();
            var storage        = new Microsoft.AppCenter.Storage.Storage(mockConnection.Object);
            var result         = storage.ShutdownAsync(TimeSpan.FromSeconds(10)).RunNotAsync();

            Assert.IsTrue(result);
            Assert.ThrowsException <StorageException>(
                () => storage.GetLogsAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <List <Log> >()).RunNotAsync());
        }
示例#2
0
        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());
        }
示例#3
0
        public void GetLogsQueryError()
        {
            var mockAdapter = new Mock <IStorageAdapter>();

            mockAdapter.Setup(
                a => a.Select(TableName, It.IsAny <string>(), It.IsAny <object>(), It.IsAny <string>(), It.IsAny <object[]>(), It.IsAny <int?>(), It.IsAny <string[]>()))
            .Throws(new StorageException());
            var fakeStorage = new Microsoft.AppCenter.Storage.Storage(mockAdapter.Object, It.IsAny <string>());
            var logs        = new List <Log>();

            Assert.ThrowsException <StorageException>(() =>
                                                      fakeStorage.GetLogsAsync(StorageTestChannelName, 1, logs).RunNotAsync());
        }
示例#4
0
 public void FailToGetALog()
 {
     // Prepare data.
     StorageAdapter adapter = new StorageAdapter();
     adapter.Initialize(_databasePath);
     var tables = new[] { ColumnIdName, ColumnChannelName, ColumnLogName };
     var types = new[] { "INTEGER PRIMARY KEY AUTOINCREMENT", "TEXT NOT NULL", "TEXT NOT NULL" };
     adapter.CreateTable(TableName, tables, types);
     adapter.Insert(TableName, tables, new List<object[]> { new object[] { 100, StorageTestChannelName, "good luck deserializing me!" } });
     var storage = new Microsoft.AppCenter.Storage.Storage(adapter, _databasePath);
     var logs = new List<Log>();
     var batchId = storage.GetLogsAsync(StorageTestChannelName, 4, logs).RunNotAsync();
     var count = storage.CountLogsAsync(StorageTestChannelName).RunNotAsync();
     Assert.IsNull(batchId);
     Assert.AreEqual(0, logs.Count);
     Assert.AreEqual(0, count);
 }
示例#5
0
        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());
        }
示例#6
0
        public void StorageThrowsStorageException()
        {
            var mockAdapter = new Mock <IStorageAdapter>();

            mockAdapter.Setup(
                a => a.Select(TableName, It.IsAny <string>(), It.IsAny <object>(), It.IsAny <string>(), It.IsAny <object[]>(), It.IsAny <int?>(), It.IsAny <string[]>()))
            .Throws(new StorageException());
            mockAdapter.Setup(c => c.Insert(TableName, It.IsAny <string[]>(), It.IsAny <IList <object[]> >()))
            .Throws(new StorageException());
            mockAdapter.Setup(c => c.Delete(TableName, It.IsAny <string>()))
            .Throws(new StorageException());
            mockAdapter.Setup(c => c.Count(TableName, It.IsAny <string>(), It.IsAny <object>()))
            .Throws(new StorageException());
            var fakeStorage = new Microsoft.AppCenter.Storage.Storage(mockAdapter.Object, It.IsAny <string>());

            Assert.ThrowsException <StorageException>(() => fakeStorage.PutLog(StorageTestChannelName, new TestLog()).RunNotAsync());
            Assert.ThrowsException <StorageException>(() => fakeStorage.DeleteLogs(StorageTestChannelName, string.Empty).RunNotAsync());
            Assert.ThrowsException <StorageException>(() => fakeStorage.CountLogsAsync(StorageTestChannelName).RunNotAsync());
            Assert.ThrowsException <StorageException>(() => fakeStorage.GetLogsAsync(StorageTestChannelName, 1, new List <Log>()).RunNotAsync());
        }
示例#7
0
        public void PutOneLog()
        {
            var addedLog = TestLog.CreateTestLog();

            _storage.PutLog(StorageTestChannelName, addedLog);
            var retrievedLogs = new List <Log>();

            _storage.GetLogsAsync(StorageTestChannelName, 1, retrievedLogs).RunNotAsync();
            var retrievedLog = retrievedLogs[0];

            Assert.AreEqual(addedLog, retrievedLog);
        }