Ejemplo n.º 1
0
        public void Initialize()
        {
            //Initialize_data
            User user1 = new User() { Id = 1, Email = "123", CreatedTime = DateTime.Now, Name = "user1", NickName = "梁贵", Password = "******", };
            User user2 = new User() { Id = 2, Email = "123", CreatedTime = DateTime.Now, Name = "user2", NickName = "梁贵2", Password = "******", };
            _users = new List<User> { user1, user2 };

            Role role1 = new Role() { Id = 1, Name = "role1", Remark = "role1" };
            Role role2 = new Role() { Id = 2, Name = "role2", Remark = "role2" };
            _roles = new List<Role> { role1, role2 };
            user1.Roles = _roles;

            //Initialize_interface
            _unitOfWork = Substitute.For<IUnitOfWork>();
            _identityService = Substitute.For<IdentityService>(_unitOfWork);
            _userRepository = Substitute.For<IRepository<User, int>>();
            _roleRepository = Substitute.For<IRepository<Role, int>>();
            _userRepository.GetByKey(Arg.Any<int>()).ReturnsForAnyArgs(x => _users.Find(r => r.Id == (int)x[0]));
            _userRepository.Entities.Returns(_users.AsQueryable());

            _roleRepository.Entities.Returns(_roles.AsQueryable());
            _roleRepository.GetByKey(Arg.Any<int>()).Returns(x => _roles.Find(r => r.Id == (int)x[0]));
            _identityService.UserRepository.Returns(_userRepository);
            _identityService.RoleRepository.Returns(_roleRepository);
        }
Ejemplo n.º 2
0
        public void InfoTest()
        {
            User.Kill(App.CurrentPath, "info");

              using (var u = User.Create(ApplicationType.Desktop, App.CurrentPath, "info"))
              {
            // пользовательские параметры
            u.Info.Set(1000, "123");
            u.Info.Set(1001, "test");
            u.Info.Set(1000, "456");
            u.Info.Set(1005, "Это проверка");
              }

              using (var u = new User(App.CurrentPath, "info"))
              {
            Assert.AreEqual(u.Info[1005], "Это проверка");
            Assert.AreEqual(u.Info[1000], "456");
            Assert.AreEqual(u.Info[InfoId.Stat.TotalSessions], "1");
              }

              using (var u = new User(App.CurrentPath, "info"))
              {
            Assert.AreEqual(u.Info[InfoId.Stat.TotalSessions], "2");
              }
        }
Ejemplo n.º 3
0
        public void TestMethod1()
        {
            var user1 = new User { ID = 1, ID2 = 1, Name = "blqw", LoginName = "blqw1" };
            var user2 = new User { ID = 2, ID2 = 2, Name = "blqw", LoginName = "blqw2" };
            var user3 = new User { ID = 3, ID2 = 3, Name = "blqw", LoginName = "blqw3" };
            var user4 = new User { ID = 4, ID2 = 4, Name = "blqw", LoginName = "blqw4" };

            var db = CacheStore<User>.Instance;
            db.Add(user1);
            db.Add(user2);
            db.Add(user3);
            db.Add(user4);

            var u1 = db.Get(1, 1);
            Assert.AreEqual(u1, user1);
            var u2 = db.Get(it => it.LoginName, "blqw2");
            Assert.AreEqual(u2, user2);
            db.Remove(it => it.LoginName, "blqw3");
            var u3 = db.Get(3, 3);
            Assert.IsNull(u3);
            db.Remove(4, 4);
            var u4 = db.Get(4, 4);
            Assert.IsNull(u4);

        }
Ejemplo n.º 4
0
        public void PwdTest()
        {
            User.Kill(App.CurrentPath, "pwd");

              var u = User.Create(ApplicationType.Desktop, App.CurrentPath, "pwd", "123");

              try
              {
            u = new User(App.CurrentPath, "pwd");
            Assert.Fail("Что-то работает не так, т.к. на базе должен стоять пароль.");
              }
              catch
              {
              }

              u = new User(App.CurrentPath, "pwd", "123");
              u.SetPassword("test");

              var account = new Account();
              account.Name = "Проверочный счет pwd";
              u.Save(account);

              Assert.AreEqual(account.Id, 1);

              try
              {
            u = new User(App.CurrentPath, "pwd", "123");
            Assert.Fail("Что-то работает не так, т.к. пароль был изменен.");
              }
              catch
              {
              }

              u = new User(App.CurrentPath, "pwd", "test");
              u.SetPassword(null);

              u = new User(App.CurrentPath, "pwd");
        }
        public void GetMaxSalaryFromFirst()
        {
            var expectedData = 54000;
            var actualData = new User();

            //ToDo Add code for first list
            actualData = userListFirst.Find(x => x.Salary == userListFirst.Max(e => e.Salary));
            Assert.IsTrue(expectedData == actualData.Salary);
        }
        public void ReturnsTheFirstElementOrDefaultByNameNotOnList()
        {
            var actualData = new User();

            //ToDo Add code for second list
            //name Ldfsdfsfd
            actualData = userListSecond.FirstOrDefault(x => x.Name == "Ldfsdfsfd");

            Assert.IsTrue(actualData == null);
        }
        public void ReturnsTheFirstElementByNameNotOnList()
        {
            var actualData = new User();

            try
            {
                //ToDo Add code for second list
                //name Ldfsdfsfd
                actualData = userListSecond.First(x => x.Name == "Ldfsdfsfd");
                Assert.Fail();
            }
            catch (InvalidOperationException ie)
            {
                Assert.AreEqual("Sequence contains no matching element", ie.Message);
            }
            catch (Exception e)
            {
                Assert.Fail("Unexpected exception of type {0} caught: {1}", e.GetType(), e.Message);
            }
        }
 public void ReturnsOnlyElementByNameMax()
 {
     var actualData = new User();
     
     try
     {
         //ToDo Add code for second list
         //name Max
        actualData = userListSecond.Single(x => x.Name == "Max");
         Assert.Fail();
     }
     catch (InvalidOperationException ie)
     {
         Assert.AreEqual("Sequence contains more than one matching element", ie.Message);
     }
     catch (Exception e)
     {
         Assert.Fail("Unexpected exception of type {0} caught: {1}", e.GetType(), e.Message);
     }
 }