Exemplo n.º 1
0
        [InlineData("453a2901-150b-4211-84b1-a40ac2ba4a35", -1, false, false, false, false)] // Unsuccessful Details (Group does not exist)
        public void TestGroupDetails(string userAspId, int groupId, bool expectingSuccess, bool isClosed, bool isCreator, bool isRegularMember)
        {
            var controllerContextMock = new Mock <ControllerContext>()
            {
                CallBase = true
            };
            var contextMock = new Mock <ApplicationDbContext>()
            {
                CallBase = true
            };

            contextMock.Setup(c => c.SaveChanges()).Returns(1);
            var controller = new GroupsController
            {
                ControllerContext = controllerContextMock.Object,
                Context           = contextMock.Object,
                GetUserId         = () => userAspId
            };

            var result = controller.Details(groupId);

            if (expectingSuccess)
            {
                if (isClosed)
                {
                    Assert.True(result is RedirectToRouteResult);
                    var redirectResult = (RedirectToRouteResult)result;
                    Assert.Equal("ClosedDetails", redirectResult.RouteValues["action"]);
                    Assert.Equal(groupId, redirectResult.RouteValues["groupId"]);
                }

                else if (isCreator)
                {
                    Assert.True(result is ViewResult);
                    var viewResult = (ViewResult)result;
                    Assert.Equal("CreatorDetails", viewResult.ViewName);
                    Assert.Equal(groupId, ((GroupDetailsViewModel)viewResult.Model).Group.GroupId);
                }

                else if (isRegularMember)
                {
                    Assert.True(result is ViewResult);
                    var viewResult = (ViewResult)result;
                    Assert.Equal("MemberDetails", viewResult.ViewName);
                    Assert.Equal(groupId, ((GroupDetailsViewModel)viewResult.Model).Group.GroupId);
                }

                else
                {
                    Assert.True(result is ViewResult);
                    var viewResult = (ViewResult)result;
                    Assert.Equal("", viewResult.ViewName);
                    Assert.Equal(groupId, ((GroupDetailsViewModel)viewResult.Model).Group.GroupId);
                }
            }
            else
            {
                Assert.True(result is HttpNotFoundResult);
            }
        }
Exemplo n.º 2
0
        public void Details_Group_ReturnGroupID()
        {
            int?groupID = 5;

            var groups = new Groups()
            {
                GroupId     = 3,
                GroupName   = "C",
                GroupLength = 6
            };

            _mockRepo.Setup(d => d.Details(groupID)).Returns(groups);

            var expectedModel = new Groups()
            {
                GroupId     = groups.GroupId,
                GroupName   = groups.GroupName,
                GroupLength = groups.GroupLength
            };

            var actual = _controller.Details(groupID);

            var actualModel = actual.Model as Groups;

            Assert.Equal(expectedModel.GroupId, actualModel.GroupId);
            Assert.Equal(expectedModel.GroupName, actualModel.GroupName);
            Assert.Equal(expectedModel.GroupLength, actualModel.GroupLength);
        }
Exemplo n.º 3
0
        public void ActivityShedules_Details()
        {
            var activity = activitySchedules.Where(a => a.ActivityID == ACTIVITY_SCHEDULE_ID_TO_USE).FirstOrDefault();

            ViewResult viewResult = controller.Details(ACTIVITY_SCHEDULE_ID_TO_USE) as ViewResult;
            var        model      = viewResult.Model as Group;

            Assert.IsNotNull(model);
            Assert.AreEqual(model.ActivityID, ACTIVITY_SCHEDULE_ID_TO_USE);
            Assert.AreEqual(model.ActivityID, activity.ActivityID);
            Assert.AreEqual(model.HourFrom, activity.HourFrom);
            Assert.AreEqual(model.HourTo, activity.HourTo);
        }