public async Task ApplyApplicationDefninitionWithNulledFunctions_NoApplicationIsPresent_ReturnsNewApplicationWithoutFunctions()
        {
            // Create an application repository that returns the supplied models so that they can be interrogated, rather than going to the DB.
            // The main thng we want to test here is how the service maps from the security contract onto the model, which is lost if we simply
            // mock the model that is returned from the repository.

            // The fake repository has an overloaded constructor that allows us to inject the mocked model it will return when getById or getByName functions
            // are called on the fake repository.
            var applicationRespository = new ApplicationRepositoryFake(null);
            var identityServiceApiResourceRepository = Substitute.For <IIdentityApiResourceRepository>();
            var permissionsRepository           = Substitute.For <IPermissionRepository>();
            var applicationFunctionRepository   = Substitute.For <IApplicationFunctionRepository>();
            var applicationDataPolicyRepository = Substitute.For <IApplicationDataPolicyRepository>();

            var securityContractApplicationService = new SecurityContractApplicationService(applicationRespository, identityServiceApiResourceRepository, permissionsRepository, applicationFunctionRepository, applicationDataPolicyRepository);

            // Define an application security contract definition.
            var applicationSecurityContract = new SecurityContractApplication();

            // The fake application respository is going to return the mocked application.
            // Also, set the functions section of the application to null (just dont define it). This should set returned application model functions association to null.
            applicationSecurityContract.Fullname = "Test Application Fullname";

            var returnedApplicationModel = await securityContractApplicationService.ApplyResourceServerDefinitionAsync(applicationSecurityContract, Guid.NewGuid());

            Assert.True(returnedApplicationModel.Name == applicationSecurityContract.Fullname, $"Returned application name: '{returnedApplicationModel.Name}' does not match the expected valueL '{applicationSecurityContract.Fullname}'");
            // Even though the mock application has application functions associated with it, they should have been removed owing to empty functions section defined in the app security contract.
            Assert.True(returnedApplicationModel.ApplicationFunctions.Count == 0, $"Returned applications functions count expected to be '0'. Actual count is '{returnedApplicationModel.ApplicationFunctions.Count}'");
        }
        public async Task ApplyApplicationDefninitionWithFunctions_ExistingApplicationIsPresent_ReturnsUpdatedApplicationWithUpdatedFunctions()
        {
            // Create an application repository that returns the supplied models so that they can be interrogated, rather than going to the DB.
            // The main thng we want to test here is how the service maps from the security contract onto the model, which is lost if we simply
            // mock the model that is returned from the repository.

            // The fake repository has an overloaded constructor that allows us to inject the mocked model it will return when getById or getByName functions
            // are called on the fake repository.
            var applicationRespository = new ApplicationRepositoryFake(mockedApplication);
            var identityServiceApiResourceRepository = Substitute.For <IIdentityApiResourceRepository>();
            var permissionsRepository              = Substitute.For <IPermissionRepository>();
            var applicationFunctionRepository      = Substitute.For <IApplicationFunctionRepository>();
            var applicationDataPolicyRepository    = Substitute.For <IApplicationDataPolicyRepository>();
            var securityContractApplicationService = new SecurityContractApplicationService(applicationRespository, identityServiceApiResourceRepository, permissionsRepository, applicationFunctionRepository, applicationDataPolicyRepository);

            // Define an application security contract definition.
            var applicationSecurityContract = new SecurityContractApplication();

            // The fake application respository is going to return the mocked application.
            // Also, set the functions section of the application to null (just dont define it). This should set returned application model functions association to null.
            // The application name is the primary key when dealing with the YAML so set it to the name on the mocked model.
            applicationSecurityContract.Fullname             = "Mocked Application Name";
            applicationSecurityContract.ApplicationFunctions = new List <SecurityContractFunction> {
                new SecurityContractFunction
                {
                    Name        = "Test Function 1",
                    Description = "Test Function 1 description",
                    Permissions = new List <SecurityContractPermission> {
                        new SecurityContractPermission
                        {
                            Name        = "Permission 1",
                            Description = "Permission 1 description"
                        }
                    }
                }
            };

            var returnedApplicationModel = await securityContractApplicationService.ApplyResourceServerDefinitionAsync(applicationSecurityContract, Guid.NewGuid());

            Assert.True(returnedApplicationModel.Name == applicationSecurityContract.Fullname, $"Returned application name: '{returnedApplicationModel.Name}' does not match the expected value '{applicationSecurityContract.Fullname}'");
            // Even though the mock application has application functions associated with it, they would NOT have actually been removed as this requires the actual deletion to happen in order for the collection to be udpated.
            // This also applies to the function elements.
            Assert.True(returnedApplicationModel.ApplicationFunctions.Count == 3, $"Returned applications functions count expected to be '3'. Actual count is '{returnedApplicationModel.ApplicationFunctions.Count}'");
            Assert.True(returnedApplicationModel.ApplicationFunctions.First().Name == "Function 1", $"Returned function name expected to be 'Function 1'. Actual value is: '{returnedApplicationModel.ApplicationFunctions.First().Name}'");
        }
Exemple #3
0
 public UpdateApplicationStateHandlerTest()
 {
     _repository = new ApplicationRepositoryFake();
 }
Exemple #4
0
 public CreateApplicationHandlerTest()
 {
     _repository = new ApplicationRepositoryFake();
 }