Esempio n. 1
0
        public void TestAddGroupOwner()
        {
            var GroupID = 1;
            TestControllerBuilder builder    = new TestControllerBuilder();
            GroupController       controller = new GroupController();

            builder.InitializeController(controller);
            var controllerContext = new Mock <ControllerContext>();
            var session           = new Mock <HttpSessionStateBase>();
            var mockHttpContext   = new Mock <HttpContextBase>();

            //get session
            mockHttpContext.Setup(ctx => ctx.Session).Returns(session.Object);
            controllerContext.Setup(ctx => ctx.HttpContext).Returns(mockHttpContext.Object);
            controllerContext.Setup(p => p.HttpContext.Session["GroupID"]).Returns(GroupID);
            controller.ControllerContext = controllerContext.Object;
            var group = new Group();
            var db    = new cap21t4Entities();

            using (var scope = new TransactionScope())
            {
                var result1 = controller.AddGroupOwner(db.Groups.First().ID.ToString("1")) as RedirectResult;
                Assert.IsNull(result1);
            }
        }
Esempio n. 2
0
        public async Task TestInsertExcelSucess()
        {
            TestControllerBuilder builder    = new TestControllerBuilder();
            GroupController       controller = new GroupController();

            builder.InitializeController(controller);
            var db      = new cap21t4Entities();
            var context = new Mock <HttpContextBase>();
            var request = new Mock <HttpRequestBase>();
            var files   = new Mock <HttpFileCollectionBase>();
            var file    = new Mock <HttpPostedFileBase>();
            var server  = new Mock <HttpServerUtilityBase>();
            var session = new Mock <HttpSessionStateBase>();

            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);
            context.Setup(c => c.Request).Returns(request.Object);
            request.Setup(r => r.Files).Returns(files.Object);
            files.Setup(f => f["file"]).Returns(file.Object);
            context.Setup(c => c.Server).Returns(server.Object);
            file.Setup(f => f.ContentLength).Returns(1);
            file.Setup(f => f.ContentType).Returns("Excel");
            server.Setup(s => s.MapPath("~/Uploads/")).Returns("./Uploads/");
            context.Setup(ctx => ctx.Session).Returns(session.Object);
            await controller.InsertExcelData();
        }
Esempio n. 3
0
        public void TestViewMyGroup()
        {
            var controller = new GroupController();
            var result     = controller.Index() as ViewResult;
            var db         = new cap21t4Entities();

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(List <Group>));
            Assert.AreEqual(db.Groups.Where(x => x.GroupParent == null).Count(), ((List <Group>)result.Model).Count);
        }
Esempio n. 4
0
        public void TestEditGroupSuccessfully()
        {
            //Arange
            var   controller = new GroupController();
            var   user       = new Group();
            var   db         = new cap21t4Entities();
            Group edit       = db.Groups.First();

            edit.GroupName        = "Nhóm 1.5";
            edit.GroupDescription = "Mobile App";

            using (var scope = new TransactionScope())
            {
                Assert.IsTrue(edit.GroupName.ToString().Equals("Nhóm 1.5"));
                Assert.IsTrue(edit.GroupDescription.ToString().Equals("Mobile App"));
                var result1 = controller.Edit(db.Groups.First().ID.ToString()) as ViewResult;
                Assert.IsNotNull(result1);
            }
        }
Esempio n. 5
0
        public void TestAddGroupSuccessfully()
        {
            //Arange
            var controller = new GroupController();
            var user       = new Group();
            var db         = new cap21t4Entities();
            var group      = new Group()
            {
                ID               = 9999,
                GroupName        = "Cap team 4",
                GroupType        = false,
                GroupDescription = "test",
                GroupParent      = 76,
                CreatedDate      = DateTime.Now
            };

            db.Groups.Add(group);
            Assert.IsNotNull(group);
        }
Esempio n. 6
0
        public void TestEditGroupUnSuccessfullyWithBlankSpaceDescription()
        {
            //Arange
            var   controller = new GroupController();
            var   user       = new Group();
            var   db         = new cap21t4Entities();
            Group edit       = db.Groups.First();

            edit.GroupName        = "Nhóm 1.5";
            edit.GroupDescription = " ";

            using (var scope = new TransactionScope())
            {
                var result1 = controller.Edit(db.Groups.First().ID.ToString()) as ViewResult;
                Assert.IsNotNull(result1);

                System.Diagnostics.Trace.WriteLine("Error data format, please try again");
            }
        }
Esempio n. 7
0
        public void TestEditGroupUnSuccessfullyWithSpecialSymbolName()
        {
            //Arange
            var   controller = new GroupController();
            var   user       = new Group();
            var   db         = new cap21t4Entities();
            Group edit       = db.Groups.First();

            edit.GroupName        = "&^%$%$";
            edit.GroupDescription = "Mobile App";

            using (var scope = new TransactionScope())
            {
                Assert.IsTrue(edit.GroupName.ToString().Equals("&^%$%$"));
                Assert.IsTrue(edit.GroupDescription.ToString().Equals("Mobile App"));
                var result1 = controller.Edit(db.Groups.First().ID.ToString()) as ViewResult;
                Assert.IsNotNull(result1);

                System.Diagnostics.Trace.WriteLine("Error data format, please try again");
            }
        }