コード例 #1
0
        public async Task <IActionResult> PostToAddNewGroup(
            [FromBody] AddCompanyRequest request,
            [FromServices] ICommandHandler <AddGroupCommand> _addGroupCommandHandler
            )
        {
            _logger.LogInformation("Running POST method to ADD new group");
            if (request == null)
            {
                request = new AddCompanyRequest();
            }


            //Gets Bizfly identity from header.
            BizflyIdentity bizflyIdentity = Request.Headers.GetIdentityFromHeaders();

            AddGroupCommand command = new AddGroupCommand(bizflyIdentity, request.NewGroupId, bizflyIdentity.UserId, request.GroupName, "COMPANY");
            await _addGroupCommandHandler.Handle(command);

            if (ModelState.IsValid)
            {
                _logger.LogInformation("New Group is created with id = {0}", request.NewGroupId);
                return(CreatedAtAction(nameof(Get), new { id = request.NewGroupId }, null));
            }
            return(BadRequest(ModelState));
        }
コード例 #2
0
        public async Task TestSuspendHandler_ToThrowNotFound_WhenGroupNotFound()
        {
            var identity = new BizflyIdentity();

            string groupId = "test-group-id";
            string ownerId = "test-user-id";

            _mockGroupRepository
            .Setup(repo => repo.GetByIdAsync(groupId))
            .Throws(new ResourceNotFoundException())
            .Verifiable();


            //  _mockGroupRepository
            //.Setup(repo => repo.AddOrUpdateAsync(It.IsAny<Group>(), null))
            //.Throws(new ResourceNotFoundException());



            SuspendGroupCommand command = new SuspendGroupCommand(identity, groupId, ownerId);


            await _suspendGroupHandler.Handle(command);

            _mockGroupRepository.Verify();
        }
コード例 #3
0
 public AddGroupCommand(BizflyIdentity identity, string newGroupId, string ownerUserId, string groupName, string groupType) : base(identity)
 {
     NewGroupId  = newGroupId;
     OwnerUserId = ownerUserId;
     GroupName   = groupName;
     GroupType   = groupType;
 }
コード例 #4
0
        public async Task HandlerThrowsException_WhenCommandIsInvalid()
        {
            var identity = new BizflyIdentity();



            //group id must be in Guid format
            string groupId   = "878a04bd-ee90-40df-8745-354165893b7e";
            string groupName = "test-group";



            AddGroupCommand command = new AddGroupCommand(identity, groupId, identity.UserId, groupName, "COMPANY");


            await _authoriserDecorator.Handle(command);
        }
コード例 #5
0
        public async Task <IActionResult> PostToSuspendGroup(
            string id,
            [FromServices] ICommandHandler <SuspendGroupCommand> _suspendGroupCommandHandler)
        {
            _logger.LogInformation("Running POST method to SUSPEND group by ID");
            //Gets Bizfly identity from header.
            BizflyIdentity bizflyIdentity = Request.Headers.GetIdentityFromHeaders();

            SuspendGroupCommand command = new SuspendGroupCommand(bizflyIdentity, id, bizflyIdentity.UserId);

            await _suspendGroupCommandHandler.Handle(command);


            if (ModelState.IsValid)
            {
                return(Ok());
            }
            return(BadRequest(ModelState));
        }
コード例 #6
0
        public async Task <IActionResult> Get(
            string id,
            [FromServices] IQueryHandler <GetGroupSmallDetailDTOQuery, GroupSmallDetailDTO> _getGroupSmallDetailDTOQueryHandler
            )
        {
            _logger.LogInformation("Running GET method to FETCH group by ID");
            //Gets Bizfly identity from header.
            BizflyIdentity bizflyIdentity = Request.Headers.GetIdentityFromHeaders();

            GetGroupSmallDetailDTOQuery query  = new GetGroupSmallDetailDTOQuery(bizflyIdentity, id);
            GroupSmallDetailDTO         result = await _getGroupSmallDetailDTOQueryHandler.HandleAsync(query);

            if (ModelState.IsValid)
            {
                return(Ok(result));
            }

            return(BadRequest(ModelState));
        }
コード例 #7
0
        public async Task <IActionResult> Delete(
            string id,
            [FromServices] ICommandHandler <DeleteGroupCommand> _deleteGroupCommandHandler)
        {
            _logger.LogInformation("Running DELETE method for GroupId = {0} ", id);

            //Gets Bizfly identity from header.
            BizflyIdentity bizflyIdentity = Request.Headers.GetIdentityFromHeaders();


            DeleteGroupCommand command = new DeleteGroupCommand(bizflyIdentity, id, bizflyIdentity.UserId);
            await _deleteGroupCommandHandler.Handle(command);

            if (ModelState.IsValid)
            {
                _logger.LogInformation("Group is deleted by ID = {0}", id);
                return(NoContent());
            }
            return(BadRequest(ModelState));
        }
コード例 #8
0
        public static BizflyIdentity GetIdentityFromHeaders(this IHeaderDictionary headers)
        {
            var bizflyIdentity = new BizflyIdentity();

            if (headers.TryGetValue("userId", out var userId))
            {
                bizflyIdentity.UserId = userId.ToString();
            }
            if (headers.TryGetValue("groupId", out var groupId))
            {
                bizflyIdentity.GroupId = userId.ToString();
            }
            if (headers.TryGetValue("groupType", out var groupType))
            {
                bizflyIdentity.GroupType = userId.ToString();
            }
            if (headers.TryGetValue("permissions", out var permissions))
            {
                bizflyIdentity.Permissions = userId.ToString().Split(',');
            }

            return(bizflyIdentity);
        }
コード例 #9
0
 public GetGroupSmallDetailDTOQuery(BizflyIdentity identity, string id)
     : base(identity)
 {
     Id = id;
 }
コード例 #10
0
 public GetAllGroupSmallDetailDTOQuery(BizflyIdentity identity)
     : base(identity)
 {
 }
コード例 #11
0
 public void Test1()
 {
     var identity = new BizflyIdentity();
 }
コード例 #12
0
 public ReactivateGroupCommand(BizflyIdentity identity, string companyId, string ownerId) : base(identity)
 {
     CompanyId = companyId;
     OwnerId   = ownerId;
 }
コード例 #13
0
 public SuspendGroupCommand(BizflyIdentity identity, string companyId, string ownerId)
     : base(identity)
 {
     CompanyId = companyId;
     OwnerId   = ownerId;
 }
コード例 #14
0
 public DeleteGroupCommand(BizflyIdentity identity, string id, string ownerId) : base(identity)
 {
     Id          = id;
     OwnerUserId = ownerId;
 }
コード例 #15
0
ファイル: Query.cs プロジェクト: luckybawa/test_prj
 public Query(BizflyIdentity identity)
 {
     Identity = identity;
 }