コード例 #1
0
 public void Constructor_NullServiceRecipientRepository_Throws()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var _ = new OrganisationsController(Mock.Of <IOrganisationRepository>(), Mock.Of <ICreateOrganisationService>(), null);
     });
 }
 public static void Constructor_NullOrganisationService_Throws()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         _ = new OrganisationsController(Mock.Of <IOrganisationRepository>(), null, Mock.Of <IServiceRecipientRepository>());
     });
 }
コード例 #3
0
        public async Task Get()
        {
            var organisation = new OrganisationEdit()
            {
                Id     = Guid.NewGuid(),
                Name   = "organisation_1",
                Config = new Config()
            };

            var service     = new Mock <IOrganisationService>();
            var authService = TestHelper.MockAuthenticationService(Scope.Branch);

            service.Setup(c => c.GetOrganisation(It.IsAny <ScopeOptions>(), It.Is <Guid>(m => m == organisation.Id.Value)))
            .ReturnsAsync(organisation);

            var controller = new OrganisationsController(authService.Object, service.Object, null);

            controller.ControllerContext = TestHelper.GetControllerContext(new ClaimsPrincipal());

            var result = await controller.Get(organisation.Id.Value);

            var okResult    = Assert.IsType <OkObjectResult>(result);
            var returnValue = Assert.IsType <OrganisationEdit>(okResult.Value);

            Assert.Same(organisation, returnValue);
        }
コード例 #4
0
 public void TestInitialize()
 {
     userManager              = DbInitializer.CreateUserManager();
     playlistManager          = DbInitializer.CreatePlaylistManager();
     _organisationManager     = DbInitializer.CreateOrganisationManager();
     _organisationsController = new OrganisationsController(DbInitializer.CreateOrganisationManager(), userManager, playlistManager);
     DbInitializer.Initialize();
 }
コード例 #5
0
        protected override void Setup()
        {
            var mockEnrichmentService = new Mock <IEnrichmentService>();

            mockEnrichmentService.Setup(x => x.GetCourseEnrichmentMetadata(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new List <UcasCourseEnrichmentGetModel>());

            organisationsController = new OrganisationsController(Context, mockEnrichmentService.Object);
        }
コード例 #6
0
        public void Setup()
        {
            _mockOrganisationRepository = new Mock <IOrganisationRepository>();
            _mockUnitOfWork             = new MockUnitOfWork
            {
                OrganisationRepository = _mockOrganisationRepository.Object
            };

            _organisationService = new OrganisationService(_mockUnitOfWork);

            _organisationsController = new OrganisationsController(_organisationService);
        }
コード例 #7
0
        public async Task Index()
        {
            var organisation = new Organisation()
            {
                Id   = Guid.NewGuid(),
                Name = "organisation_1"
            };

            var items = new PagedItems <Organisation>()
            {
                TotalItems = 1,
                Items      = new List <Organisation>()
                {
                    organisation
                }
            };

            var service     = new Mock <IOrganisationService>();
            var authService = TestHelper.MockAuthenticationService(Scope.Branch);

            OrganisationQueryOptions queryOptions = null;

            service.Setup(c => c.GetOrganisations(It.IsAny <OrganisationQueryOptions>()))
            .Callback((OrganisationQueryOptions options) => queryOptions = options)
            .ReturnsAsync(items);

            var controller = new OrganisationsController(authService.Object, service.Object, null);

            controller.ControllerContext = TestHelper.GetControllerContext(new ClaimsPrincipal());

            var result = await controller.Index();

            Assert.Equal(Scope.Branch, queryOptions.Scope.Scope);
            Assert.Equal("Name", queryOptions.SortOptions.Column);
            Assert.Equal(SortDirection.Ascending, queryOptions.SortOptions.Direction);
            Assert.Equal(0, queryOptions.PageOptions.Size);
            Assert.Equal(0, queryOptions.PageOptions.Number);

            var okResult    = Assert.IsType <OkObjectResult>(result);
            var returnValue = Assert.IsType <PagedItems <Organisation> >(okResult.Value);

            Assert.Same(items, returnValue);
        }
コード例 #8
0
        public async Task Update()
        {
            var organisation = new OrganisationEdit()
            {
                Id     = Guid.NewGuid(),
                Name   = "organisation_1",
                Config = new Config()
            };

            var service     = new Mock <IOrganisationService>();
            var authService = TestHelper.MockAuthenticationService(Scope.Branch);

            var result = new Result()
            {
                Success = true
            };

            ScopeOptions     options = null;
            OrganisationEdit updated = null;

            service.Setup(c => c.UpdateOrganisation(It.IsAny <ScopeOptions>(), It.Is <OrganisationEdit>(m => m == organisation)))
            .Callback((ScopeOptions o, OrganisationEdit u) =>
            {
                updated = u;
                options = o;
            })
            .ReturnsAsync(result);

            var controller = new OrganisationsController(authService.Object, service.Object, null);

            controller.ControllerContext = TestHelper.GetControllerContext(new ClaimsPrincipal());

            var actual = await controller.Update(organisation.Id.Value, organisation);

            Assert.Same(organisation, updated);
            Assert.Equal(Scope.Branch, options.Scope);

            var okResult    = Assert.IsType <OkObjectResult>(actual);
            var returnValue = Assert.IsType <Result>(okResult.Value);

            Assert.Same(result, returnValue);
        }
コード例 #9
0
        public OrganisationsControllerTests()
        {
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "1"),
                new Claim(ClaimTypes.Role, "Admin"),
            }, "mock"));
            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Cookie"] = $"access_token=xxxxx";
            httpContext.User = user;

            _mockUseCase    = new Mock <IOrganisationsUseCase>();
            _classUnderTest = new OrganisationsController(_mockUseCase.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = httpContext
                }
            };
        }
コード例 #10
0
        public void TestInitialize()
        {
            _documentStore        = DocumentStoreHelper.StartRaven();
            _mockUserContext      = new Mock <IUserContext>();
            _mockCommandProcessor = new Mock <ICommandProcessor>();
            _mockOrganisationsViewModelBuilder    = new Mock <IOrganisationsViewModelBuilder>();
            _mockStreamItemsViewModelBuilder      = new Mock <IStreamItemsViewModelBuilder>();
            _mockTeamsViewModelBuilder            = new Mock <ITeamsViewModelBuilder>();
            _mockPostsViewModelBuilder            = new Mock <IPostsViewModelBuilder>();
            _mockMemberViewModelBuilder           = new Mock <IMemberViewModelBuilder>();
            _mockReferenceSpeciesViewModelBuilder = new Mock <IReferenceSpeciesViewModelBuilder>();

            _controller = new OrganisationsController(
                _mockCommandProcessor.Object,
                _mockUserContext.Object,
                _mockOrganisationsViewModelBuilder.Object,
                _mockStreamItemsViewModelBuilder.Object,
                _mockTeamsViewModelBuilder.Object,
                _mockPostsViewModelBuilder.Object,
                _mockMemberViewModelBuilder.Object,
                _mockReferenceSpeciesViewModelBuilder.Object
                );
        }