public async Task Group_Details_WithValidRecord(bool isUserLoggedOn, bool canUserEdit) { var grs = GetMock <IGroupReadService>(); var govrs = GetMock <IGovernorsReadService>(); var id = GetMock <IIdentity>(); var estabList = CreateEstabList(); id.Setup(x => x.IsAuthenticated).Returns(isUserLoggedOn); grs.Setup(x => x.GetAsync(It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ServiceResultDto <GroupModel>(new GroupModel { GroupUId = 1, Name = "grp" })); grs.Setup(x => x.GetLinksAsync(It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(Enumerable.Empty <LinkedGroupModel>()); grs.Setup(x => x.CanEditAsync(It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(canUserEdit); grs.Setup(x => x.CanEditGovernanceAsync(It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(canUserEdit); grs.Setup(x => x.GetChangeHistoryAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <IPrincipal>())).ReturnsAsync(new PaginatedResult <GroupChangeDto>()); grs.Setup(x => x.GetEstablishmentGroupsAsync(It.IsAny <int>(), It.IsAny <IPrincipal>(), true)).ReturnsAsync(estabList); govrs.Setup(x => x.GetGovernorPermissions(null, It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(() => new GovernorPermissions { Add = true, Update = true, Remove = true }); var response = (ViewResult)await ObjectUnderTest.Details(1); if (!isUserLoggedOn) { grs.Verify(x => x.GetChangeHistoryAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <IPrincipal>()), Times.Never()); } else { grs.Verify(x => x.GetChangeHistoryAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <IPrincipal>()), Times.Once()); } var viewModel = (GroupDetailViewModel)response.Model; Assert.That(viewModel.CanUserEdit, Is.EqualTo(canUserEdit)); Assert.That(viewModel.Establishments.Count, Is.EqualTo(estabList.Count)); for (int i = 0; i < estabList.Count; i++) { Assert.That(viewModel.Establishments[i].Address, Is.EqualTo(estabList[i].Address.ToString())); Assert.That(viewModel.Establishments[i].Name, Is.EqualTo(estabList[i].Name)); Assert.That(viewModel.Establishments[i].CCIsLeadCentre, Is.EqualTo(estabList[i].CCIsLeadCentre)); Assert.That(viewModel.Establishments[i].EditMode, Is.EqualTo(false)); Assert.That(viewModel.Establishments[i].HeadFirstName, Is.EqualTo(estabList[i].HeadFirstName)); Assert.That(viewModel.Establishments[i].HeadLastName, Is.EqualTo(estabList[i].HeadLastName)); Assert.That(viewModel.Establishments[i].HeadTitleName, Is.EqualTo(estabList[i].HeadTitle)); Assert.That(viewModel.Establishments[i].Id, Is.EqualTo(estabList[i].Id)); Assert.That(viewModel.Establishments[i].JoinedDate, Is.EqualTo(estabList[i].JoinedDate)); Assert.That(viewModel.Establishments[i].LAESTAB, Is.EqualTo(estabList[i].LAESTAB)); Assert.That(viewModel.Establishments[i].LocalAuthorityName, Is.EqualTo(estabList[i].LocalAuthorityName)); Assert.That(viewModel.Establishments[i].PhaseName, Is.EqualTo(estabList[i].PhaseName)); Assert.That(viewModel.Establishments[i].StatusName, Is.EqualTo(estabList[i].StatusName)); Assert.That(viewModel.Establishments[i].TypeName, Is.EqualTo(estabList[i].TypeName)); Assert.That(viewModel.Establishments[i].Urn, Is.EqualTo(estabList[i].Urn)); } }