Exemplo n.º 1
0
        public void WhenConstructingAndReceivedPasswordShouldPassPasswordToSQLiteRepository()
        {
            var password     = new byte[] { 0xFF, 0xAA, 0xCC, 0xCC };
            var reynaService = new ReynaService(password, null, false, this.Logger.Object);

            Assert.Equal(password, ((SQLiteRepository)reynaService.PersistentStore).Password);
        }
Exemplo n.º 2
0
        public void WhenConstructingAndReceivedPasswordShouldPassPasswordToSQLiteRepository()
        {
            var password = new byte[] { 0xFF, 0xAA, 0xCC, 0xCC };
            var reynaService = new ReynaService(password, null);

            Assert.Equal(password, ((SQLiteRepository)reynaService.PersistentStore).Password); 
        }
Exemplo n.º 3
0
        public void ShouldEncryptDbIfPasswordIsPassedAndDbIsNotEncrypted()
        {
            var sqliteRepository = new SQLiteRepository(new ReynaNullLogger(), new byte[] { 0x33, 0xFF, 0xAB });

            sqliteRepository.Create();

            var reynaService = new ReynaService(new byte[] { 0x33, 0xFF, 0xAB }, null, false, new ReynaNullLogger());

            reynaService.Start();

            var assemblyFile = new FileInfo(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
            var path         = Path.Combine(assemblyFile.DirectoryName, "reyna.db");

            var bytes = new byte[16];

            using (var file = File.OpenRead(path))
            {
                file.Read(bytes, 0, bytes.Length);
            }

            var stringResult = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);

            Assert.AreNotEqual("SQLite format 3\0", stringResult);

            reynaService.Stop();
            File.Delete(path);
        }
Exemplo n.º 4
0
        public void ShouldKeepSizeTheSameWhenAddingNewMessage()
        {
            long size     = 2 * 1024 * 1024; // 2 mega
            var  password = new byte[] { 0x33, 0xFF, 0xAB };

            ReynaService.ResetStorageSizeLimit();
            var sqliteRepository = new SQLiteRepository(new ReynaNullLogger(), password);

            sqliteRepository.Create();

            var reynaService = new ReynaService(password, null, false, new ReynaNullLogger());

            reynaService.Start();

            var assemblyFile = new FileInfo(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
            var path         = Path.Combine(assemblyFile.DirectoryName, "reyna.db");

            ReynaService.SetStorageSizeLimit(new ReynaNullLogger(), password, size);

            putMessageFromFile(reynaService, assemblyFile.DirectoryName, 100);
            reynaService.Stop();
            var fileInfo = new FileInfo(path);

            Assert.AreEqual(1812480, fileInfo.Length);
            File.Delete(path);
        }
Exemplo n.º 5
0
        public void WhenConstructingWithUseNetworkStateIsFalseShouldNotUseNetworkStateService()
        {
            var reynaService = new ReynaService(null, null, false, this.Logger.Object);

            Assert.Null(reynaService.NetworkStateService);
            reynaService.Dispose();
        }
Exemplo n.º 6
0
        public void WhenAddingAndRemovingFromDifferentThreadShouldNotThrow()
        {
            var password = new byte[] { 0x33, 0xFF, 0xAB };

            ReynaService.ResetStorageSizeLimit();
            this.Repository = new SQLiteRepository(new ReynaNullLogger(), password);
            this.Repository.Create();

            Thread injectingThread = new Thread(this.AddMessage);
            Thread removingThread  = new Thread(this.RemoveMessage);
            Thread readThread      = new Thread(this.ReadMessages);
            Thread deleteThread    = new Thread(this.DeleteMessages);

            injectingThread.Start();
            removingThread.Start();
            readThread.Start();
            deleteThread.Start();

            injectingThread.Join();
            removingThread.Join();
            readThread.Join();
            deleteThread.Join();

            Assert.AreEqual(0, this.Repository.AvailableMessagesCount);
        }
Exemplo n.º 7
0
        public void WhenConstructingWithUseNetworkStateIsFalseAndHasOtherArgsShouldNotUseNetworkStateService()
        {
            var password     = new byte[] { 0xFF, 0xAA, 0xCC, 0xCC };
            var reynaService = new ReynaService(password, null, false, this.Logger.Object);

            Assert.Null(reynaService.NetworkStateService);
            Assert.Equal(password, ((SQLiteRepository)reynaService.PersistentStore).Password);
            reynaService.Dispose();
        }
 public void WhenCallingDisposeAndServicesAreNullShouldNotDisposeServices()
 {
     var helper = new TestUnityHelper();
     var container = helper.GetContainer();
     ReynaService service = new ReynaService(null, container);
     service.StoreService = null;
     service.ForwardService = null;
     service.NetworkStateService = null;
     service.Dispose();
     helper.mockStoreService.Verify(s => s.Dispose(), Times.Never);
     helper.mockForwardService.Verify(s => s.Dispose(), Times.Never);
     helper.mockNetworkStateService.Verify(s => s.Dispose(), Times.Never);
 }
Exemplo n.º 9
0
 public void StartStopDisposeShouldWork()
 {
     var reynaService = new ReynaService(false, this.Logger.Object);
     Assert.Null(reynaService.NetworkStateService);
     reynaService.Start();
     System.Threading.Thread.Sleep(1000);
     reynaService.Stop();
     reynaService.Stop();
     reynaService.Stop();
     reynaService.Dispose();
     reynaService.Dispose();
     reynaService.Dispose();
 }
Exemplo n.º 10
0
 public GivenAReynaService()
 {
     service = new ReynaService(null, unity.GetContainer());
     httpClient = unity.mockHttpClient;
     preferences = unity.mockPreferences;
     persistentStore = unity.mockSqlStore;
     volatileStore = unity.mockVolatileStore;
     networkStateService = unity.mockNetworkStateService;
     storeService = unity.mockStoreService;
     forwardService = unity.mockForwardService;
     encryptionChecker = unity.mockEncryptionChecker;
     reynaLogger = unity.mockReynaLogger;
 }
Exemplo n.º 11
0
        public void StartStopDisposeShouldWork()
        {
            var reynaService = new ReynaService(null, null, false, this.Logger.Object);

            Assert.Null(reynaService.NetworkStateService);
            reynaService.Start();
            System.Threading.Thread.Sleep(1000);
            reynaService.Stop();
            reynaService.Stop();
            reynaService.Stop();
            reynaService.Dispose();
            reynaService.Dispose();
            reynaService.Dispose();
        }
Exemplo n.º 12
0
        public void WhenCallingStartAndMessageAddedAndStorageSizeLimitExistsShouldCallAddWithLimitOnRepository()
        {
            using (var key = Registry.LocalMachine.CreateSubKey(@"Software\Reyna"))
            {
                var message = new Message(new Uri("http://www.google.com"), string.Empty);
                var logger  = new ReynaNullLogger();
                ReynaService.SetStorageSizeLimit(logger, null, 2000000);
                this.StoreService.Put(message);

                this.PersistentStore.Verify(r => r.Add(message, 2000000), Times.Once());
            }

            Registry.LocalMachine.DeleteSubKey(@"Software\Reyna\PeriodicBackoutCheck", false);
            Registry.LocalMachine.DeleteSubKey(@"Software\Reyna", false);
        }
Exemplo n.º 13
0
        public static void Main(string[] args)
        {
            var store = new ReynaService();

            store.Start();
            Time from = new Time(10, 00);
            Time to = new Time(12, 59);
            ReynaService.SetCellularDataBlackout(new TimeRange(from, to));

            store.Put(GetMessage());
            store.Put(GetMessage());
            store.Put(GetMessage());

            Thread.Sleep(100);

            store.Put(GetMessage());
            store.Put(GetMessage());
            store.Put(GetMessage());

            store.Stop();
        }
Exemplo n.º 14
0
        public static void Main(string[] args)
        {
            var store = new ReynaService(null, null, false, new ReynaNullLogger());

            store.Start();
            Time from = new Time(10, 00);
            Time to   = new Time(12, 59);

            ReynaService.SetCellularDataBlackout(new TimeRange(from, to));

            store.Put(GetMessage());
            store.Put(GetMessage());
            store.Put(GetMessage());

            Thread.Sleep(100);

            store.Put(GetMessage());
            store.Put(GetMessage());
            store.Put(GetMessage());

            store.Stop();
        }
Exemplo n.º 15
0
        public void WhenConstructingWithoutAPasswordShouldnotSetPasswordOnSecureStore()
        {
            var helper = new TestUnityHelper();
            var container = helper.GetContainer();

            helper.mockSqlStore.SetupSet(s => s.Password = It.IsAny<byte[]>()).Verifiable();

            ReynaService service = new ReynaService(null, container);

            helper.mockSqlStore.VerifySet(s => s.Password = It.IsAny<byte[]>(), Times.Never);
        }
Exemplo n.º 16
0
        public void WhenConstructingWithAPasswordShouldSetPasswordOnSecureStore()
        {
            var helper = new TestUnityHelper();
            var container = helper.GetContainer();
            byte[] bytes = Encoding.ASCII.GetBytes("password");

            helper.mockSqlStore.SetupSet(s => s.Password = bytes).Verifiable();

            ReynaService service = new ReynaService(bytes, container);

            helper.mockSqlStore.VerifySet(s => s.Password=bytes, Times.Exactly(1));
        }
Exemplo n.º 17
0
 public void WhenConstructingWithAPasswordPasswordFieldShouldBeSet()
 {
     byte[] bytes = Encoding.ASCII.GetBytes("password");
     var helper = new TestUnityHelper();
     var container = helper.GetContainer();
     ReynaService service = new ReynaService(bytes, container);
     Assert.True(bytes.SequenceEqual(service.Password));
 }
Exemplo n.º 18
0
 public void WhenConstructingShouldCallInitialiseOnStoreService()
 {
     var helper = new TestUnityHelper();
     var container = helper.GetContainer();
     ReynaService service = new ReynaService(null, container);
     helper.mockStoreService.Verify(s => s.Initialize(helper.mockVolatileStore.Object, helper.mockSqlStore.Object), Times.Exactly(1));
 }
Exemplo n.º 19
0
 public void WhenConstructingShouldCallInitialiseOnForwardService()
 {
     var helper = new TestUnityHelper();
     var container = helper.GetContainer();
     ReynaService service = new ReynaService(null, container);
     helper.mockForwardService.Verify(s => s.Initialize(helper.mockSqlStore.Object, helper.mockHttpClient.Object, helper.mockNetworkStateService.Object, It.IsAny<int>(), It.IsAny<int>(), It.IsAny<bool>()), Times.Exactly(1));
 }
Exemplo n.º 20
0
        public void WhenCallingStartAndPasswordIsSetAndDbIsNotEncryptedShouldEncryptDbUsingPassword()
        {
            var helper = new TestUnityHelper();
            var container = helper.GetContainer();
            byte[] bytes = Encoding.ASCII.GetBytes("password");
            ReynaService service = new ReynaService(bytes, container);
            helper.mockEncryptionChecker.Setup(m => m.DbEncrypted()).Returns(false);

            service.Start();

            helper.mockEncryptionChecker.Verify(m => m.EncryptDb(bytes), Times.Exactly(1));
        }
Exemplo n.º 21
0
        public void WhenCallingStartAndPasswordIsNotSetAndShouldNotEncryptDb()
        {
            var helper = new TestUnityHelper();
            var container = helper.GetContainer();
            ReynaService service = new ReynaService(null, container);

            service.Start();

            helper.mockEncryptionChecker.Verify(m => m.DbEncrypted(), Times.Never);
        }
Exemplo n.º 22
0
 public void WhenConstructingWithUseNetworkStateIsTrueShouldUseNetworkStateService()
 {
     var reynaService = new ReynaService(null, null, true, this.Logger.Object);
     Assert.NotNull(reynaService.NetworkStateService);
     reynaService.Dispose();
 }
Exemplo n.º 23
0
        public void WhenConstructingWithoutPasswordShouldNotPassAnyPasswordToSQLiteRepository()
        {
            var reynaService = new ReynaService(null, null, false, this.Logger.Object);

            Assert.Null(((SQLiteRepository)reynaService.PersistentStore).Password);
        }
Exemplo n.º 24
0
 public void WhenConstructingWithUseNetworkStateIsFalseShouldNotUseNetworkStateService()
 {
     var reynaService = new ReynaService(false, this.Logger.Object);
     Assert.Null(reynaService.NetworkStateService);
     reynaService.Dispose();
 }
Exemplo n.º 25
0
        public void WhenConstructingWithoutPasswordShouldNotPassAnyPasswordToSQLiteRepository()
        {
            var reynaService = new ReynaService();

            Assert.Null(((SQLiteRepository)reynaService.PersistentStore).Password);
        }
Exemplo n.º 26
0
 public void WhenConstructingWithUseNetworkStateIsFalseAndHasOtherArgsShouldNotUseNetworkStateService()
 {
     var password = new byte[] { 0xFF, 0xAA, 0xCC, 0xCC };
     var reynaService = new ReynaService(password, null, false, this.Logger.Object);
     Assert.Null(reynaService.NetworkStateService);
     Assert.Equal(password, ((SQLiteRepository)reynaService.PersistentStore).Password);
     reynaService.Dispose();
 }