Ejemplo n.º 1
0
        public async Task Group_Create_WithUnknownWarning_IgnoresIt()
        {
            InjectBasicLAsAndGroupTypes();
            GetMock <IGroupsWriteService>().Setup(x => x.ValidateAsync(It.IsAny <SaveGroupDto>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ValidationEnvelopeDto {
                Warnings = new List <ApiWarning> {
                    new ApiWarning {
                        Code = "unknown", Message = "similar"
                    }
                }
            });
            GetMock <IGroupsWriteService>().Setup(x => x.SaveNewAsync(It.IsAny <SaveGroupDto>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ApiResponse <NumericResultDto>(true)
            {
                Response = new NumericResultDto {
                    Value = 123
                }
            });
            GetMock <IGroupReadService>().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]));

            var result = (RedirectToRouteResult)await ObjectUnderTest.Create(new GroupEditorViewModel
            {
                GroupName         = "test group",
                Action            = ActionSave,
                GroupTypeId       = (int)eLookupGroupType.Federation,
                OpenDate          = new Web.UI.Models.DateTimeViewModel(DateTime.Now),
                ProcessedWarnings = true
            }, ActionSave);

            Assert.That(result.RouteValues["action"], Is.EqualTo("Details"));
            Assert.That(result.RouteValues["id"], Is.EqualTo(123));
        }
Ejemplo n.º 2
0
        public void Write_WithSmallHeader_ReturnsExpectedResult()
        {
            var hdr    = new ASCIIEncoding().GetBytes("short header");
            var result = ObjectUnderTest.Write(TestHelpers.BlockExpectedResult, hdr);

            Approvals.VerifyBinaryFile(result, ".stl");
        }
Ejemplo n.º 3
0
        public async Task Group_Convert_FindValidGroup()
        {
            GetMock <ICachedLookupService>().Setup(x => x.GetNameAsync(It.IsAny <Expression <Func <int?> > >(), It.IsAny <string>())).ReturnsAsync("placeholder");
            GetMock <IGroupReadService>().Setup(x => x.SearchByIdsAsync(It.IsAny <string>(), It.Is <int?>(i => i == 1000), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <IPrincipal>())).ReturnsAsync(() => new ApiPagedResult <SearchGroupDocument>(1, new List <SearchGroupDocument>()
            {
                new SearchGroupDocument {
                    Name = "Group 1000", GroupUId = 1000, GroupTypeId = (int)eLookupGroupType.SingleacademyTrust
                }
            }));

            var vm = new ConvertSATViewModel
            {
                ActionName = "find",
                Text       = "1000"
            };
            var response = (ViewResult)await ObjectUnderTest.Convert(vm);

            vm.Details.Name.ShouldBe("Group 1000");
            vm.Details.GroupUId.ShouldBe(1000);
            vm.Details.GroupTypeId.ShouldBe((int)eLookupGroupType.SingleacademyTrust);
            vm.CountryName.ShouldBe("placeholder");
            vm.CountyName.ShouldBe("placeholder");
            vm.Token.ShouldNotBe(null);
            response.ViewName.ShouldBe("");
        }
Ejemplo n.º 4
0
        public async Task Group_Convert_Confirm_WithValidationError()
        {
            var domainModel = new SearchGroupDocument {
                Name = "Group 1000", GroupUId = 1000, GroupTypeId = (int)eLookupGroupType.SingleacademyTrust
            };

            GetMock <IGroupsWriteService>().Setup(x => x.ConvertSAT2MAT(It.Is <int>(i => i == 1000), It.Is <bool>(b => b == true), It.IsAny <IPrincipal>())).ReturnsAsync(new ApiResponse <NumericResultDto>(false)
            {
                Errors = new [] { new ApiError {
                                      Code = "test", Message = "msg"
                                  } }
            });

            var vm = new ConvertSATViewModel
            {
                Token              = UriHelper.SerializeToUrlToken(domainModel),
                ActionName         = "confirm",
                CopyGovernanceInfo = true
            };
            var response = (ViewResult)await ObjectUnderTest.Convert(vm);

            response.ViewName.ShouldBe("");
            Assert.That(ObjectUnderTest.ModelState[""].Errors[0].ErrorMessage, Is.EqualTo("msg"));
            GetMock <IGroupsWriteService>().Verify(x => x.ConvertSAT2MAT(It.Is <int>(i => i == 1000), It.Is <bool>(b => b == true), It.IsAny <IPrincipal>()), Times.Once);
        }
Ejemplo n.º 5
0
        public async Task Group_Convert_Confirm_Success()
        {
            var domainModel = new SearchGroupDocument {
                Name = "Group 1000", GroupUId = 1000, GroupTypeId = (int)eLookupGroupType.SingleacademyTrust
            };

            GetMock <IGroupsWriteService>().Setup(x => x.ConvertSAT2MAT(It.Is <int>(i => i == 1000), It.Is <bool>(b => b == true), It.IsAny <IPrincipal>())).ReturnsAsync(new ApiResponse <NumericResultDto>(true)
            {
                Response = new NumericResultDto {
                    Value = 200
                }
            });

            var vm = new ConvertSATViewModel
            {
                Token              = UriHelper.SerializeToUrlToken(domainModel),
                ActionName         = "confirm",
                CopyGovernanceInfo = true
            };
            var response = (RedirectToRouteResult)await ObjectUnderTest.Convert(vm);

            response.RouteName.ShouldBe("GroupDetails");
            response.RouteValues["id"].ShouldBe(200);
            GetMock <IGroupsWriteService>().Verify(x => x.ConvertSAT2MAT(It.Is <int>(i => i == 1000), It.Is <bool>(b => b == true), It.IsAny <IPrincipal>()), Times.Once);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public async Task Group_SaveNewAcademyTrust()
        {
            var gws = GetMock <IGroupsWriteService>();

            gws.Setup(x => x.ValidateAsync(It.IsAny <SaveGroupDto>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ValidationEnvelopeDto());
            gws.Setup(x => x.SaveNewAsync(It.IsAny <SaveGroupDto>(), It.IsAny <IPrincipal>())).ReturnsAsync(new ApiResponse <NumericResultDto>(true)
            {
                Response = new NumericResultDto {
                    Value = 123
                }
            });

            GetMock <ISecurityService>().Setup(x => x.GetCreateGroupPermissionAsync(It.IsAny <IPrincipal>()))
            .ReturnsAsync(new CreateGroupPermissionDto {
                GroupTypes = new eLookupGroupType[] { eLookupGroupType.MultiacademyTrust }
            });


            var vm = new CreateAcademyTrustViewModel
            {
                CompaniesHouseAddressToken = UriHelper.SerializeToUrlToken(new AddressDto {
                    Line1 = "line1", CityOrTown = "Bobville"
                }),
                CompaniesHouseNumber = "67362546543",
                TypeId   = (int)eLookupGroupType.MultiacademyTrust,
                Name     = "Multi acad",
                OpenDate = DateTime.Now,
                GroupId  = "54243"
            };
            var result = (RedirectToRouteResult)await ObjectUnderTest.SaveNewAcademyTrust(vm);

            Assert.That(result.RouteValues["action"], Is.EqualTo("Details"));
            Assert.That(result.RouteValues["id"], Is.EqualTo(123));
        }
Ejemplo n.º 9
0
        public async void Create_Album_ById_0_Returns_Album()
        {
            var fix         = new Fixture();
            var inputAlbum  = fix.Create <AlbumModel>();
            var zeroAlbumId = 0;

            inputAlbum.Id = zeroAlbumId;

            var outputAlbum = fix.Create <AlbumModel>();

            outputAlbum.Id = 4;

            For <IAlbumService>()
            .Setup(s => s.CreateAlbum(It.IsAny <AlbumModel>()))
            .Returns(Task.FromResult(outputAlbum)).Verifiable();

            IHttpActionResult result = await ObjectUnderTest.CreateAlbum(inputAlbum);

            var albumId = result as OkNegotiatedContentResult <AlbumModel>;

            result.ShouldNotBeNull();
            result.ShouldNotBeOfType <BadRequestResult>();
            result.ShouldNotBeOfType <NotFoundResult>();
            result.ShouldBeOfType <OkNegotiatedContentResult <AlbumModel> >();
            albumId.Content.Id.ShouldBe(outputAlbum.Id);
            For <IAlbumService>().Verify();
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        public void WriteFile_WithBlock_ReturnsExpectedResult()
        {
            var namer = Approvals.GetDefaultNamer();
            var file  = Path.Combine(namer.SourcePath, namer.Name + ".received.stl");

            ObjectUnderTest.WriteToFile(file, TestHelpers.BlockExpectedResult);
            Approvals.Verify(new FileInfo(file));
        }
 public void Group_CreateNewGroup_PermissionDenied()
 {
     InjectBasicLAsAndGroupTypes();
     GetMock <ISecurityService>().Setup(x => x.GetCreateGroupPermissionAsync(It.IsAny <IPrincipal>())).ReturnsAsync(new CreateGroupPermissionDto {
         GroupTypes = new eLookupGroupType[0]
     });
     Assert.That(async() => await ObjectUnderTest.CreateNewGroup("Federation"), Throws.TypeOf <PermissionDeniedException>());
 }
Ejemplo n.º 13
0
        public void Group_Convert()
        {
            var response = (ViewResult)ObjectUnderTest.Convert();
            var vm       = (ConvertSATViewModel)response.Model;

            Assert.That(response.ViewName, Is.EqualTo(string.Empty));
            Assert.That(response.Model, Is.TypeOf <ConvertSATViewModel>());
        }
Ejemplo n.º 14
0
        public void Write_WithLargeHeader_ReturnsExpectedResult()
        {
            var hdr      = string.Join("", Enumerable.Repeat("abcdefghijklmnopqrstuvwxyz1234567890", 10));
            var hdrBytes = new ASCIIEncoding().GetBytes(hdr);

            var result = ObjectUnderTest.Write(TestHelpers.BlockExpectedResult, hdrBytes);

            Approvals.VerifyBinaryFile(result, ".stl");
        }
Ejemplo n.º 15
0
        public async void Delete_Album_ById_0_Returns_Bad_Request()
        {
            var zeroAlbumId          = 0;
            IHttpActionResult result = await ObjectUnderTest.DelteAlbum(zeroAlbumId);

            result.ShouldNotBeNull();
            result.ShouldNotBeOfType <OkNegotiatedContentResult <bool> >();
            result.ShouldBeOfType <BadRequestResult>();
        }
Ejemplo n.º 16
0
        public async void Get_Album_ById_0_Returns_Bad_Request()
        {
            var zeroAlbumId = 0;

            IHttpActionResult model = await ObjectUnderTest.GetAlbumById(zeroAlbumId);

            model.ShouldNotBeNull();
            model.ShouldBeOfType <BadRequestResult>();
            model.ShouldNotBeOfType <OkResult>();
        }
        protected override void TestIgnoringInvalidEntries()
        {
            var inputWithInvalidEntry = @"[{""first_name"":""Pat"",""last_name"":""Silverthorne"",""country"":""France"",""age"":60},
                                             {""invalid"":""Glen"",""last_name"":""Oliff"",""country"":""Bangladesh"",""age"":34},
                                             {""first_name"":""Edvard"",""last_name"":""Ausher"",""country"":""Liberia"",""age"":92}]";

            var result = ObjectUnderTest.DeserializeArray(inputWithInvalidEntry);

            Assert.AreEqual(2, result.Count());
        }
Ejemplo n.º 18
0
        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));
            }
        }
Ejemplo n.º 19
0
        public void GetControllerModels_ForEachReturnTypeInTestClass2_CallsGetModelsWithThatReturnType()
        {
            ((IModelsGenerator)Mocks[typeof(IModelsGenerator)]).Stub(x => x.GetModels(Arg <Type> .Is.Anything)).Return(new Dictionary <string, ApiDocModel>());

            ObjectUnderTest.GetControllerModels(typeof(TestClass2));

            ((IModelsGenerator)Mocks[typeof(IModelsGenerator)]).AssertWasCalled(x => x.GetModels(typeof(String)));
            ((IModelsGenerator)Mocks[typeof(IModelsGenerator)]).AssertWasCalled(x => x.GetModels(typeof(Int64)));
            ((IModelsGenerator)Mocks[typeof(IModelsGenerator)]).AssertWasCalled(x => x.GetModels(typeof(TestClass1)));
            ((IModelsGenerator)Mocks[typeof(IModelsGenerator)]).AssertWasNotCalled(x => x.GetModels(typeof(Int32)));
        }
Ejemplo n.º 20
0
        public async Task Group_CreateNewGroup(string type, int?localAuthorityId)
        {
            GetMock <ISecurityService>().Setup(x => x.GetCreateGroupPermissionAsync(It.IsAny <IPrincipal>()))
            .ReturnsAsync(new CreateGroupPermissionDto {
                GroupTypes = new eLookupGroupType[] { eLookupGroupType.ChildrensCentresCollaboration, eLookupGroupType.Federation, eLookupGroupType.Trust, eLookupGroupType.SchoolSponsor }, CCLocalAuthorityId = localAuthorityId
            });

            InjectBasicLAsAndGroupTypes();

            GetMock <IPrincipal>().Setup(x => x.IsInRole(It.IsAny <string>())).Returns(false);

            var result = (ViewResult)await ObjectUnderTest.CreateNewGroup(type);

            var model = (GroupEditorViewModel)result.Model;

            if (type == "ChildrensCentre")
            {
                Assert.That(model.GroupTypeId, Is.EqualTo((int)eLookupGroupType.ChildrensCentresCollaboration));
                Assert.That(model.SaveMode, Is.EqualTo(eSaveMode.DetailsAndLinks));
                Assert.That(result.ViewName, Is.EqualTo("CreateChildrensCentre"));

                if (localAuthorityId.HasValue)
                {
                    Assert.IsFalse(model.IsLocalAuthorityEditable);
                    Assert.That(model.LocalAuthorityId, Is.EqualTo(localAuthorityId));
                    Assert.That(model.LocalAuthorityName, Is.EqualTo("placeholder"));
                }
                else
                {
                    Assert.IsTrue(model.IsLocalAuthorityEditable);
                }
            }
            else
            {
                Assert.That(model.SaveMode, Is.EqualTo(eSaveMode.Details));
                Assert.IsFalse(model.IsLocalAuthorityEditable);
                Assert.That(result.ViewName, Is.EqualTo("Create"));
            }

            switch (type)
            {
            case "Federation":
                Assert.That(model.GroupTypeId, Is.EqualTo((int)eLookupGroupType.Federation));
                break;

            case "Trust":
                Assert.That(model.GroupTypeId, Is.EqualTo((int)eLookupGroupType.Trust));
                break;

            case "Sponsor":
                Assert.That(model.GroupTypeId, Is.EqualTo((int)eLookupGroupType.SchoolSponsor));
                break;
            }
        }
 public Exception ClassFinish()
 {
     try
     {
         ObjectUnderTest.OnFinish();
         return(null);
     }
     catch (Exception ex)
     {
         return(ex);
     }
 }
 public Exception ClassStart()
 {
     try
     {
         ObjectUnderTest.OnStart();
         return(null);
     }
     catch (Exception ex)
     {
         return(ex);
     }
 }
Ejemplo n.º 23
0
        public async void Update_Album_ById_0_Returns_Bad_Request()
        {
            var fix   = new Fixture();
            var album = fix.Create <AlbumModel>();

            album.Id = 0;

            IHttpActionResult model = await ObjectUnderTest.UpdateAlbum(album);

            model.ShouldNotBeNull();
            model.ShouldNotBeOfType <OkNegotiatedContentResult <AlbumModel> >();
            model.ShouldBeOfType <BadRequestResult>();
        }
Ejemplo n.º 24
0
        public async void DeleteAlbum_ById_0_Returns_False()
        {
            var albumId = 0;

            For <IMediator>()
            .Setup(m => m.Send(It.IsAny <DeleteAlbumCommand>(), default(CancellationToken)))
            .Returns(Task.FromResult(false)).Verifiable();

            var result = await ObjectUnderTest.DeleteAlbum(albumId);

            result.ShouldBeFalse();
            For <IMediator>().Verify();
        }
Ejemplo n.º 25
0
        public async void GetAlbum_ById_0_Returns_Null()
        {
            var albumId = 0;

            For <IMediator>()
            .Setup(m => m.Send(It.IsAny <AlbumQuery>(), default(CancellationToken)))
            .Returns(Task.FromResult <AlbumModel>(null)).Verifiable();

            var result = await ObjectUnderTest.GetAlbum(albumId);

            result.ShouldBeNull();
            For <IMediator>().Verify();
        }
Ejemplo n.º 26
0
        public async void UpdateAlbum_InValid_Request_Returns_False()
        {
            var fix          = new Fixture();
            var invalidAlbum = fix.Create <AlbumModel>();

            For <IMediator>()
            .Setup(m => m.Send(It.IsAny <UpdateAlbumCommand>(), default(CancellationToken)))
            .Returns(Task.FromResult(false)).Verifiable();

            var result = await ObjectUnderTest.UpdateAlbum(invalidAlbum);

            result.ShouldBeFalse();
            For <IMediator>().Verify();
        }
        public async Task Estab_AddOrReplaceEstablishmentAddress()
        {
            var nationalities = new List <LookupDto>
            {
                new LookupDto {
                    Code = "1", Id = 1, Name = "Nationality 1"
                },
                new LookupDto {
                    Code = "2", Id = 2, Name = "Nationality 2"
                },
                new LookupDto {
                    Code = "3", Id = 3, Name = "Nationality 3"
                }
            };

            var counties = new List <LookupDto>
            {
                new LookupDto {
                    Code = "1", Id = 1, Name = "County 1"
                },
                new LookupDto {
                    Code = "2", Id = 2, Name = "County 2"
                },
                new LookupDto {
                    Code = "3", Id = 3, Name = "County 3"
                }
            };

            var establishment = new EstablishmentModel
            {
                Urn  = 5,
                Name = "test"
            };

            GetMock <IGroupReadService>().Setup(x => x.GetAllByEstablishmentUrnAsync(It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(new[] { new GroupModel {
                                                                                                                                                          Name = "Group 1", GroupUId = 1000
                                                                                                                                                      } });
            GetMock <ICachedLookupService>().Setup(c => c.NationalitiesGetAllAsync()).ReturnsAsync(() => nationalities);
            GetMock <ICachedLookupService>().Setup(c => c.CountiesGetAllAsync()).ReturnsAsync(() => counties);
            GetMock <IEstablishmentReadService>().Setup(e => e.GetAsync(It.IsAny <int>(), It.IsAny <IPrincipal>())).ReturnsAsync(() => new ServiceResultDto <EstablishmentModel>(establishment));
            GetMock <IEstablishmentReadService>().Setup(e => e.GetEditPolicyAsync(It.IsAny <EstablishmentModel>(), It.IsAny <IPrincipal>())).ReturnsAsync(() => new EstablishmentEditPolicyEnvelope {
                EditPolicy = new EstablishmentDisplayEditPolicy {
                    IEBTDetail = new IEBTDetailDisplayEditPolicy {
                        AccommodationChangedId = true
                    }
                }
            });

            await ObjectUnderTest.AddOrReplaceEstablishmentAddressAsync(5, "test");
        }
Ejemplo n.º 28
0
    public void TestEventRaised()
    {
        // arrange
        var called = false;

        var test = new ObjectUnderTest();

        test.WidthChanged += (sender, args) => called = true;

        // act
        test.Width = 42;

        // assert
        Assert.IsTrue(called);
    }
        protected override void TestIgnoringInvalidEntries()
        {
            var inputWithInvalidEntry = @"first_name,last_name,country,age
Ryon,,Belarus,71
Elie,Mardall,Kazakhstan,invalid
Dorothy,Lanigan,American Samoa,70";

            var result = ObjectUnderTest.DeserializeArray(inputWithInvalidEntry);

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("Dorothy", result.First().FirstName);
            Assert.AreEqual("Lanigan", result.First().LastName);
            Assert.AreEqual("American Samoa", result.First().Country);
            Assert.AreEqual(70, result.First().Age);
        }
Ejemplo n.º 30
0
        public async Task Group_Convert_FindNonExistentSAT()
        {
            var grs = GetMock <IGroupReadService>();

            grs.Setup(x => x.SearchByIdsAsync(It.IsAny <string>(), It.Is <int?>(i => i == 1000), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <IPrincipal>())).ReturnsAsync(() => new ApiPagedResult <SearchGroupDocument>(0, new List <SearchGroupDocument>()));

            var response = (ViewResult)await ObjectUnderTest.Convert(new ConvertSATViewModel
            {
                ActionName = "find",
                Text       = "1000"
            });

            Assert.That(ObjectUnderTest.ModelState["Text"].Errors[0].ErrorMessage, Is.EqualTo("We were unable to find a single-academy trust matching those details"));
            Assert.That(response.ViewName, Is.EqualTo(string.Empty));
        }