示例#1
0
        public void TryEnterLogicTest()
        {
            var user = data.Users.Data.First();

            Assert.AreSame(user, manager.FindUserByLoginPassword(user.Login, user.Password));
            Assert.AreEqual(null, manager.FindUserByLoginPassword(user.Login + MoqDataGenerator.GetRandomString(1), user.Password));
        }
示例#2
0
        public void TryEnterTest()
        {
            var user   = data.Users.Data.First();
            var result = userManager.TryEnter(user.Login, user.Password);

            Assert.AreSame(user, result);
            result = userManager.TryEnter(user.Login, user.Password + MoqDataGenerator.GetRandomString(10));
            Assert.AreEqual(null, result);
        }
示例#3
0
 private Program CreateProgram(int id) =>
 new Program
 {
     ActualVersion = MoqDataGenerator.GetRandomNumber(10, 100),
     Code          = MoqDataGenerator.GetRandomString(100),
     Name          = MoqDataGenerator.GetRandomString(10),
     ProgramID     = id,
     ProgramRobots = new List <ProgramRobot>()
 };
示例#4
0
        public async Task AddUserTest()
        {
            int amount = data.Users.Data.Count();
            var user   = new User
            {
                Login    = MoqDataGenerator.GetRandomString(10),
                Password = MoqDataGenerator.GetRandomString(10),
                Nickname = MoqDataGenerator.GetRandomString(10)
            };
            await userManager.AddUserAsync(user);

            Assert.AreEqual(amount + 1, data.Users.Data.Count());
            Assert.AreSame(user, data.Users.Data.Last());
        }
示例#5
0
        public void CreateUserLogicTest()
        {
            var user = new User
            {
                Login    = MoqDataGenerator.GetRandomString(10),
                Password = MoqDataGenerator.GetRandomString(10)
            };
            int amount = data.Users.Data.Count();

            manager.CreateUser(user.Login, user.Password);
            Assert.AreEqual(amount + 1, data.Users.Data.Count());
            Assert.AreEqual(user.Login, data.Users.Data.Last().Login);
            Assert.AreEqual(user.Password, data.Users.Data.Last().Password);
        }
        public async Task CreateAccountTest()
        {
            int    amount  = data.Accounts.Data.Count();
            string name    = MoqDataGenerator.GetRandomString(10);
            int    sum     = MoqDataGenerator.GetRandomNumber(10, 100);
            var    account = await accountManager.CreateAccount(name, sum);

            var last = data.Accounts.Data.Last();

            Assert.AreSame(account, last);
            Assert.AreEqual(amount + 1, data.Accounts.Data.Count());
            Assert.AreEqual(name, last.Name);
            Assert.AreEqual(sum, last.TargetSum);
        }
        public async Task EntranceTest()
        {
            var amount = context.Users.Count();
            var user   = new User
            {
                Login    = MoqDataGenerator.GetRandomString(10),
                Password = MoqDataGenerator.GetRandomString(10),
            };

            context.Users.Add(user);
            await context.SaveChangesAsync();

            try
            {
                using (var wb = new WebClient())
                {
                    // хороший случай
                    wb.Encoding = Encoding.UTF8;
                    var data = new NameValueCollection();
                    data["Login"]    = user.Login;
                    data["Password"] = user.Password;
                    var            response = wb.UploadValues(serverUrl + "/api/user/entrance", "POST", data);
                    string         json     = Encoding.Default.GetString(response);
                    EntranceOutput resp     = JsonConvert.DeserializeObject <EntranceOutput>(json);
                    Assert.AreEqual(resp.Token, user.UserID);

                    // плохой случай
                    bool failed = false;
                    data["Login"]    = user.Login + MoqDataGenerator.GetRandomString(10);
                    data["Password"] = user.Password;
                    try
                    {
                        response = wb.UploadValues(serverUrl + "/api/user/entrance", "POST", data);
                    }
                    catch (Exception e)
                    {
                        failed = true;
                    }
                    Assert.AreEqual(failed, true);
                }
            }
            finally
            {
                context.Users.Remove(user);
                await context.SaveChangesAsync();

                Assert.AreEqual(amount, context.Users.Count());
            }
        }
        public async Task CreatePaymentTest()
        {
            var user    = data.Users.Data.First();
            var account = data.Accounts.Data.First();
            var text    = MoqDataGenerator.GetRandomString(10);
            var value   = MoqDataGenerator.GetRandomNumber(1, 100);
            var date    = DateTime.Now;
            int amount  = data.Payments.Data.Count();
            await paymentManager.CreatePayment(text, date, user, account, value);

            Assert.AreEqual(amount + 1, data.Payments.Data.Count());
            var result = data.Payments.Data.Last();

            Assert.AreSame(result.User, user);
            Assert.AreSame(result.Account, account);
            Assert.AreEqual(text, result.Text);
            Assert.AreEqual(value, result.Value);
            Assert.AreEqual(date, result.Date);
        }
        public async Task RegistrationTest()
        {
            User last   = null;
            var  amount = context.Users.Count();

            try
            {
                using (var wb = new WebClient())
                {
                    wb.Encoding = Encoding.UTF8;
                    var data = new NameValueCollection();
                    var user = new User
                    {
                        Login    = MoqDataGenerator.GetRandomString(10),
                        Password = MoqDataGenerator.GetRandomString(10),
                        Nickname = MoqDataGenerator.GetRandomString(10),
                    };
                    data["Login"]    = user.Login;
                    data["Password"] = user.Password;
                    data["Nickname"] = user.Nickname;
                    var                response = wb.UploadValues(serverUrl + "/api/user/registration", "POST", data);
                    string             json     = Encoding.Default.GetString(response);
                    RegistrationOutput resp     = JsonConvert.DeserializeObject <RegistrationOutput>(json);
                    Assert.AreEqual(amount + 1, context.Users.Count());

                    last = context.Users.ToList().Last();
                    Assert.AreEqual(last.Login, user.Login);
                    Assert.AreEqual(last.Password, user.Password);
                    Assert.AreEqual(last.Nickname, user.Nickname);
                    Assert.AreEqual(last.UserID, resp.Token);
                }
            }
            finally
            {
                context.Users.Remove(last);
                await context.SaveChangesAsync();

                Assert.AreEqual(amount, context.Users.Count());
            }
        }
示例#10
0
        public void GetProgramApiTest()
        {
            /*
             * . создать программу
             * . получить и проверить программу
             * . удалить программу
             */

            var program = new Program
            {
                Code = MoqDataGenerator.GetRandomString(100),
                Name = MoqDataGenerator.GetRandomString(10)
            };

            context.Programs.Add(program);
            var amount = context.Programs.Count();

            context.SaveChanges();
            Assert.AreEqual(amount, context.Programs.Count() - 1);

            try
            {
                using (var wb = new WebClient())
                {
                    wb.Encoding = Encoding.UTF8;
                    var json = wb.DownloadString(serverUrl + "/api/GetProgram?programId=" + program.ProgramID);
                    var resp = JsonConvert.DeserializeObject <ProgramExport>(json);
                    Assert.AreEqual(resp.Name, program.Name);
                    Assert.AreEqual(resp.Code, program.Code);
                    Assert.AreEqual(resp.ProgramId, program.ProgramID);
                }
            }
            finally
            {
                context.Programs.Remove(program);
                context.SaveChanges();
                Assert.AreEqual(amount, context.Programs.Count());
            }
        }
示例#11
0
        private void CheckUpdateData()
        {
            // поменяем
            user.Login          = MoqDataGenerator.GetRandomString(10);
            user.Password       = MoqDataGenerator.GetRandomString(10);
            user.Nickname       = MoqDataGenerator.GetRandomString(10);
            account.Description = MoqDataGenerator.GetRandomString(10);
            account.Name        = MoqDataGenerator.GetRandomString(10);
            payment.Date        = DateTime.Now;
            payment.Text        = MoqDataGenerator.GetRandomString(10);
            payment.Value       = MoqDataGenerator.GetRandomNumber(1, 100);
            token.Value         = MoqDataGenerator.GetRandomString(11);

            // сохраним изменения в БД
            _context.Entry(user).State    = EntityState.Modified;
            _context.Entry(account).State = EntityState.Modified;
            _context.Entry(payment).State = EntityState.Modified;
            _context.Entry(token).State   = EntityState.Modified;
            _context.SaveChanges();

            // проверить, что наши экземпляры сущностей по-прежнему лежат в БД
            CheckEntitiesAreInDB();
        }
示例#12
0
        private void CheckUpdateData()
        {
            // поменяем все кроме ImageRecipe, ибо такие нужно не менять, а удалять
            program.Name = MoqDataGenerator.GetRandomString(10);
            programRobot.CurrentVersion = MoqDataGenerator.GetRandomNumber(10, 100);
            configuration.Port          = MoqDataGenerator.GetRandomNumber(10, 11111);
            user.Login            = MoqDataGenerator.GetRandomString(10);
            user.Password         = MoqDataGenerator.GetRandomString(10);
            robot.ActivationCode  = MoqDataGenerator.GetRandomNumber(0, 9999);
            robotCommand.Argument = MoqDataGenerator.GetRandomNumber(1, 100);
            robotCommand.Type     = MoqDataGenerator.GetRandomNumber(1, 100);

            // сохраним изменения в БД
            _context.Entry(program).State       = EntityState.Modified;
            _context.Entry(programRobot).State  = EntityState.Modified;
            _context.Entry(configuration).State = EntityState.Modified;
            _context.Entry(user).State          = EntityState.Modified;
            _context.Entry(robot).State         = EntityState.Modified;
            _context.Entry(robotCommand).State  = EntityState.Modified;
            _context.SaveChanges();

            // проверить, что наши экземпляры сущностей по-прежнему лежат в БД
            CheckEntitiesIsInDb();
        }
示例#13
0
        private async Task FillWithTestData()
        {
            // создаем объекты
            var user = new User
            {
                Login    = MoqDataGenerator.GetRandomString(10),
                Password = MoqDataGenerator.GetRandomString(10),
                Nickname = MoqDataGenerator.GetRandomString(10),
                UserID   = MoqDataGenerator.GetRandomNumber(1, 100)
            };

            var account = new Account
            {
                AccountID   = MoqDataGenerator.GetRandomNumber(1, 100),
                Name        = MoqDataGenerator.GetRandomString(10),
                Description = MoqDataGenerator.GetRandomString(100)
            };

            var payment = new Payment
            {
                Date      = DateTime.Now,
                PaymentID = MoqDataGenerator.GetRandomNumber(1, 100),
                Value     = MoqDataGenerator.GetRandomNumber(1, 1000),
                Text      = MoqDataGenerator.GetRandomString(1000)
            };

            var userAccount = new UserAccount
            {
                UserAccountID = MoqDataGenerator.GetRandomNumber(1, 100)
            };

            var token = new Token
            {
                Value = MoqDataGenerator.GetRandomString(10)
            };


            // устанавливаем связи
            account.UserAccounts = new List <UserAccount> {
                userAccount
            };
            account.Payments = new List <Payment> {
                payment
            };
            payment.User      = user;
            payment.UserID    = user.UserID;
            payment.Account   = account;
            user.UserAccounts = new List <UserAccount> {
                userAccount
            };
            user.Payments = new List <Payment> {
                payment
            };
            userAccount.User      = user;
            userAccount.Account   = account;
            userAccount.UserID    = user.UserID;
            userAccount.AccountID = account.AccountID;
            token.User            = user;
            token.UserID          = user.UserID;

            await Accounts.AddAsync(account);

            await Payments.AddAsync(payment);

            await Users.AddAsync(user);

            await UserAccounts.AddAsync(userAccount);

            await Tokens.AddAsync(token);
        }
示例#14
0
        private void FillWithTestData()
        {
            // создали по одной сущности в каждый из списков
            var user = new User
            {
                Login    = MoqDataGenerator.GetRandomString(10),
                Password = MoqDataGenerator.GetRandomString(10),
                UserID   = 1
            };
            var robot = new Robot
            {
                RobotID        = MoqDataGenerator.GetRandomNumber(1, 100),
                Configurations = new List <Configuration>(),
                ProgramRobots  = new List <ProgramRobot>(),
                ActivationCode = MoqDataGenerator.GetRandomNumber(1, 100)
            };
            var program = CreateProgram(id: 1);

            var configuration = new Configuration
            {
                ConfigurationID = MoqDataGenerator.GetRandomNumber(10, 100),
                Port            = MoqDataGenerator.GetRandomNumber(10, 11111)
            };
            var programRobot = new ProgramRobot
            {
                ProgramRobotID = MoqDataGenerator.GetRandomNumber(10, 100)
            };

            var image = new Image
            {
                ImageMimeType = MoqDataGenerator.GetRandomString(10),
                ImageData     = MoqDataGenerator.GetSomeBytes(),
                ImageID       = 1,
                Name          = MoqDataGenerator.GetRandomString(10)
            };

            var robotCommand = new RobotCommand
            {
                RobotCommandID = MoqDataGenerator.GetRandomNumber(10, 100),
                Type           = 0
            };

            // добавили связи между сущностями
            robot.Configurations.Add(configuration);
            robot.ProgramRobots.Add(programRobot);
            robot.User            = user;
            robot.UserID          = user.UserID;
            configuration.Robot   = robot;
            configuration.RobotID = robot.RobotID;
            program.ProgramRobots.Add(programRobot);
            program.Image               = image;
            program.ImageID             = image.ImageID;
            programRobot.Robot          = robot;
            programRobot.Program        = program;
            programRobot.RobotID        = robot.RobotID;
            programRobot.ProgramID      = program.ProgramID;
            programRobot.CurrentVersion = program.ActualVersion - 1;
            robotCommand.Argument       = program.ProgramID;
            robotCommand.Robot          = robot;
            robotCommand.RobotID        = robot.RobotID;

            // добавили сущности в списки сущностей
            Robots.Add(robot);
            Programs.Add(program);
            Configurations.Add(configuration);
            ProgramRobots.Add(programRobot);
            Users.Add(user);
            RobotCommands.Add(robotCommand);
            Images.Add(image);

            // добавили еще 4 программы для теста pagination
            for (var i = 0; i < 4; i++)
            {
                Programs.Add(CreateProgram(i + 2));
            }
        }