예제 #1
0
        public async Task Insert()
        {
            var branch = new Branch()
            {
                Id             = Guid.NewGuid(),
                OrganisationId = Guid.NewGuid(),
                Name           = "Branch1"
            };

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

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

            ScopeOptions options  = null;
            Branch       inserted = null;

            service.Setup(c => c.InsertBranch(It.IsAny <ScopeOptions>(), It.Is <Branch>(m => m == branch)))
            .Callback((ScopeOptions o, Branch i) =>
            {
                inserted = i;
                options  = o;
            })
            .ReturnsAsync(result);

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

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

            var actual = await controller.Insert(branch);

            Assert.Same(branch, inserted);
            Assert.Equal(Scope.Branch, options.Scope);

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

            Assert.Same(result, returnValue);
        }