コード例 #1
0
 public void TestAuthenticationOnLogin()
 {
     using (var s = new DiskServiceImpl(GetPersistence()))
     {
         s.Login("nananana", "blub");
     }
 }
コード例 #2
0
 public void TestWriteFail()
 {
     using (var s = new DiskServiceImpl(GetPersistenceWithData()))
     {
         s.WriteBlock(new UserDto { Login = "******", HashedPassword = "******" }, _disk.Id, 33, new byte[33]);
     }
 }
コード例 #3
0
 public void TestReadFail()
 {
     using (var s = new DiskServiceImpl(GetPersistenceWithData()))
     {
         s.ReadBlock(new UserDto { Login = "******", HashedPassword = "******" }, _disk.Id, 33);
     }
 }
コード例 #4
0
 public void TestAuthenticationOnCreateDisk()
 {
     using (var s = new DiskServiceImpl(GetPersistence()))
     {
         s.Login("nananana", "blub");
         var disk = s.CreateDisk(new UserDto { Login = "******", HashedPassword = "******" },
                      new DiskOptionsDto { BlockSize = 1000, MasterBlockSize = 1000, SerializedFileSystemOptions = new byte[10] });
     }
 }
コード例 #5
0
 public void TestCreateDiskBad()
 {
     using (var persistence = GetPersistence())
     {
         var s = new DiskServiceImpl(persistence);
         var disk = s.CreateDisk(new UserDto { Login = "******", HashedPassword = "******" }, null);
         Assert.IsNull(disk);
     }
 }
コード例 #6
0
        public void TestWriteRead()
        {
            using (var s = new DiskServiceImpl(GetPersistenceWithData()))
            {
                var expected = new byte[100];
                new Random(1).NextBytes(expected);

                s.WriteBlock(_userDto, _disk.Id, 33, expected);

                var actual = s.ReadBlock(_userDto, _disk.Id, 33);

                for (var i = 0; i < expected.Length; i++) Assert.AreEqual(expected[i], actual[i]);
            }
        }
コード例 #7
0
 public void TestCreateDiskSuccess()
 {
     using (var persistence = GetPersistenceWithUser())
     {
         var user = persistence.CreateUser(_userDto.Login, _userDto.HashedPassword);
         var s = new DiskServiceImpl(persistence);
         var disk = s.CreateDisk(user, new DiskOptionsDto());
         Assert.AreEqual(user.Id, disk.UserId);
         Assert.AreEqual(1, persistence.Disks(user).Count);
         Assert.AreEqual(user.Id, persistence.Disks(user).First().UserId);
         Assert.AreEqual(user.Id, disk.UserId);
         Assert.AreEqual(1, disk.UserId);
     }
 }
コード例 #8
0
 public void TestRegistrationFail()
 {
     using (var persistence = GetPersistence())
     {
         var u = persistence.CreateUser("bla", "blub");
         var s = new DiskServiceImpl(persistence);
         s.Register(u.Login, "blub");
     }
 }
コード例 #9
0
 public void TestLogin()
 {
     using (var persistence = GetPersistence())
     {
         persistence.CreateUser("bla", "blub");
         var s = new DiskServiceImpl(persistence);
         var user = s.Login("bla", "blub");
         Assert.AreEqual("bla", user.Login);
         Assert.AreEqual("blub", user.HashedPassword);
     }
 }
コード例 #10
0
 public void TestDisksEmpty()
 {
     using (var persistence = GetPersistenceWithUser())
     {
         var s = new DiskServiceImpl(persistence);
         Assert.AreEqual(0, s.Disks(_userDto).Count);
     }
 }
コード例 #11
0
        public void TestUpdateDisk()
        {
            using (var persistence = GetPersistence())
            {
                var user = persistence.CreateUser(_userDto.Login, _userDto.HashedPassword);

                var disk = persistence.CreateDisk(user, new DiskOptionsDto());
                disk.LocalVersion = 10;
                disk.LastServerVersion = 10;
                persistence.UpdateDisk(disk);

                var s = new DiskServiceImpl(persistence);

                disk.NewestBlock = 77;
                s.UpdateDisk(user, disk);
                Assert.AreEqual(77, s.Disks(user).First().NewestBlock);
            }
        }
コード例 #12
0
 public void TestLoginFail()
 {
     using (var persistence = GetPersistence())
     {
         persistence.CreateUser("bla", "test");
         var s = new DiskServiceImpl(persistence);
         s.Login("bla", "blub");
     }
 }
コード例 #13
0
        public void TestSynchronizationStateUpToDate()
        {
            using (var persistence = GetPersistence())
            {
                var user = persistence.CreateUser(_userDto.Login, _userDto.HashedPassword);
                persistence.CreateDisk(user, new DiskOptionsDto());

                var s = new DiskServiceImpl(persistence);

                var clonedDisk = s.Disks(user).First();
                Assert.AreEqual(SynchronizationState.UpToDate, s.FetchSynchronizationState(user, clonedDisk));
            }
        }
コード例 #14
0
 public void TestDisks()
 {
     using (var persistence = GetPersistenceWithUser())
     {
         var disk = new DiskDto { UserId = _userDto.Id, Id = 1 };
         persistence.CreateDisk(_userDto, new DiskOptionsDto());
         var s = new DiskServiceImpl(persistence);
         Assert.AreEqual(1, s.Disks(_userDto).Count);
         Assert.AreEqual(disk.Id, s.Disks(_userDto).First().Id);
     }
 }
コード例 #15
0
        public void TestReadWriteOptions()
        {
            using (var persistence = GetPersistence())
            {
                var user = persistence.CreateUser(_userDto.Login, _userDto.HashedPassword);

                var disk = persistence.CreateDisk(user, new DiskOptionsDto());
                disk.LocalVersion = 10;
                disk.LastServerVersion = 10;
                persistence.UpdateDisk(disk);

                var s = new DiskServiceImpl(persistence);

                var b = new byte[] { 1, 2, 3 };

                s.SetDiskOptions(user, disk, new DiskOptionsDto { SerializedFileSystemOptions = b });
                var actual = s.GetDiskOptions(user, disk);
                Assert.AreEqual(b.Length, actual.SerializedFileSystemOptions.Length);
                Assert.AreEqual(1, actual.SerializedFileSystemOptions[0]);
                Assert.AreEqual(2, actual.SerializedFileSystemOptions[1]);
                Assert.AreEqual(3, actual.SerializedFileSystemOptions[2]);
            }
        }
コード例 #16
0
 public void TestRegistration()
 {
     using (var persistence = GetPersistence())
     {
         var s = new DiskServiceImpl(persistence);
         var user = s.Register("bla", "blub");
         Assert.AreEqual("bla", user.Login);
         Assert.AreEqual("blub", user.HashedPassword);
         Assert.IsFalse(persistence.LoginFree("bla"));
     }
 }
コード例 #17
0
 public void TestRegisterAndLogin()
 {
     using (var persistence = GetPersistence())
     {
         var s = new DiskServiceImpl(persistence);
         s.Register(_userDto.Login, _userDto.HashedPassword);
         var user = s.Login(_userDto.Login, _userDto.HashedPassword);
         Assert.IsNotNull(user);
     }
 }
コード例 #18
0
        public void TestSynchronizationStateRemoteChanges()
        {
            using (var persistence = GetPersistence())
            {
                var user = persistence.CreateUser(_userDto.Login, _userDto.HashedPassword);

                var disk = persistence.CreateDisk(user, new DiskOptionsDto());
                disk.LocalVersion = 10;
                disk.LastServerVersion = 10;
                persistence.UpdateDisk(disk);

                var s = new DiskServiceImpl(persistence);

                var clonedDisk = new DiskDto { LastServerVersion = 9, LocalVersion = 9, UserId = user.Id, Id = disk.Id };
                Assert.AreEqual(SynchronizationState.RemoteChanges, s.FetchSynchronizationState(user, clonedDisk));
            }
        }
コード例 #19
0
 public void TestDeleteDisks()
 {
     using (var persistence = GetPersistence())
     {
         var user = persistence.CreateUser(_userDto.Login, _userDto.HashedPassword);
         var disk = persistence.CreateDisk(user, new DiskOptionsDto());
         var s = new DiskServiceImpl(persistence);
         Assert.IsTrue(s.DeleteDisk(user, disk));
         Assert.AreEqual(0, s.Disks(user).Count);
     }
 }