public ActionResult Index() { var groups = this.groups.GetAll().ToList(); var groupsCount = groups.Count; var usersCount = this.users.GetAll().Count(); var friendLists = this.friendLists.GetAll(); var friendListsCount = friendLists.Count; var friendsCount = 0; var messagesCount = 0; foreach (var friendList in friendLists) { friendsCount += friendList.Friends.Count; } foreach (var group in groups) { messagesCount += group.Messages.Count; } var adminViewModel = new AdminDataInitalViewModel(); adminViewModel.FriendListsCount = friendListsCount; adminViewModel.GroupsCount = groupsCount; adminViewModel.MessagesCount = messagesCount; adminViewModel.UsersCount = usersCount; adminViewModel.FriendsCount = friendsCount; return(View(adminViewModel)); }
public void Index_ShouldRender_ViewWithCorrectParameters() { var userServiceMocked = new Mock <IUserService>(); var groupsServiceMocked = new Mock <IGroupService>(); var friendListServiceMocked = new Mock <IFriendListService>(); groupsServiceMocked.Setup(m => m.GetAll()) .Returns(new List <Group>() { new Group() { Messages = new List <Message>() { new Message() { }, new Message() { } } } }); friendListServiceMocked.Setup(m => m.GetAll()) .Returns(new List <FriendsList>() { new FriendsList() { Friends = new List <Friend>() { new Friend() { }, new Friend() { }, new Friend() { } } } }); userServiceMocked.Setup(m => m.GetAll()) .Returns(new List <User>() { new User() { }, new User() { } }); var controller = new AdministrationController(groupsServiceMocked.Object, friendListServiceMocked.Object, userServiceMocked.Object); var adminViewModel = new AdminDataInitalViewModel(); adminViewModel.FriendListsCount = 1; adminViewModel.GroupsCount = 1; adminViewModel.MessagesCount = 2; adminViewModel.UsersCount = 2; adminViewModel.FriendsCount = 3; controller .WithCallTo(m => m.Index()) .ShouldRenderDefaultView() .WithModel <AdminDataInitalViewModel>(viewModel => { Assert.AreEqual(viewModel.MessagesCount, adminViewModel.MessagesCount); Assert.AreEqual(viewModel.GroupsCount, adminViewModel.GroupsCount); Assert.AreEqual(viewModel.UsersCount, adminViewModel.UsersCount); Assert.AreEqual(viewModel.FriendsCount, adminViewModel.FriendsCount); Assert.AreEqual(viewModel.FriendListsCount, adminViewModel.FriendListsCount); }); }