Beispiel #1
0
        public async Task IdTest()
        {
            UserContext _context = GetContext();

            _context.Document.Add(new Document()
            {
                Id      = "GRT47895347",
                GroupId = 1,
                UserId  = 1,
                Tags    = "Abc",
                File    = ""
            });
            _context.Document.Add(new Document()
            {
                Id      = "GRTfgfgf5",
                GroupId = 1,
                UserId  = 1,
                Tags    = "Arr",
                File    = ""
            });
            _context.Document.Add(new Document()
            {
                Id      = "GRT43765yuerfh",
                GroupId = 1,
                UserId  = 2,
                Tags    = "Abc; Bcd;",
                File    = ""
            });
            await _context.SaveChangesAsync();

            LogOut();
            IActionResult res = await controller.Id(1, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.AreEqual(((GroupModel)((ViewResult)res).Model).Id, 1);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["CanEdit"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsParticipant"]);
            res = await controller.Id(200, null);

            Assert.IsInstanceOf <NotFoundResult>(res);
            res = await controller.Id(2, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.IsInstanceOf <GroupModel>(((ViewResult)res).Model);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsParticipant"]);
            Assert.AreEqual(((GroupModel)((ViewResult)res).Model).Id, 2);
            res = await controller.Id(3, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsParticipant"]);

            LogIn(Admin);
            res = await controller.Id(1, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanEdit"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsParticipant"]);
            // Test number
            Assert.AreEqual(_context.Document.Where(d => d.GroupId == 1).Count(), ((GroupModel)((ViewResult)res).Model).Documents.Count);
            // Test tags
            qs = new QueryString("?#Abc");
            HttpRequestMoq.SetupGet(r => r.QueryString).Returns(qs);
            res = await controller.Id(1, null);

            Assert.AreEqual(2, ((GroupModel)((ViewResult)res).Model).Documents.Count);
            qs = new QueryString("?#bcd");
            HttpRequestMoq.SetupGet(r => r.QueryString).Returns(qs);
            res = await controller.Id(1, null);

            Assert.AreEqual(1, ((GroupModel)((ViewResult)res).Model).Documents.Count);
            qs = new QueryString("?#Arr");
            HttpRequestMoq.SetupGet(r => r.QueryString).Returns(qs);
            res = await controller.Id(1, null);

            Assert.AreEqual(1, ((GroupModel)((ViewResult)res).Model).Documents.Count);
            qs = new QueryString("?#sdfsdfg5r");
            HttpRequestMoq.SetupGet(r => r.QueryString).Returns(qs);
            res = await controller.Id(1, null);

            Assert.AreEqual(0, ((GroupModel)((ViewResult)res).Model).Documents.Count);
            qs = new QueryString();
            HttpRequestMoq.SetupGet(r => r.QueryString).Returns(qs);


            res = await controller.Id(2, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.IsInstanceOf <GroupModel>(((ViewResult)res).Model);
            Assert.AreEqual(((GroupModel)((ViewResult)res).Model).Id, 2);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanEdit"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsParticipant"]);
            res = await controller.Id(3, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.AreEqual(((GroupModel)((ViewResult)res).Model).Id, 3);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanEdit"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsParticipant"]);

            LogIn(users[1]);
            res = await controller.Id(1, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanEdit"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsParticipant"]);
            Assert.AreEqual(((GroupModel)((ViewResult)res).Model).Id, 1);
            res = await controller.Id(2, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.IsInstanceOf <GroupModel>(((ViewResult)res).Model);
            Assert.AreEqual(((GroupModel)((ViewResult)res).Model).Id, 2);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["CanEdit"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsParticipant"]);
            res = await controller.Id(3, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["CanEdit"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsParticipant"]);
            Assert.AreEqual(((GroupModel)((ViewResult)res).Model).Id, 3);

            LogIn(users[2]);
            res = await controller.Id(1, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["CanEdit"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsParticipant"]);
            Assert.AreEqual(((GroupModel)((ViewResult)res).Model).Id, 1);
            res = await controller.Id(2, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.IsInstanceOf <GroupModel>(((ViewResult)res).Model);
            Assert.AreEqual(((GroupModel)((ViewResult)res).Model).Id, 2);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["CanEdit"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsTrue((bool)((ViewResult)res).ViewData["IsParticipant"]);
            res = await controller.Id(3, null);

            Assert.IsInstanceOf <ViewResult>(res);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["CanRead"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["CanEdit"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsAdmin"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsSubscribed"]);
            Assert.IsFalse((bool)((ViewResult)res).ViewData["IsParticipant"]);
        }