Exemple #1
0
        public async Task KnownExceptionIsThrownAsIs()
        {
            var mockStorageAdapter = Mock.Of <IStorageAdapter>();

            using (var storage = new Microsoft.AppCenter.Storage.Storage(mockStorageAdapter))
            {
                var exception = new StorageException();
                Mock.Get(mockStorageAdapter).Setup(adapter => adapter.CountAsync(It.IsAny <Expression <Func <LogEntry, bool> > >())).Throws(exception);
                Mock.Get(mockStorageAdapter).Setup(adapter => adapter.InsertAsync(It.IsAny <LogEntry>())).Throws(exception);
                try
                {
                    await storage.PutLog(StorageTestChannelName, TestLog.CreateTestLog());

                    Assert.Fail("Should have thrown exception");
                }
                catch (Exception e)
                {
                    Assert.AreSame(exception, e);
                }
                try
                {
                    await storage.CountLogsAsync(StorageTestChannelName);

                    Assert.Fail("Should have thrown exception");
                }
                catch (Exception e)
                {
                    Assert.AreSame(exception, e);
                }
            }
        }
Exemple #2
0
 public void UnknownExceptionIsConvertedToStorageException()
 {
     var mockStorageAdapter = Mock.Of<IStorageAdapter>();
     using (var storage = new Microsoft.AppCenter.Storage.Storage(mockStorageAdapter, _databasePath))
     {
         var exception = new Exception();
         Mock.Get(mockStorageAdapter).Setup(adapter => adapter.Count(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<object>())).Throws(exception);
         Mock.Get(mockStorageAdapter).Setup(adapter => adapter.Insert(It.IsAny<string>(), It.IsAny<string[]>(), It.IsAny<IList<object[]>>())).Throws(exception);
         Assert.ThrowsException<StorageException>(() => storage.PutLog(StorageTestChannelName, TestLog.CreateTestLog()).RunNotAsync());
         Assert.ThrowsException<StorageException>(() => storage.CountLogsAsync(StorageTestChannelName).RunNotAsync());
     }
 }
Exemple #3
0
        public async Task UnknownExceptionIsConvertedToStorageException()
        {
            var mockStorageAdapter = Mock.Of <IStorageAdapter>();

            using (var storage = new Microsoft.AppCenter.Storage.Storage(mockStorageAdapter))
            {
                var exception = new Exception();
                Mock.Get(mockStorageAdapter).Setup(adapter => adapter.CountAsync(It.IsAny <Expression <Func <LogEntry, bool> > >())).Throws(exception);
                Mock.Get(mockStorageAdapter).Setup(adapter => adapter.InsertAsync(It.IsAny <LogEntry>())).Throws(exception);
                await Assert.ThrowsExceptionAsync <StorageException>(() => storage.PutLog(StorageTestChannelName, TestLog.CreateTestLog()));

                await Assert.ThrowsExceptionAsync <StorageException>(() => storage.CountLogsAsync(StorageTestChannelName));
            }
        }
Exemple #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);
 }
Exemple #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());
        }
Exemple #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());
        }
Exemple #7
0
        public void CountEmptyStorage()
        {
            var count = _storage.CountLogsAsync(StorageTestChannelName).RunNotAsync();

            Assert.AreEqual(0, count);
        }