Example #1
0
        public async Task Group_EditLinks_Post_Success()
        {
            var domainModel = CreateGroupModel();
            var gws         = GetMock <IGroupsWriteService>();
            var grs         = GetMock <IGroupReadService>();

            grs.Setup(x => x.GetAsync(It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ServiceResultDto <GroupModel>(domainModel));
            gws.Setup(x => x.ValidateAsync(It.IsAny <SaveGroupDto>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ValidationEnvelopeDto());
            grs.Setup(x => x.ExistsAsync(It.IsAny <IPrincipal>(), It.IsAny <CompaniesHouseNumber?>(), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <string>(), It.IsAny <int?>())).ReturnsAsync(false);
            GetMock <ISecurityService>().Setup(x => x.CreateAnonymousPrincipal()).Returns(new GenericPrincipal(new GenericIdentity(""), new string[0]));
            gws.Setup(x => x.SaveAsync(It.IsAny <SaveGroupDto>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ApiResponse(true));
            InjectBasicLAsAndGroupTypes();

            var viewModel = new GroupEditorViewModel
            {
                GroupUId             = 123,
                GroupName            = "This is a test",
                Action               = ActionSave,
                SaveMode             = eSaveMode.Links,
                GroupTypeId          = (int)eLookupGroupType.Federation,
                LinkedEstablishments = new GroupLinkedEstablishmentsViewModel
                {
                    Establishments = CreateEstablishmentGroupViewModelList(1)
                }
            };
            var result = (RedirectToRouteResult)await ObjectUnderTest.EditLinks(viewModel);

            Assert.That(result.RouteValues["action"], Is.EqualTo("Details"));
            Assert.That(result.RouteValues["id"], Is.EqualTo(123));

            GetMock <IGroupsWriteService>().Verify(x => x.SaveAsync(It.Is <SaveGroupDto>(v => v.LinkedEstablishments != null && v.GroupUId == 123 && v.Group == null), It.IsAny <IPrincipal>()), Times.Once);
        }
Example #2
0
        public async Task Group_EditLinks_SaveJoinedDate_Success()
        {
            var domainModel = CreateGroupModel();

            var grs = GetMock <IGroupReadService>();

            grs.Setup(x => x.GetAsync(It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ServiceResultDto <GroupModel>(domainModel));
            grs.Setup(x => x.ExistsAsync(It.IsAny <IPrincipal>(), It.IsAny <CompaniesHouseNumber?>(), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <string>(), It.IsAny <int?>())).ReturnsAsync(false);
            GetMock <IGroupsWriteService>().Setup(x => x.ValidateAsync(It.IsAny <SaveGroupDto>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ValidationEnvelopeDto());
            GetMock <ISecurityService>().Setup(x => x.CreateAnonymousPrincipal()).Returns(new GenericPrincipal(new GenericIdentity(""), new string[0]));
            GetMock <IGroupsWriteService>().Setup(x => x.SaveAsync(It.IsAny <SaveGroupDto>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ApiResponse(true));
            InjectBasicLAsAndGroupTypes();

            var estabs    = CreateEstablishmentGroupViewModelList(3);
            var viewModel = new GroupEditorViewModel
            {
                GroupUId             = 123,
                GroupName            = "This is a test",
                Action               = ActionLinkedEstablishmentSave,
                SaveMode             = eSaveMode.Links,
                GroupTypeId          = (int)eLookupGroupType.Federation,
                LinkedEstablishments = new GroupLinkedEstablishmentsViewModel
                {
                    Establishments = estabs
                }
            };

            estabs[0].JoinedDateEditable = new Web.UI.Models.DateTimeViewModel(DateTime.Now.AddDays(1));
            estabs[0].EditMode           = true;
            var result = (ViewResult)await ObjectUnderTest.EditLinks(viewModel);

            viewModel.LinkedEstablishments.Establishments[0].EditMode.ShouldBe(false);
            viewModel.LinkedEstablishments.Establishments[0].JoinedDate.Value.Date.ShouldBe(viewModel.LinkedEstablishments.Establishments[0].JoinedDateEditable.ToDateTime().Value.Date);
        }
Example #3
0
        public async Task Group_EditLinks()
        {
            var grs       = GetMock <IGroupReadService>();
            var estabList = CreateEstabList();

            InjectBasicLAsAndGroupTypes();

            var domainModel = new GroupModel
            {
                Address = new AddressDto
                {
                    CityOrTown = Faker.Address.City(),
                    Line1      = Faker.Address.StreetAddress(),
                    Line2      = Faker.Address.SecondaryAddress(),
                    Line3      = Faker.Address.UkCounty(),
                    PostCode   = Faker.Address.UkPostCode()
                },
                ClosedDate           = DateTime.Now,
                CompaniesHouseNumber = "67829662",
                ConfirmationUpToDateGovernanceRequired = true,
                ConfirmationUpToDateGovernance_LastConfirmationDate = DateTime.Now,
                DelegationInformation = "delinf",
                GroupId             = "123",
                GroupTypeId         = (int)eLookupGroupType.Federation,
                GroupUId            = 123,
                HeadFirstName       = Faker.Name.First(),
                HeadLastName        = Faker.Name.Last(),
                HeadTitleId         = 1,
                LocalAuthorityId    = 1,
                ManagerEmailAddress = Faker.Internet.Email(),
                Name     = "I am Federation",
                OpenDate = DateTime.Now.Subtract(TimeSpan.FromDays(10)),
                StatusId = (int)eLookupGroupStatus.Open
            };

            grs.Setup(x => x.GetAsync(It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ServiceResultDto <GroupModel>(domainModel));
            grs.Setup(x => x.GetEstablishmentGroupsAsync(It.IsAny <int>(), It.IsAny <IPrincipal>(), true)).ReturnsAsync(estabList);

            var response = (ViewResult)await ObjectUnderTest.EditLinks(123);

            var vm = (GroupEditorViewModel)response.Model;

            Assert.That(response.ViewName, Is.EqualTo(string.Empty));
            Assert.That(vm.GroupName, Is.EqualTo("I am Federation"));
            Assert.That(vm.GroupUId, Is.EqualTo(123));
            Assert.That(vm.GroupType, Is.EqualTo(eLookupGroupType.Federation));
            Assert.That(vm.GroupTypeId, Is.EqualTo((int)eLookupGroupType.Federation));
            Assert.That(vm.GroupTypeMode, Is.EqualTo(eGroupTypeMode.Federation));
            Assert.That(vm.GroupTypeName, Is.EqualTo("placeholder"));
            Assert.That(vm.CCLeadCentreUrn, Is.EqualTo(estabList.Single(x => x.CCIsLeadCentre == true).Urn));
            Assert.That(vm.SaveMode, Is.EqualTo(eSaveMode.Links));
            Assert.That(vm.InEditMode, Is.True);
            Assert.That(vm.LinkedEstablishments.Establishments.Count, Is.EqualTo(10));
            Assert.That(vm.ListOfEstablishmentsPluralName, Is.EqualTo("Schools"));
            Assert.That(vm.SelectedTabName, Is.EqualTo("links"));
            Assert.That(vm.OpenDateLabel, Is.EqualTo("Open date"));
            Assert.That(vm.PageTitle, Is.EqualTo("Edit federation"));
            Assert.That(vm.CanUserCloseAndMarkAsCreatedInError, Is.False);
        }
        public async Task Estab_EditLinks_Null_Id()
        {
            var response = await ObjectUnderTest.EditLinks(null);

            Assert.IsTrue(response is HttpNotFoundResult);
        }
        public async Task Estab_EditLinks_Id_NotFound()
        {
            GetMock <IEstablishmentReadService>().Setup(e => e.GetAsync(It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(() => new ServiceResultDto <EstablishmentModel>(eServiceResultStatus.NotFound));

            Assert.That(async() => await ObjectUnderTest.EditLinks(4), Throws.TypeOf <EntityNotFoundException>(), "Expected exception of type EntityNotFoundException");
        }