Ejemplo n.º 1
0
        //[TestMethod]
        public async void TestDeleteAllAsync()
        {
            var motherService = new MotherService();
            var users         = await motherService.ListUserAsync();

            foreach (MotherLibrary.User user in users)
            {
                var tasks = await motherService.ListTaskAsync(user.UserName);

                foreach (MotherLibrary.Task task in tasks)
                {
                    await motherService.DeleteTaskAsync(user.UserName, task.Date, task.Begin);
                }
                await motherService.DeleteUserAsync(user.UserName);
            }
            var progresses = await motherService.ListProgressAsync();

            foreach (Progress progress in progresses)
            {
                await motherService.DeleteProgressAsync(progress.ProgressName);
            }

            users = await motherService.ListUserAsync();

            Assert.AreEqual(0, users.Count);
            var taskss = await motherService.ListTasksAsync();

            Assert.AreEqual(0, taskss.Count);
            progresses = await motherService.ListProgressAsync();

            Assert.AreEqual(0, progresses.Count);
        }
Ejemplo n.º 2
0
        [TestMethod]          //Success
        public async Task TestUserServicesAsync()
        {
            var motherService = new MotherService();                 //声明服务

            var users = await motherService.ListUserAsync();         //初始时

            Assert.AreEqual(0, users.Count);

            var user1 = new MotherLibrary.User {
                UserName = "******", Password = "******"
            };
            var user2 = new MotherLibrary.User {
                UserName = "******", Password = "******"
            };
            var user3 = new MotherLibrary.User {
                UserName = "******", Password = "******"
            };
            await motherService.NewUserAsync(user1.UserName, user1.Password);

            await motherService.NewUserAsync(user2.UserName, user2.Password);

            await motherService.NewUserAsync(user3.UserName, user3.Password);               //插入3个测试用户

            users = await motherService.ListUserAsync();

            Assert.AreEqual(3, users.Count);                       //应有3个用户
            Assert.AreEqual("Test1", users[0].UserName);
            Assert.AreEqual("1", users[0].Password);
            Assert.AreEqual(0, users[0].TotalTime);

            Assert.AreEqual("Test2", users[1].UserName);
            Assert.AreEqual("2", users[1].Password);
            Assert.AreEqual(0, users[1].TotalTime);

            Assert.AreEqual("Test3", users[2].UserName);
            Assert.AreEqual("3", users[2].Password);
            Assert.AreEqual(0, users[2].TotalTime);


            users[0].Password  = "******";                 //修改用户数据
            users[0].TotalTime = 10;
            users[1].Password  = "******";
            users[1].TotalTime = 20;
            users[2].Password  = "******";
            users[2].TotalTime = 30;

            await motherService.UpdateUserAsync(users[0].UserName, users[0].Password, users[0].TotalTime);

            await motherService.UpdateUserAsync(users[1].UserName, users[1].Password, users[1].TotalTime);

            await motherService.UpdateUserAsync(users[2].UserName, users[2].Password, users[2].TotalTime);

            users = await motherService.ListUserAsync();       //确认修改的数据保存成功

            Assert.AreEqual("111", users[0].Password);
            Assert.AreEqual(10, users[0].TotalTime);
            Assert.AreEqual("222", users[1].Password);
            Assert.AreEqual(20, users[1].TotalTime);
            Assert.AreEqual("333", users[2].Password);
            Assert.AreEqual(30, users[2].TotalTime);


            Assert.AreEqual(3, users.Count);
            await motherService.DeleteUserAsync(users[0].UserName);          //删除测试用户

            await motherService.DeleteUserAsync(users[1].UserName);

            await motherService.DeleteUserAsync(users[2].UserName);


            users = await motherService.ListUserAsync();       //确认数量

            Assert.AreEqual(0, users.Count);
        }
        //[TestMethod]
        public async Task TestTaskServicesAsync()
        {
            var motherService = new MotherService();
            var users         = await motherService.ListUserAsync();



            var tasks = await motherService.ListTasksAsync();  //所有Tasks

            Assert.AreEqual(0, tasks.Count);


            var user1 = new User {
                UserName = "******", Password = "******"
            };                                                                //增加1个测试用户
            await motherService.NewUserAsync(user1.UserName, user1.Password);

            users = await motherService.ListUserAsync();

            Assert.AreEqual(1, users.Count);



            var task1 = new MotherLibrary.Task {
                UserId = users[0].Id, Date = 20180720, Begin = "10:59", DefaultTime = 60, Introduction = "test1"
            };
            var task2 = new MotherLibrary.Task {
                UserId = users[0].Id, Date = 20180721, Begin = "10:59", DefaultTime = 60, Introduction = "test2"
            };
            var task3 = new MotherLibrary.Task {
                UserId = users[0].Id, Date = 20180722, Begin = "10:59", DefaultTime = 60, Introduction = "test3"
            };


            var result1 = await motherService.NewTaskAsync(users[0].UserName, task1.Date, task1.Begin, task1.DefaultTime, task1.Introduction); //新建3个任务。

            var result2 = await motherService.NewTaskAsync(users[0].UserName, task2.Date, task2.Begin, task2.DefaultTime, task2.Introduction);

            var result3 = await motherService.NewTaskAsync(users[0].UserName, task3.Date, task3.Begin, task3.DefaultTime, task3.Introduction);

            Assert.AreEqual(true, result1);
            Assert.AreEqual(true, result2);
            Assert.AreEqual(true, result3);



            tasks = await motherService.ListTaskAsync(users[0].UserName);               //查看任务。

            Assert.AreEqual(3, tasks.Count);
            Assert.AreEqual(20180720, tasks[0].Date);
            Assert.AreEqual(20180721, tasks[1].Date);
            Assert.AreEqual(20180722, tasks[2].Date);


            await motherService.DeleteTaskAsync(users[0].UserName, tasks[0].Date, tasks[0].Begin);

            await motherService.DeleteTaskAsync(users[0].UserName, tasks[1].Date, tasks[1].Begin);

            await motherService.DeleteTaskAsync(users[0].UserName, tasks[2].Date, tasks[2].Begin);


            tasks = await motherService.ListTaskAsync(users[0].UserName);

            Assert.AreEqual(0, tasks.Count);

            users = await motherService.ListUserAsync();

            Assert.AreEqual(1, users.Count);

            await motherService.DeleteUserAsync(users[0].UserName);

            users = await motherService.ListUserAsync();

            Assert.AreEqual(0, users.Count);
        }