public void ShouldValidateAddLocalEducationAgencyModelWithValidValues()
        {
            // Arrange
            var existingLeaWithDifferentId = new LocalEducationAgency
            {
                EducationOrganizationId = 2
            };

            _mockOdsApiFacade.Setup(x => x.GetAllLocalEducationAgencies()).Returns(new List <LocalEducationAgency>
            {
                existingLeaWithDifferentId
            });

            var existingSchoolWithDifferentId = new School
            {
                EducationOrganizationId = 3
            };

            _mockOdsApiFacade.Setup(x => x.GetAllSchools()).Returns(new List <School>
            {
                existingSchoolWithDifferentId
            });

            _mockOdsApiFacadeFactory.Setup(x => x.Create())
            .Returns(Task.FromResult(_mockOdsApiFacade.Object));

            var validator = new AddLocalEducationAgencyModelValidator(_mockOdsApiFacadeFactory.Object);

            validator.ShouldValidate(_addLocalEducationAgencyModel);
        }
        public void ShouldNotValidateAddLocalEducationAgencyModelIfPassedWithExistingLeaEdOrgId()
        {
            // Arrange
            var existingLeaWithSameId = new LocalEducationAgency
            {
                EducationOrganizationId = Id
            };

            _mockOdsApiFacade.Setup(x => x.GetAllLocalEducationAgencies()).Returns(new List <LocalEducationAgency>
            {
                existingLeaWithSameId
            });

            var existingSchoolWithDifferentId = new School
            {
                EducationOrganizationId = 2
            };

            _mockOdsApiFacade.Setup(x => x.GetAllSchools()).Returns(new List <School>
            {
                existingSchoolWithDifferentId
            });

            _mockOdsApiFacadeFactory.Setup(x => x.Create())
            .Returns(Task.FromResult(_mockOdsApiFacade.Object));

            var validator = new AddLocalEducationAgencyModelValidator(_mockOdsApiFacadeFactory.Object);

            validator.ShouldNotValidate(_addLocalEducationAgencyModel, "This 'Local Education Organization ID' is already associated with another Education Organization. Please provide a unique value.");
        }
        public void ShouldNotValidateAddSchoolModelIfGradeLevelsListIsEmpty()
        {
            // Arrange
            _addSchoolModel.GradeLevels = new List <string>();

            var existingLeaWithDifferentId = new LocalEducationAgency
            {
                EducationOrganizationId = 2
            };

            _mockOdsApiFacade.Setup(x => x.GetAllLocalEducationAgencies()).Returns(new List <LocalEducationAgency>
            {
                existingLeaWithDifferentId
            });

            var existingSchoolWithDifferentId = new School
            {
                EducationOrganizationId = 3
            };

            _mockOdsApiFacade.Setup(x => x.GetAllSchools()).Returns(new List <School>
            {
                existingSchoolWithDifferentId
            });

            _mockOdsApiFacadeFactory.Setup(x => x.Create())
            .Returns(Task.FromResult(_mockOdsApiFacade.Object));

            var validator = new AddSchoolModelValidator(_mockOdsApiFacadeFactory.Object);

            validator.ShouldNotValidate(_addSchoolModel, "You must choose at least one grade level");
        }
        /// <summary>
        /// Updates or creates a resource based on the resource identifier. The PUT operation is used to update or create a resource by identifier.  If the resource doesn't exist, the resource will be created using that identifier.  Additionally, natural key values cannot be changed using this operation, and will not be modified in the database.  If the resource &quot;id&quot; is provided in the JSON body, it will be ignored as well.
        /// </summary>
        /// <param name="id">A resource identifier specifying the resource to be updated.</param>
        /// <param name="IfMatch">The ETag header value used to prevent the PUT from updating a resource modified by another consumer.</param>
        /// <param name="body">The JSON representation of the &quot;localEducationAgency&quot; resource to be updated.</param>
        /// <returns>A RestSharp <see cref="IRestResponse"/> instance containing the API response details.</returns>
        public IRestResponse PutLocalEducationAgency(string id, string IfMatch, LocalEducationAgency body)
        {
            var request = new RestRequest("/localEducationAgencies/{id}", Method.PUT);

            request.RequestFormat = DataFormat.Json;

            request.AddUrlSegment("id", id);
            // verify required params are set
            if (id == null || body == null)
            {
                throw new ArgumentException("API method call is missing required parameters");
            }
            request.AddHeader("If-Match", IfMatch);
            request.AddBody(body);
            request.Parameters.First(param => param.Type == ParameterType.RequestBody).Name = "application/json";
            var response = client.Execute(request);

            var location = response.Headers.FirstOrDefault(x => x.Name == "Location");

            if (location != null && !string.IsNullOrWhiteSpace(location.Value.ToString()))
            {
                body.id = location.Value.ToString().Split('/').Last();
            }
            return(response);
        }
        public void Should_resolve_destination_addresses_with_local_education_agency_address_resolver()
        {
            // Arrange
            var lea = new LocalEducationAgency
            {
                StreetNumberName = StreetNumberName,
                State            = State,
                City             = City,
                ZipCode          = ZipCode
            };

            var edfiLea = new EdFiLocalEducationAgency("id", new List <EdFiEducationOrganizationAddress>(),
                                                       new List <EdFiEducationOrganizationCategory>(), 1234, localEducationAgencyCategoryDescriptor: "leaCategory",
                                                       nameOfInstitution: "TestLea");

            Mapper.Initialize(cfg =>
                              cfg.CreateMap <LocalEducationAgency, EdFiLocalEducationAgency>()
                              .ForMember(dst => dst.Addresses, opt => opt.ResolveUsing <LocalEducationAgencyAddressResolver>()));

            // Act
            var result = Mapper.Map(lea, edfiLea);

            // Assert
            result.ShouldNotBeNull();
            result.Addresses.ShouldNotBeNull();
            result.Addresses.Count.ShouldBeGreaterThan(0);
            result.Addresses.First().City.ShouldBe(City);
            result.Addresses.First().StreetNumberName.ShouldBe(StreetNumberName);
            result.Addresses.First().StateAbbreviationDescriptor.ShouldBe(State);
            result.Addresses.First().PostalCode.ShouldBe(ZipCode);
        }
Example #6
0
        public void When_resolve_destination_state_education_agency_reference_from_source()
        {
            // Arrange
            var lea = new LocalEducationAgency
            {
                StateOrganizationId = StateEducationAgencyId
            };

            var edfiLea = new EdFiLocalEducationAgency("id", new List <EdFiEducationOrganizationAddress>(),
                                                       new List <EdFiEducationOrganizationCategory>(), 1234,
                                                       nameOfInstitution: Name, localEducationAgencyCategoryDescriptor: Category);

            var mapperConfiguration = new MapperConfiguration(cfg =>
                                                              cfg.CreateMap <LocalEducationAgency, EdFiLocalEducationAgency>()
                                                              .ForMember(dst => dst.StateEducationAgencyReference,
                                                                         opt => opt.MapFrom <StateEducationAgencyReferenceResolver>()));
            var mapper = mapperConfiguration.CreateMapper();

            // Act
            var result = mapper.Map(lea, edfiLea);

            // Assert
            result.ShouldNotBeNull();
            result.StateEducationAgencyReference.ShouldNotBeNull();
            result.StateEducationAgencyReference.StateEducationAgencyId.ShouldBe(StateEducationAgencyId);
        }
        public void ShouldValidateAddPostSecondaryInstitutionModelWithValidValues()
        {
            // Arrange
            var existingLeaWithDifferentId = new LocalEducationAgency
            {
                EducationOrganizationId = 2
            };

            _mockOdsApiFacade.Setup(x => x.GetAllLocalEducationAgencies()).Returns(new List <LocalEducationAgency>
            {
                existingLeaWithDifferentId
            });

            var existingSchoolWithDifferentId = new School
            {
                EducationOrganizationId = 3
            };

            _mockOdsApiFacade.Setup(x => x.GetAllSchools()).Returns(new List <School>
            {
                existingSchoolWithDifferentId
            });

            var existingPsiWithDifferentId = new PostSecondaryInstitution
            {
                EducationOrganizationId = 4
            };

            _mockOdsApiFacade.Setup(x => x.GetAllPostSecondaryInstitutions()).Returns(new List <PostSecondaryInstitution>
            {
                existingPsiWithDifferentId
            });

            var validator = new AddPostSecondaryInstitutionModelValidator();

            validator.ShouldValidate(_addPostSecondaryInstitutionModel);

            EducationOrganizationValidationHelper
            .ProposedEducationOrganizationIdIsInUse(_addPostSecondaryInstitutionModel.PostSecondaryInstitutionId.Value, _mockOdsApiFacade.Object)
            .ShouldBeFalse();
        }
            public void When_Mapping_LocalEducationAgency_to_EdFiLocalEducationAgency_Should_Have_Expected_Values_On_Destination()
            {
                // Arrange
                var lea = new LocalEducationAgency
                {
                    Id = Id,
                    LocalEducationAgencyId = LeaId,
                    Name = Name,
                    LocalEducationAgencyCategoryType = LocalEducationAgencyCategoryType,
                    State = State,
                    ApartmentRoomSuiteNumber = ApartmentRoomSuiteNumber,
                    StreetNumberName         = StreetNumberName,
                    City                          = City,
                    ZipCode                       = PostalCode,
                    StateOrganizationId           = StateEducationAgencyId,
                    EducationOrganizationCategory = LocalEducationAgencyCategoryType
                };

                var edfiLea = new EdFiLocalEducationAgency(Id, new List <EdFiEducationOrganizationAddress>(),
                                                           new List <EdFiEducationOrganizationCategory>(), LeaId, nameOfInstitution: Name, localEducationAgencyCategoryDescriptor: LocalEducationAgencyCategoryType);
                // Act
                var result = _mapper.Map(lea, edfiLea);

                // Assert
                result.ShouldNotBeNull();
                result.Id.ShouldBe(Id);
                result.LocalEducationAgencyId.ShouldBe(LeaId);
                result.NameOfInstitution.ShouldBe(Name);
                result.LocalEducationAgencyCategoryDescriptor.ShouldBe(LocalEducationAgencyCategoryType);
                result.Addresses.Count.ShouldBe(1);
                result.Addresses.First().StreetNumberName.ShouldBe(StreetNumberName);
                result.Addresses.First().City.ShouldBe(City);
                result.Addresses.First().StateAbbreviationDescriptor.ShouldContain(State);
                result.Addresses.First().ApartmentRoomSuiteNumber.ShouldBe(ApartmentRoomSuiteNumber);
                result.Addresses.First().PostalCode.ShouldBe(PostalCode);
                result.StateEducationAgencyReference.StateEducationAgencyId.ShouldBe(StateEducationAgencyId);
                result.Categories.Count.ShouldBe(1);
                result.Categories.First().EducationOrganizationCategoryDescriptor.ShouldContain(LocalEducationAgencyCategoryType);
            }
Example #9
0
        /// <summary>
        /// Creates or updates resources based on the natural key values of the supplied resource. The POST operation can be used to create or update resources. In database terms, this is often referred to as an &quot;upsert&quot; operation (insert + update).  Clients should NOT include the resource &quot;id&quot; in the JSON body because it will result in an error (you must use a PUT operation to update a resource by &quot;id&quot;). The web service will identify whether the resource already exists based on the natural key values provided, and update or create the resource appropriately.
        /// </summary>
        /// <param name="body">The JSON representation of the &quot;localEducationAgency&quot; resource to be created or updated.</param>
        /// <returns>A RestSharp <see cref="IRestResponse"/> instance containing the API response details.</returns>
        public IRestResponse PostLocalEducationAgencies(LocalEducationAgency body)
        {
            var request = new RestRequest("/localEducationAgencies", Method.POST);

            request.RequestFormat = DataFormat.Json;

            // verify required params are set
            if (body == null)
            {
                throw new ArgumentException("API method call is missing required parameters");
            }
            request.AddBody(body);
            var response = client.Execute(request);

            var location = response.Headers.FirstOrDefault(x => x.Name == "Location");

            if (location != null && !string.IsNullOrWhiteSpace(location.Value.ToString()))
            {
                body.id = location.Value.ToString().Split('/').Last();
            }
            return(response);
        }
        public void ShouldNotValidateAddSchoolModelIfGradeLevelsListIsEmpty()
        {
            // Arrange
            _addPsiSchoolModel.GradeLevels = new List <string>();

            var existingLeaWithDifferentId = new LocalEducationAgency
            {
                EducationOrganizationId = 2
            };

            _mockOdsApiFacade.Setup(x => x.GetAllLocalEducationAgencies()).Returns(new List <LocalEducationAgency>
            {
                existingLeaWithDifferentId
            });

            var existingSchoolWithDifferentId = new School
            {
                EducationOrganizationId = 3
            };

            _mockOdsApiFacade.Setup(x => x.GetAllSchools()).Returns(new List <School>
            {
                existingSchoolWithDifferentId
            });

            var existingPsiWithDifferentId = new PostSecondaryInstitution
            {
                EducationOrganizationId = 4
            };

            _mockOdsApiFacade.Setup(x => x.GetAllPostSecondaryInstitutions()).Returns(new List <PostSecondaryInstitution>
            {
                existingPsiWithDifferentId
            });

            var validator = new AddPsiSchoolModelValidator();

            validator.ShouldNotValidate(_addPsiSchoolModel, "You must choose at least one grade level");
        }
        public void ShouldNotValidateAddLocalEducationAgencyModelIfPassedWithExistingLeaEdOrgId()
        {
            // Arrange
            var existingLeaWithSameId = new LocalEducationAgency
            {
                EducationOrganizationId = Id
            };

            _mockOdsApiFacade.Setup(x => x.GetAllLocalEducationAgencies()).Returns(new List <LocalEducationAgency>
            {
                existingLeaWithSameId
            });

            var existingSchoolWithDifferentId = new School
            {
                EducationOrganizationId = 2
            };

            _mockOdsApiFacade.Setup(x => x.GetAllSchools()).Returns(new List <School>
            {
                existingSchoolWithDifferentId
            });

            var existingPsiWithDifferentId = new PostSecondaryInstitution
            {
                EducationOrganizationId = 4
            };

            _mockOdsApiFacade.Setup(x => x.GetAllPostSecondaryInstitutions()).Returns(new List <PostSecondaryInstitution>
            {
                existingPsiWithDifferentId
            });

            EducationOrganizationValidationHelper
            .ProposedEducationOrganizationIdIsInUse(_addLocalEducationAgencyModel.LocalEducationAgencyId.Value, _mockOdsApiFacade.Object)
            .ShouldBeTrue();
        }
Example #12
0
        public void When_Perform_Get_Request_To_LocalEducationAgencyList_Return_Education_Organization_List()
        {
            // Arrange
            var lea = new LocalEducationAgency();

            var schools = new List <School>
            {
                new School()
            };

            var leas = new List <LocalEducationAgency>
            {
                lea
            };

            var psis = new List <PostSecondaryInstitution>
            {
                new PostSecondaryInstitution()
            };
            const string gradeLevel = "FirstGrade";
            const string value      = "Namespace#FirstGrade";
            const string localEducationAgencyCategory      = "School";
            const string localEducationAgencyCategoryValue = "Namespace#School";

            _mockOdsApiFacade.Setup(x => x.GetSchoolsByLeaIds(new List <int>()
            {
                lea.EducationOrganizationId
            })).Returns(schools);
            _mockOdsApiFacade.Setup(x => x.GetLocalEducationAgenciesByPage(0, Page <LocalEducationAgency> .DefaultPageSize + 1)).Returns(leas);
            _mockOdsApiFacade.Setup(x => x.GetPostSecondaryInstitutionsByPage(0, Page <PostSecondaryInstitution> .DefaultPageSize + 1)).Returns(psis);
            _mockOdsApiFacadeFactory.Setup(x => x.Create())
            .Returns(Task.FromResult(_mockOdsApiFacade.Object));
            _mockOdsApiFacade.Setup(x => x.GetAllGradeLevels())
            .Returns(new List <SelectOptionModel> {
                new SelectOptionModel {
                    DisplayText = gradeLevel, Value = value
                }
            });
            _mockOdsApiFacade.Setup(x => x.GetLocalEducationAgencyCategories())
            .Returns(new List <SelectOptionModel>
            {
                new SelectOptionModel {
                    DisplayText = localEducationAgencyCategory, Value = localEducationAgencyCategoryValue
                }
            });
            _controller =
                new EducationOrganizationsController(_mockOdsApiFacadeFactory.Object, _mockMapper.Object, _mockInstanceContext.Object, _tabDisplayService.Object, _inferExtensionDetails);

            // Act
            var result = _controller.LocalEducationAgencyList(1).Result as PartialViewResult;

            // Assert
            result.ShouldNotBeNull();
            var model = (LocalEducationAgencyViewModel)result.ViewData.Model;

            model.ShouldNotBeNull();
            model.Schools.Count.ShouldBeGreaterThan(0);
            model.LocalEducationAgencies.Items.Count().ShouldBeGreaterThan(0);

            var addSchoolModel = model.AddSchoolModel;

            addSchoolModel.ShouldNotBeNull();
            addSchoolModel.GradeLevelOptions.Count.ShouldBe(1);
            addSchoolModel.GradeLevelOptions.Single().DisplayText.ShouldBe(gradeLevel);
            addSchoolModel.GradeLevelOptions.Single().Value.ShouldBe(value);

            var addLocalEducationAgencyModel = model.AddLocalEducationAgencyModel;

            addLocalEducationAgencyModel.ShouldNotBeNull();
            addLocalEducationAgencyModel.LocalEducationAgencyCategoryTypeOptions.Count.ShouldBe(1);
            addLocalEducationAgencyModel.LocalEducationAgencyCategoryTypeOptions.Single().DisplayText.ShouldBe(localEducationAgencyCategory);
            addLocalEducationAgencyModel.LocalEducationAgencyCategoryTypeOptions.Single().Value.ShouldBe(localEducationAgencyCategoryValue);
        }
Example #13
0
        private static Claim CreateLocalEducationAgencyClaim(LocalEducationAgency lea, string claimType)
        {
            var properties = new Dictionary<string, string>();
            //properties.Add(EdFiClaimProperties.EducationOrganizationName, lea.Name);
            properties.Add(EdFiClaimProperties.LocalEducationAgencyId, lea.LocalEducationAgencyId.ToString());
            properties.Add(EdFiClaimProperties.EducationOrganizationName, lea.Name);

            string serializedProperties = JsonConvert.SerializeObject(properties);

            var claim = new Claim(claimType, serializedProperties);

            return claim;
        }