Пример #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);
     }
 }