예제 #1
0
        public void CreateOrder_Throw_Exception_If_Orderref_Exists()
        {
            var institution = UsingDbContext(ctx => ctx.Institution.Add(InitFakeEntity.GetFakeInstitution()));
            var adminEntity = InitFakeEntity.GetFakeAdmin();

            adminEntity.InstitutionId = institution.Id;
            var   admin = UsingDbContext(ctx => ctx.Admin.Add(adminEntity));
            Order order = InitFakeEntity.GetFakeOrder();

            order.UserId = admin.UserId;
            UsingDbContext(ctx => ctx.Order.Add(order));
            OrderDto createOrder = new OrderDto()
            {
                DeliveryCharge = 1000,
                Discount       = 1000,
                OrderRef       = "1234567",
                Subtotal       = 1000,
                Timestamp      = DateTime.Now,
                Total          = 10000,
                TotalQuantity  = 100,
                UserId         = admin.UserId
            };

            UserFriendlyException ex = Should.Throw <UserFriendlyException>(
                () => _orderAppService.CreateOrder(createOrder)
                );

            Assert.True(ex != null);
        }
예제 #2
0
        public void GetClassInfoTeachers_Should_Return_Correct_Number_Of_Records_And_SingletonPage_Is_Not_Null()
        {
            Institution institution = UsingDbContext(ctx => ctx.Institution.First());

            ClassInfo classInfo = new ClassInfo
            {
                Name            = "Class2",
                ReminderInterva = 180,
                InstitutionId   = institution.Id,
                DateCreated     = DateTime.Now
            };

            for (int i = 0; i < 10; i++)
            {
                Admin admin = InitFakeEntity.GetFakeAdmin();
                admin.UserName = "******" + i;
                classInfo.Admins.Add(admin);
            }
            ClassInfo classInfo2 = UsingDbContext(c => c.ClassInfo.Add(classInfo));

            var result = _classAppService.GetClassInfoTeachers(classInfo2.Id, 1, 10);

            result.CurrentPage.ShouldBe(1);
            result.ListData.Count.ShouldBe(10);
            result.TotalPages.ShouldBe(1);
        }
예제 #3
0
        public void UpdateInstitution_Return_True_With_Admins()
        {
            var institutionTemp = InitFakeEntity.GetFakeInstitution();
            var admin           = InitFakeEntity.GetFakeAdmin();

            institutionTemp.Admins.Add(admin);

            var            institution    = UsingDbContext(ctx => ctx.Institution.Add(institutionTemp));
            InstitutionOut getInstitution = new InstitutionOut()
            {
                Id       = institution.Id,
                District = "abssssss",
                Name     = "brian_test",
                Address  = "shanghai",
                Tel      = "1"
            };

            var result = _institutionAppService.Update(getInstitution);

            var resultInstitution = UsingDbContext(
                ctx => ctx.Institution.Include(x => x.Admins).First(x => x.Id == institution.Id
                                                                    ));


            result.ShouldBe(true);
            resultInstitution.District.ShouldBe(getInstitution.District);
            resultInstitution.Name.ShouldBe(getInstitution.Name);
            resultInstitution.Address.ShouldBe(getInstitution.Address);
            resultInstitution.Admins.Count.ShouldBe(1);
        }
예제 #4
0
        public void DeleteUsersClassInfo_Return_True_If_Success()
        {
            var instituionTemp = InitFakeEntity.GetFakeInstitution();
            var institution    = UsingDbContext(ctx => ctx.Institution.Add(instituionTemp));



            Admin admin = InitFakeEntity.GetFakeAdmin();

            admin.InstitutionId = institution.Id;
            admin.UserType      = UserType.Teacher;

            ClassInfo classInfoTemp = new ClassInfo
            {
                Name            = "Class2111",
                ReminderInterva = 180,
                InstitutionId   = institution.Id,
                DateCreated     = DateTime.Now
            };

            UsingDbContext(ctx =>
            {
                ctx.Admin.Add(admin);
                classInfoTemp.Admins.Add(admin);
                ctx.ClassInfo.Add(classInfoTemp);
            });
            var adminResult = UsingDbContext(ctx => ctx.Admin.Include(x => x.Classes).Single(x => x.UserName == admin.UserName));
            var classInfo2  = UsingDbContext(ctx => ctx.ClassInfo.Include(x => x.Admins).Single(x => x.Name == classInfoTemp.Name));
            var result      = _classAppService.DeleteUsersClassInfo(classInfo2.Id, adminResult.UserId);

            result.ShouldBe(true);
        }
예제 #5
0
        public void AllocationClassInfoToTeacher_Return_False_If_User_Already_Has_The_Class()
        {
            var   instituionTemp = InitFakeEntity.GetFakeInstitution();
            var   institution    = UsingDbContext(ctx => ctx.Institution.Add(instituionTemp));
            Admin admin          = InitFakeEntity.GetFakeAdmin();

            admin.UserType      = UserType.Teacher;
            admin.InstitutionId = institution.Id;

            ClassInfo classInfoTemp = new ClassInfo
            {
                Name            = "Class2111",
                ReminderInterva = 180,
                InstitutionId   = institution.Id,
                DateCreated     = DateTime.Now
            };

            UsingDbContext(ctx =>
            {
                ctx.Admin.Add(admin);
                classInfoTemp.Admins.Add(admin);
                ctx.ClassInfo.Add(classInfoTemp);
            });
            var  adminResult = UsingDbContext(ctx => ctx.Admin.Include(x => x.Classes).Single(x => x.UserName == admin.UserName));
            var  classInfo   = UsingDbContext(ctx => ctx.ClassInfo.Include(x => x.Admins).Single(x => x.Name == classInfoTemp.Name));
            bool b           = _classAppService.AllocationClassInfoToTeacher(classInfo.Id, adminResult.UserId);

            b.ShouldBe(false);
        }
예제 #6
0
        public void Login_Return_Success_If_Account_Lock_And_LockTime_Expire()
        {
            Admin admin = InitFakeEntity.GetFakeAdmin();

            UsingDbContext(ctx => ctx.Admin.Add(admin));
            _iAdminAppSerice.Login(admin.UserName, "1");
            _iAdminAppSerice.Login(admin.UserName, "1");
            var result = _iAdminAppSerice.Login(admin.UserName, "1");
            var admin2 = UsingDbContext(ctx => ctx.Admin.FirstOrDefault(x => x.UserName == admin.UserName));

            result.LoginResult.ShouldBe(LoginResult.AccountLock);
            Assert.True(result.LockMintues > 0);
            admin2.AccessFailedCount.ShouldBe(3);
            UsingDbContext(ctx =>
            {
                var a = ctx.Admin.FirstOrDefault(x => x.UserName == admin.UserName);
                if (a == null)
                {
                    return;
                }
                if (a.LastLoginDate.HasValue)
                {
                    a.LastLoginDate = a.LastLoginDate.Value.AddMinutes(-31);
                }
            });
            result = _iAdminAppSerice.Login(admin.UserName, admin.Password);
            result.ErrorCount.ShouldBe(0);
            result.LockMintues.ShouldBe(0);
            result.LoginResult.ShouldBe(LoginResult.Success);
        }
예제 #7
0
        public void CreateOrder_Return_Ture_If_Success()
        {
            var institution = UsingDbContext(ctx => ctx.Institution.Add(InitFakeEntity.GetFakeInstitution()));
            var adminEntity = InitFakeEntity.GetFakeAdmin();

            adminEntity.InstitutionId = institution.Id;
            var      admin = UsingDbContext(ctx => ctx.Admin.Add(adminEntity));
            OrderDto order = new OrderDto()
            {
                DeliveryCharge = 1000,
                Discount       = 1000,
                OrderRef       = "1234567",
                Subtotal       = 1000,
                Timestamp      = DateTime.Now,
                Total          = 10000,
                TotalQuantity  = 100,
                UserId         = admin.UserId
            };

            var result      = _orderAppService.CreateOrder(order);
            var orderResult = UsingDbContext(ctx => ctx.Order.First());

            Assert.True(result);
            Assert.True(orderResult.Id > 0);
        }
예제 #8
0
        public void CheckUserName_Return_False_If_Found()
        {
            Admin admin = InitFakeEntity.GetFakeAdmin();

            UsingDbContext(ctx => ctx.Admin.Add(admin));
            var result = _iAdminAppSerice.CheckAdminUserName(admin.UserName);

            result.ShouldBe(false);
        }
예제 #9
0
        public void UpdatePwd_Throw_If_OldPwd_Error()
        {
            Admin  admin             = InitFakeEntity.GetFakeAdmin();
            string pwd               = "1112221";
            var    admin2            = UsingDbContext(ctx => ctx.Admin.Add(admin));
            UserFriendlyException ex = Should.Throw <UserFriendlyException>(() => _iAdminAppSerice.UpdatePwd(admin2.UserId, pwd, pwd));

            Assert.True(ex != null);
        }
예제 #10
0
        public void GetAdmin_Return_Entity_If_Found()
        {
            Admin admin  = InitFakeEntity.GetFakeAdmin();
            Admin admin2 = UsingDbContext(ctx => ctx.Admin.Add(admin));
            var   result = _iAdminAppSerice.GetAdmin(admin2.UserId);

            Assert.True(result.Id > 0);
            result.UserId.ShouldBe(admin2.UserId);
        }
예제 #11
0
        public void AllocationClassInfoToTeacher_Return_False_If_Class_Not_Exists()
        {
            Institution institution = UsingDbContext(ctx => ctx.Institution.First());
            Admin       admin       = InitFakeEntity.GetFakeAdmin();

            admin.InstitutionId = institution.Id;
            Admin adminResult = UsingDbContext(c => c.Admin.Add(admin));
            bool  b           = _classAppService.AllocationClassInfoToTeacher(100, adminResult.UserId);

            b.ShouldBe(false);
        }
예제 #12
0
        public void DeleteAdmin_Return_True_If_Success()
        {
            var   admin  = InitFakeEntity.GetFakeAdmin();
            Admin admin2 = UsingDbContext(ctx => ctx.Admin.Add(admin));

            _iAdminAppSerice.DeleteAdmin(admin2.UserId);
            var temp = UsingDbContext(ctx => ctx.Admin.FirstOrDefault(x => x.UserId == admin2.UserId));

            temp.IsDelete.ShouldBe(true);
            Assert.True(temp.Id > 0);
        }
예제 #13
0
        public void Login_Return_Login_Success_If_Right()
        {
            Admin admin = InitFakeEntity.GetFakeAdmin();

            UsingDbContext(ctx => ctx.Admin.Add(admin));
            var result = _iAdminAppSerice.Login(admin.UserName, admin.Password);

            result.ErrorCount.ShouldBe(0);
            result.LockMintues.ShouldBe(0);
            result.LoginResult.ShouldBe(LoginResult.Success);
        }
예제 #14
0
        public void UpdatePwd_Return_True_If_Success()
        {
            Admin  admin  = InitFakeEntity.GetFakeAdmin();
            string pwd    = "1111";
            var    admin2 = UsingDbContext(ctx => ctx.Admin.Add(admin));
            var    result = _iAdminAppSerice.UpdatePwd(admin2.UserId, admin2.Password, pwd);
            var    admin3 = UsingDbContext(ctx => ctx.Admin.First((x => x.UserId == admin2.UserId)));

            admin3.Password.ShouldBe(pwd);
            result.ShouldBe(true);
        }
예제 #15
0
        public void Login_Update_AccessFailedCount_2_If_PwdError_Count_2()
        {
            Admin admin = InitFakeEntity.GetFakeAdmin();

            UsingDbContext(ctx => ctx.Admin.Add(admin));
            _iAdminAppSerice.Login(admin.UserName, "1");
            var result = _iAdminAppSerice.Login(admin.UserName, "1");
            var admin2 = UsingDbContext(ctx => ctx.Admin.FirstOrDefault(x => x.UserName == admin.UserName));

            result.LoginResult.ShouldBe(LoginResult.PwdError);
            admin2.AccessFailedCount.ShouldBe(2);
        }
예제 #16
0
        public void AllocationClassInfoToTeacher_Return_True_If_Success()
        {
            Institution institution = UsingDbContext(ctx => ctx.Institution.First());
            Admin       admin       = InitFakeEntity.GetFakeAdmin();

            admin.InstitutionId = institution.Id;
            Admin     adminResult = UsingDbContext(c => c.Admin.Add(admin));
            ClassInfo classInfo   = UsingDbContext(ctx => ctx.ClassInfo.First());
            bool      b           = _classAppService.AllocationClassInfoToTeacher(classInfo.Id, adminResult.UserId);

            b.ShouldBe(true);
        }
예제 #17
0
        public void GetOrderByOrderRef_Should_Return_Correct_Number_Of_Records()
        {
            Admin admin = UsingDbContext(ctx => ctx.Admin.Add(InitFakeEntity.GetFakeAdmin()));
            Order order = InitFakeEntity.GetFakeOrder();

            order.OrderRef = Util.CreateOrderRef();
            order.UserId   = admin.UserId;
            var      reult    = UsingDbContext(ctx => ctx.Order.Add(order));
            OrderDto orderDto = _orderAppService.GetOrderByOrderRef(order.OrderRef);

            orderDto.OrderRef.ShouldBe(order.OrderRef);
        }
예제 #18
0
        public void Login_Return_PwdError_If_PwdError()
        {
            Admin admin = InitFakeEntity.GetFakeAdmin();

            UsingDbContext(ctx => ctx.Admin.Add(admin));
            var result = _iAdminAppSerice.Login(admin.UserName, "1");
            var admin2 = UsingDbContext(ctx => ctx.Admin.FirstOrDefault(x => x.UserName == admin.UserName));

            result.ErrorCount.ShouldBe(0);
            result.LockMintues.ShouldBe(0);
            result.LoginResult.ShouldBe(LoginResult.PwdError);
            admin2.AccessFailedCount.ShouldBe(1);
        }
예제 #19
0
        public void CreateClassInfo_Return_0_If_The_User_Not_Fount_Institution()
        {
            Admin       admin     = UsingDbContext(ctx => ctx.Admin.Add(InitFakeEntity.GetFakeAdmin()));
            ClassInfoIn classInfo = new ClassInfoIn
            {
                Name            = "Brian",
                ReminderInterva = 180,
                UserId          = admin.UserId
            };
            var result = _classAppService.CreateClassInfo(classInfo);

            result.ShouldBe(0);
        }
예제 #20
0
        public void Login_Return_AccountLock_If_PwdError_Count_3()
        {
            Admin admin = InitFakeEntity.GetFakeAdmin();

            UsingDbContext(ctx => ctx.Admin.Add(admin));
            _iAdminAppSerice.Login(admin.UserName, "1");
            _iAdminAppSerice.Login(admin.UserName, "1");
            var result = _iAdminAppSerice.Login(admin.UserName, "1");
            var admin2 = UsingDbContext(ctx => ctx.Admin.FirstOrDefault(x => x.UserName == admin.UserName));

            result.LoginResult.ShouldBe(LoginResult.AccountLock);
            Assert.True(result.LockMintues > 0);
            admin2.AccessFailedCount.ShouldBe(3);
        }
예제 #21
0
        public void GetAllAdmin__Should_Return_Correct_Number_Of_Records()
        {
            for (int i = 0; i < 8; i++)
            {
                Admin admin = InitFakeEntity.GetFakeAdmin();
                admin.UserName = admin.UserName + i.ToString();
                UsingDbContext(ctx => ctx.Admin.Add(admin));
            }
            var count  = UsingDbContext(ctx => ctx.Admin.Count());
            var result = _iAdminAppSerice.GetAllAdmin(1);

            result.ListData.Count.ShouldBe(count);
            result.CurrentPage.ShouldBe(1);
            result.TotalPages.ShouldBe(1);
        }
예제 #22
0
        public void AllocationClassInfoToTeacher_Return_False_If_User_Institution_Not_Equals_Class()
        {
            Institution institution  = InitFakeEntity.GetFakeInstitution();
            var         institution2 = UsingDbContext(ctx => ctx.Institution.Add(institution));
            Admin       admin        = InitFakeEntity.GetFakeAdmin();

            admin.InstitutionId = institution2.Id;
            admin.UserType      = UserType.Teacher;

            Admin     adminResult = UsingDbContext(c => c.Admin.Add(admin));
            ClassInfo classInfo   = UsingDbContext(ctx => ctx.ClassInfo.First());
            bool      b           = _classAppService.AllocationClassInfoToTeacher(classInfo.Id, adminResult.UserId);

            b.ShouldBe(false);
        }
예제 #23
0
        public void UpdateOrderPaid_Return_Ture_If_Success()
        {
            Admin admin = UsingDbContext(ctx => ctx.Admin.Add(InitFakeEntity.GetFakeAdmin()));
            Order order = InitFakeEntity.GetFakeOrder();

            order.OrderRef = Util.CreateOrderRef();
            order.UserId   = admin.UserId;
            UsingDbContext(ctx => ctx.Order.Add(order));
            bool result = _orderAppService.UpdateOrderPaid(order.OrderRef, true);

            Order orderResult = UsingDbContext(ctx => ctx.Order.FirstOrDefault(x => x.OrderRef == order.OrderRef));

            Assert.True(result);
            Assert.True(orderResult.Paid);
        }
예제 #24
0
        public void SearchAdminPaination_Should_Return_Correct_Number_Of_Records_If_UserName_Null_And_UserType_Is_Teacher()
        {
            var userName = "******";

            for (int i = 0; i < 8; i++)
            {
                Admin admin = InitFakeEntity.GetFakeAdmin();
                admin.UserName = userName + i;
                admin.UserType = UserType.Teacher;
                UsingDbContext(ctx => ctx.Admin.Add(admin));
            }
            var result = _iAdminAppSerice.SearchAdminPaination(1, null, null);

            result.CurrentPage.ShouldBe(1);
            result.ListData.Count.ShouldBe(10);
            result.TotalPages.ShouldBe(1);
        }
예제 #25
0
        public void SearchAdminPaination_Return_Empty_If_UserName_Not_Exists_And_UserType_Is_Admin()
        {
            var userName = "******";

            for (int i = 0; i < 20; i++)
            {
                UserType userType = i < 9 ? UserType.Admin : UserType.Teacher;
                Admin    admin    = InitFakeEntity.GetFakeAdmin();
                admin.UserName = userName + i;
                admin.UserType = userType;
                UsingDbContext(ctx => ctx.Admin.Add(admin));
            }
            var result = _iAdminAppSerice.SearchAdminPaination(1, (int)UserType.Admin, "aaaaa");

            result.CurrentPage.ShouldBe(0);
            result.ListData.Count.ShouldBe(0);
            result.TotalPages.ShouldBe(0);
        }
예제 #26
0
        public void SearchAdminPaination_Return_10_If_UserName_Exists()
        {
            var userName = "******";

            for (int i = 0; i < 10; i++)
            {
                Admin admin = InitFakeEntity.GetFakeAdmin();
                admin.UserName = userName + i;
                UsingDbContext(ctx => ctx.Admin.Add(admin));
            }
            var list = UsingDbContext(ctx => ctx.Admin.Where(x => x.UserName.Contains(userName)).Count());

            list.ShouldBe(10);
            var result = _iAdminAppSerice.SearchAdminPaination(1, null, userName);

            result.CurrentPage.ShouldBe(1);
            result.ListData.Count.ShouldBe(10);
            result.TotalPages.ShouldBe(1);
        }
예제 #27
0
        public void GetInstitutionOrderList_Should_Return_Correct_Number_Of_Records_Page_Not_Null()
        {
            var institution = UsingDbContext(ctx => ctx.Institution.Add(InitFakeEntity.GetFakeInstitution()));
            var adminEntity = InitFakeEntity.GetFakeAdmin();

            adminEntity.InstitutionId = institution.Id;
            var admin = UsingDbContext(ctx => ctx.Admin.Add(adminEntity));

            for (int i = 0; i < 10; i++)
            {
                Order order = InitFakeEntity.GetFakeOrder();
                order.UserId    = admin.UserId;
                order.OrderRef += i;
                UsingDbContext(ctx => ctx.Order.Add(order));
            }
            var result = _orderAppService.GetInstitutionOrderList(institution.Id, 1, 10);

            result.CurrentPage.ShouldBe(1);
            result.TotalPages.ShouldBe(1);
            result.ListData.Count.ShouldBe(10);
        }
예제 #28
0
        public void GetAll_Should_Should_Return_Correct_Number_Of_Records()
        {
            var institution = UsingDbContext(ctx => ctx.Institution.Add(InitFakeEntity.GetFakeInstitution()));
            var adminEntity = InitFakeEntity.GetFakeAdmin();

            adminEntity.InstitutionId = institution.Id;
            var admin = UsingDbContext(ctx => ctx.Admin.Add(adminEntity));

            for (int i = 0; i < 10; i++)
            {
                Order order = InitFakeEntity.GetFakeOrder();
                order.UserId    = admin.UserId;
                order.OrderRef += i;
                UsingDbContext(ctx => ctx.Order.Add(order));
            }

            PaginationDataList <OrderDto> list = _orderAppService.GetAll(1, null);

            list.CurrentPage.ShouldBe(1);
            list.ListData.Count.ShouldBe(10);
            list.TotalPages.ShouldBe(1);
        }
예제 #29
0
 public void GetAllInstitutionIdStudent_Should_Return_Correct_Number_Of_Records()
 {
     #region Arrange Insert data
     var   instituion = InitFakeEntity.GetFakeInstitution();
     Admin admin      = InitFakeEntity.GetFakeAdmin();
     admin.UserName = "******";
     Admin admin2 = InitFakeEntity.GetFakeAdmin();
     admin2.UserName = "******";
     instituion.Admins.Add(admin);
     instituion.Admins.Add(admin2);
     Random random = new Random();
     int    count  = 0;
     for (int i = 0; i < 5; i++)
     {
         ClassInfo classInfo = new ClassInfo
         {
             Name            = "ClassTest" + i,
             ReminderInterva = 180 + i,
             DateCreated     = DateTime.Now
         };
         int len = random.Next(5, 10);
         count += len;
         for (int j = 0; j < len; j++)
         {
             Student student = InitFakeEntity.GetFakeStudent();
             student.UserName = "******" + i + "-" + j;
             classInfo.Students.Add(student);
         }
         classInfo.Admins.Add(i % 2 == 0 ? admin : admin2);
         instituion.ClassInfos.Add(classInfo);
     }
     var institution2 = UsingDbContext(ctx => ctx.Institution.Add(instituion));
     #endregion
     var result = _institutionAppService.GetAllInstitutionIdStudent(institution2.Id, 1, count);
     result.TotalPages.ShouldBe(1);
     result.CurrentPage.ShouldBe(1);
     result.ListData.Count.ShouldBe(count);
 }
예제 #30
0
        public void GetAllInstitutionAdmin__Should_Return_Correct_Number_Of_Records()
        {
            var institution = new Institution
            {
                Address  = "上海",
                District = "浦东新区",
                Name     = "FirstInstitution2",
                Tel      = "18817617807"
            };

            for (int i = 0; i < 10; i++)
            {
                Admin admin = InitFakeEntity.GetFakeAdmin();
                admin.UserName = admin.UserName + i.ToString();
                institution.Admins.Add(admin);
            }
            var institution2 = UsingDbContext(ctx => ctx.Institution.Add(institution));
            var result       = _iAdminAppSerice.GetAllInstitutionAdmin(1, institution2.Id);

            result.ListData.Count.ShouldBe(10);
            result.CurrentPage.ShouldBe(1);
            result.TotalPages.ShouldBe(1);
        }