public void ApisJsonBuilder_BuildForPath_NullPath_ShouldBuildForWholeCatalog()
 {
     //------------Setup for test--------------------------
     EnvironmentVariables.DnsName = "http://localhost/";
     EnvironmentVariables.Port = 3142;
     var mockAuthorizationService = new Mock<IAuthorizationService>();
     mockAuthorizationService.Setup(service => service.IsAuthorized(AuthorizationContext.View, It.IsAny<string>())).Returns(true);
     mockAuthorizationService.Setup(service => service.IsAuthorized(AuthorizationContext.Execute, It.IsAny<string>())).Returns(true);
     var mockResourceCatalog = new Mock<IResourceCatalog>();
     var resources = new List<IResource>();
     var resource1 = new Resource { ResourceName = "Execution Engine Test",ResourcePath = "Acceptance Testing Resources\\Execution Engine\\Execution Engine Test", ResourceType = ResourceType.WorkflowService};
     var resource2 = new Resource { ResourceName = "Hello World", ResourcePath = "Hello World", ResourceType = ResourceType.WorkflowService };
     var resource3 = new Resource { ResourceName = "9139Local", ResourcePath = "Acceptance Testing Resources\\9139Local", ResourceType = ResourceType.WorkflowService };
     
     resources.Add(resource1);
     resources.Add(resource2);
     resources.Add(resource3);
     mockResourceCatalog.Setup(catalog => catalog.GetResourceList(It.IsAny<Guid>())).Returns(resources);
     var apisJsonBuilder = new ApisJsonBuilder(mockAuthorizationService.Object,mockResourceCatalog.Object);
     var exceptedApisJson = GetExceptedApisJsonForServerNoSecurity();
     //------------Execute Test---------------------------
     var apisJson = apisJsonBuilder.BuildForPath(null,false);
     //------------Assert Results-------------------------
     Assert.IsNotNull(apisJson);
     Assert.AreEqual(exceptedApisJson,apisJson);
     Assert.AreEqual(exceptedApisJson.Apis.Count,apisJson.Apis.Count);
     Assert.AreEqual(exceptedApisJson.Apis[0].BaseUrl.Contains("secure"), apisJson.Apis[0].BaseUrl.Contains("secure"));
 }
        public void ApisJsonBuilder_Constructor_AuthorizationService_PropertySet()
        {
            //------------Setup for test--------------------------


            //------------Execute Test---------------------------
            var builder = new ApisJsonBuilder(new Mock<IAuthorizationService>().Object,new Mock<IResourceCatalog>().Object);
            //------------Assert Results-------------------------
            Assert.IsNotNull(builder.AuthorizationService);
            Assert.IsNotNull(builder.ResourceCatalog);
        }
        public void ApisJsonBuilder_BuildForPath_OnlyAuthorized_MixPublicWithSecure_ShouldBuildForWholeCatalog()
        {
            //------------Setup for test--------------------------
            EnvironmentVariables.DnsName = "http://localhost/";
            EnvironmentVariables.Port = 3142;
            var publicAuthorizedResourceID = Guid.NewGuid();
            var authorizedResource1 = Guid.NewGuid();
            var authorizedResource2 = Guid.NewGuid();
            var mockAuthorizationService = new Mock<IAuthorizationService>();
            mockAuthorizationService.Setup(service => service.IsAuthorized(AuthorizationContext.View, publicAuthorizedResourceID.ToString())).Returns(false);
            mockAuthorizationService.Setup(service => service.IsAuthorized(AuthorizationContext.Execute, publicAuthorizedResourceID.ToString())).Returns(false);
            mockAuthorizationService.Setup(service => service.IsAuthorized(AuthorizationContext.View, authorizedResource1.ToString())).Returns(true);
            mockAuthorizationService.Setup(service => service.IsAuthorized(AuthorizationContext.Execute, authorizedResource1.ToString())).Returns(true);
            mockAuthorizationService.Setup(service => service.IsAuthorized(AuthorizationContext.View, authorizedResource2.ToString())).Returns(true);
            mockAuthorizationService.Setup(service => service.IsAuthorized(AuthorizationContext.Execute, authorizedResource2.ToString())).Returns(true);
            mockAuthorizationService.Setup(service => service.IsAuthorized(GlobalConstants.GenericPrincipal, AuthorizationContext.View, publicAuthorizedResourceID.ToString())).Returns(true);
            mockAuthorizationService.Setup(service => service.IsAuthorized(GlobalConstants.GenericPrincipal, AuthorizationContext.Execute, publicAuthorizedResourceID.ToString())).Returns(true);
            var mockResourceCatalog = new Mock<IResourceCatalog>();
            var resources = new List<IResource>();
            var resource1 = new Resource { ResourceID = publicAuthorizedResourceID, ResourceName = "Execution Engine Test", ResourcePath = "Acceptance Testing Resources\\Execution Engine\\Execution Engine Test", ResourceType = ResourceType.WorkflowService };
            var resource2 = new Resource { ResourceID = authorizedResource1, ResourceName = "Hello World", ResourcePath = "Hello World", ResourceType = ResourceType.WorkflowService };
            var resource3 = new Resource { ResourceID = authorizedResource2, ResourceName = "9139Local", ResourcePath = "Acceptance Testing Resources\\9139Local", ResourceType = ResourceType.WorkflowService };

            resources.Add(resource1);
            resources.Add(resource2);
            resources.Add(resource3);
            mockResourceCatalog.Setup(catalog => catalog.GetResourceList(It.IsAny<Guid>())).Returns(resources);
            var apisJsonBuilder = new ApisJsonBuilder(mockAuthorizationService.Object, mockResourceCatalog.Object);
            var exceptedApisJson = GetExceptedApisJsonForServerSecurity();
            //------------Execute Test---------------------------
            var apisJson = apisJsonBuilder.BuildForPath(null,false);
            //------------Assert Results-------------------------
            Assert.IsNotNull(apisJson);
            Assert.AreEqual(exceptedApisJson, apisJson);
            Assert.AreEqual(exceptedApisJson.Apis.Count, apisJson.Apis.Count);
            Assert.AreEqual(exceptedApisJson.Apis[0].BaseUrl, apisJson.Apis[0].BaseUrl);
            Assert.AreEqual(exceptedApisJson.Apis[1].BaseUrl, apisJson.Apis[1].BaseUrl);
        }