public async Task Test_Search_DropPoint_As_Administrator_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "23456",
                testDropPointName,
                testAddress);
            var dropPoints = new List <DropPoint>()
            {
                DropPoint
            };

            DropPointServiceMock.Setup(x => x.SearchDropPoints(testUserId, It.IsAny <string>()))
            .ReturnsAsync(dropPoints);

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(true);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(true);

            Mock <HttpRequestMessage> httpRequestMock = new Mock <HttpRequestMessage>();

            Controller.User    = IIPrincipalMock.Object;
            Controller.Request = httpRequestMock.Object;

            var result = await Controller.Search("test_query", testUserId);

            Assert.IsInstanceOf <OkNegotiatedContentResult <PageEnvelope <DropPoint> > >(result);

            var convertedResult = result as OkNegotiatedContentResult <PageEnvelope <DropPoint> >;

            Assert.IsNotNull(convertedResult);
            Assert.AreEqual(1, convertedResult.Content.data.Count());
            Assert.AreEqual(DropPoint, convertedResult.Content.data.First());
        }
示例#2
0
        public async Task <IHttpActionResult> Put(DropPoint value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var authorizedId = User.Identity.GetUserId();

            if (value.UserId != null && value.UserId != authorizedId &&
                !IsUserAdminOrBackendOfficeAdmin())
            {
                // TODO: Need to fix this differently by a proper result
                return(Unauthorized());
            }

            if (IsUserAdminOrBackendOfficeAdmin())
            {
                return(Ok(await service.Update(value)));
            }
            else
            {
                return(Ok(await service.Update(value, value.UserId)));
            }
        }
示例#3
0
        public async Task <IActionResult> Edit(int id, [Bind("DropPointName,NewDropPointName,RouteId")] DropPoint dropPoint)
        {
            if (id != dropPoint.DropPointId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(dropPoint);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DropPointExists(dropPoint.DropPointId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RouteId"] = new SelectList(_context.Route, "RouteId", "RouteName", dropPoint.RouteId);
            return(View(dropPoint));
        }
        public async Task Test_Search_DropPoint_As_User_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "23456",
                testDropPointName,
                testAddress);
            var dropPoints = new List <DropPoint>()
            {
                DropPoint
            };

            DropPointServiceMock.Setup(x => x.SearchDropPoints(testUserId, It.IsAny <string>()))
            .ReturnsAsync(dropPoints);

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(false);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(false);

            Mock <HttpRequestMessage> httpRequestMock = new Mock <HttpRequestMessage>();

            Controller.User    = IIPrincipalMock.Object;
            Controller.Request = httpRequestMock.Object;

            var result = await Controller.Search("test_query", "23456");

            Assert.IsInstanceOf <UnauthorizedResult>(result);
        }
        public async Task Test_Delete_DropPoint_As_User_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "23456",
                testDropPointName,
                testAddress)
            {
                Id = "test_dropPoint_id"
            };

            DropPointServiceMock.Setup(x => x.Delete("test_dropPoint_id", "23456"))
            .Returns <string, string>((id, userId) => Task.FromResult <DropPoint>(DropPoint));

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(false);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(false);

            Mock <HttpRequestMessage> httpRequestMock = new Mock <HttpRequestMessage>();

            Controller.User    = IIPrincipalMock.Object;
            Controller.Request = httpRequestMock.Object;

            var result = await Controller.Delete("test_dropPoint_id", "23456");

            Assert.IsInstanceOf <UnauthorizedResult>(result);
        }
        public async Task Test_Delete_DropPoint_As_Administrator_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "23456",
                testDropPointName,
                testAddress)
            {
                Id = "test_dropPoint_id"
            };

            DropPointServiceMock.Setup(x => x.Delete("test_dropPoint_id"))
            .Returns <string>((id) => Task.FromResult <DropPoint>(DropPoint));

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(true);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(false);

            Mock <HttpRequestMessage> httpRequestMock = new Mock <HttpRequestMessage>();

            Controller.User    = IIPrincipalMock.Object;
            Controller.Request = httpRequestMock.Object;

            var result = await Controller.Delete("test_dropPoint_id", "23456");

            Assert.IsInstanceOf <OkNegotiatedContentResult <DropPoint> >(result);

            var convertedResult = result as OkNegotiatedContentResult <DropPoint>;

            Assert.IsNotNull(convertedResult.Content);
            Assert.AreEqual(DropPoint.Address, convertedResult.Content.Address);
            Assert.AreEqual(DropPoint.UserId, convertedResult.Content.UserId);
            Assert.AreEqual("test_dropPoint_id", convertedResult.Content.Id);
            Assert.AreEqual(DropPoint.Name, convertedResult.Content.Name);
        }
        public async Task Test_Post_DropPoint_As_Administrator_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "456789",
                testDropPointName,
                testAddress);

            DropPointServiceMock.Setup(x => x.Insert(It.IsAny <DropPoint>()))
            .Returns <DropPoint>((x) => Task.FromResult(x));

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(true);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(true);

            Controller.User = IIPrincipalMock.Object;
            var result = await Controller.Post(DropPoint);

            Assert.IsInstanceOf <OkNegotiatedContentResult <DropPoint> >(result);

            var convertedResult = result as OkNegotiatedContentResult <DropPoint>;

            Assert.IsNotNull(convertedResult.Content);
            Assert.AreEqual(DropPoint.Address, convertedResult.Content.Address);
            Assert.AreEqual(DropPoint.Name, convertedResult.Content.Name);
            Assert.AreEqual(DropPoint.UserId, convertedResult.Content.UserId);
        }
示例#8
0
        public async Task <IHttpActionResult> Post([FromBody] DropPoint value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var authorizedId = User.Identity.GetUserId();


            if (value.UserId != null && value.UserId != authorizedId &&
                !IsUserAdminOrBackendOfficeAdmin())
            {
                // TODO: Need to fix this differently by a proper result
                return(Unauthorized());
            }

            value.Id = default(string);
            if (string.IsNullOrWhiteSpace(value.UserId))
            {
                value.UserId = authorizedId;
            }
            var result = await service.Insert(value);

            return(Ok(result));
        }
示例#9
0
 // Start is called before the first frame update
 void Start()
 {
     AIDropPoint = GameObject.FindGameObjectWithTag(ENEMY_DROPPOINT).GetComponent <DropPoint>();
     GameObject[] unitsTab = GameObject.FindGameObjectsWithTag("Enemy");
     units.AddRange(unitsTab);
     currentPopulation = units.Count;
 }
示例#10
0
 // Start is called before the first frame update
 void Start()
 {
     AIDropPoint = GameObject.FindGameObjectWithTag(ENEMY_DROPPOINT).GetComponent <DropPoint>();
     GameObject[] unitsTab = GameObject.FindGameObjectsWithTag("Enemy");
     units.AddRange(unitsTab);
     currentPopulation        = units.Count;
     scarceRessourceThreshold = GameManager._instance.ressourceThreshold;
 }
示例#11
0
 public IActionResult PostDropPoints([FromBody] DropPoint dp)
 {
     using (var scope = new TransactionScope())
     {
         _dpRepository.InsertPoint(dp);
         scope.Complete();
         return(CreatedAtAction(nameof(GetDropPoints), new { id = dp.DropPointId }, dp));
     }
 }
示例#12
0
        public async Task <IActionResult> Create([Bind("DropPointName,NewDropPointName,RouteId")] DropPoint dropPoint)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dropPoint);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RouteId"] = new SelectList(_context.Route, "RouteId", "RouteName", dropPoint.RouteId);
            return(View(dropPoint));
        }
示例#13
0
 public IActionResult PutDropPoints([FromBody] DropPoint dp)
 {
     if (dp != null)
     {
         using (var scope = new TransactionScope())
         {
             _dpRepository.UpdatePoint(dp);
             scope.Complete();
             return(new OkResult());
         }
     }
     return(new NoContentResult());
 }
示例#14
0
        public async Task <DropPoint> Update(DropPoint obj)
        {
            if (string.IsNullOrWhiteSpace(obj.Id))
            {
                throw new ArgumentNullException(nameof(obj.Id));
            }
            var result = await Collection.FindOneAndReplaceAsync(x => x.Id == obj.Id, obj);

            if (result == null)
            {
                throw new EntityUpdateException(typeof(DropPoint), obj.Id);
            }
            return(result);
        }
示例#15
0
        public async Task Test_Post_DropPoint_As_User_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "456789",
                testDropPointName,
                testAddress);

            DropPointServiceMock.Setup(x => x.Insert(It.IsAny<DropPoint>())).Returns<DropPoint>((x) => Task.FromResult(x));

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(false);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(false);

            Controller.User = IIPrincipalMock.Object;

            var result = await Controller.Post(DropPoint);
            Assert.IsInstanceOf<UnauthorizedResult>(result);
        }
示例#16
0
        public async Task Test_Post_DropPoint_As_User_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "456789",
                testDropPointName,
                testAddress);

            DropPointServiceMock.Setup(x => x.Insert(It.IsAny <DropPoint>())).Returns <DropPoint>((x) => Task.FromResult(x));

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(false);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(false);

            Controller.User = IIPrincipalMock.Object;

            var result = await Controller.Post(DropPoint);

            Assert.IsInstanceOf <UnauthorizedResult>(result);
        }
示例#17
0
        public async Task <DropPoint> Update(DropPoint obj, string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (string.IsNullOrWhiteSpace(obj.Id))
            {
                throw new ArgumentNullException(nameof(obj.Id));
            }

            var result = await Collection.FindOneAndReplaceAsync(x => x.Id == obj.Id && x.UserId == userId, obj);

            if (result == null)
            {
                throw new EntityUpdateException($"DropPoint with user id {userId} and id {obj.Id} is invalid");
            }
            return(result);
        }
示例#18
0
        public async Task Test_Post_DropPoint_As_User()
        {
            DropPoint = new DropPoint(
                testUserId,
                testDropPointName,
                testAddress);

            DropPointServiceMock.Setup(x => x.Insert(It.IsAny<DropPoint>())).Returns<DropPoint>((x) => Task.FromResult(x));

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(false);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(false);

            Controller.User = IIPrincipalMock.Object;

            var result = await Controller.Post(DropPoint);
            Assert.IsInstanceOf<OkNegotiatedContentResult<DropPoint>>(result);

            var convertedResult = result as OkNegotiatedContentResult<DropPoint>;
            Assert.IsNotNull(convertedResult.Content);
            Assert.AreEqual(DropPoint.Address, convertedResult.Content.Address);
            Assert.AreEqual(DropPoint.Name, convertedResult.Content.Name);
            Assert.AreEqual(DropPoint.UserId, convertedResult.Content.UserId);
        }
示例#19
0
        public async Task<IHttpActionResult> Put(DropPoint value)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var authorizedId = User.Identity.GetUserId();

            if (value.UserId != null && value.UserId != authorizedId
                && !IsUserAdminOrBackendOfficeAdmin())
            {
                // TODO: Need to fix this differently by a proper result
                return Unauthorized();
            }
         
            if(IsUserAdminOrBackendOfficeAdmin())
            {
                return Ok(await service.Update(value));
            }
            else
            {
                return Ok(await service.Update(value, value.UserId));
            }
            
        }
示例#20
0
        public async Task <DropPoint> Insert(DropPoint obj)
        {
            await Collection.InsertOneAsync(obj);

            return(obj);
        }
示例#21
0
 public void InsertPoint(DropPoint dp)
 {
     _dbContext.Add(dp);
     Save();
 }
示例#22
0
 public void UpdatePoint(DropPoint dp)
 {
     _dbContext.Entry(dp).State = EntityState.Modified;
     Save();
 }
示例#23
0
        public async Task<DropPoint> Update(DropPoint obj, string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (string.IsNullOrWhiteSpace(obj.Id))
            {
                throw new ArgumentNullException(nameof(obj.Id));
            }

            var result = await Collection.FindOneAndReplaceAsync(x => x.Id == obj.Id && x.UserId == userId, obj);
            if (result == null)
                throw new EntityUpdateException($"DropPoint with user id {userId} and id {obj.Id} is invalid");
            return result;
        }
示例#24
0
 public async Task<DropPoint> Insert(DropPoint obj)
 {
     await Collection.InsertOneAsync(obj);
     return obj;
 }
示例#25
0
 public DragQuery(Block b, int x, int y)
 {
     DraggedBlock = b;
     DragStartpoint.Set(x, y);
     DropPoint.Set(x, y);
 }
示例#26
0
        public async Task Test_Delete_DropPoint_As_Administrator_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "23456",
                testDropPointName,
                testAddress)
            {
                Id = "test_dropPoint_id"
            };

            DropPointServiceMock.Setup(x => x.Delete("test_dropPoint_id"))
                .Returns<string>((id) => Task.FromResult<DropPoint>(DropPoint));

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(true);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(false);

            Mock<HttpRequestMessage> httpRequestMock = new Mock<HttpRequestMessage>();

            Controller.User = IIPrincipalMock.Object;
            Controller.Request = httpRequestMock.Object;

            var result = await Controller.Delete("test_dropPoint_id", "23456");
            Assert.IsInstanceOf<OkNegotiatedContentResult<DropPoint>>(result);

            var convertedResult = result as OkNegotiatedContentResult<DropPoint>;
            Assert.IsNotNull(convertedResult.Content);
            Assert.AreEqual(DropPoint.Address, convertedResult.Content.Address);
            Assert.AreEqual(DropPoint.UserId, convertedResult.Content.UserId);
            Assert.AreEqual("test_dropPoint_id", convertedResult.Content.Id);
            Assert.AreEqual(DropPoint.Name, convertedResult.Content.Name);
        }
示例#27
0
        public async Task Test_Delete_DropPoint_As_User_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "23456",
                testDropPointName,
                testAddress)
            {
                Id = "test_dropPoint_id"
            };

            DropPointServiceMock.Setup(x => x.Delete("test_dropPoint_id", "23456"))
                .Returns<string, string>((id, userId) => Task.FromResult<DropPoint>(DropPoint));

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(false);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(false);

            Mock<HttpRequestMessage> httpRequestMock = new Mock<HttpRequestMessage>();

            Controller.User = IIPrincipalMock.Object;
            Controller.Request = httpRequestMock.Object;

            var result = await Controller.Delete("test_dropPoint_id", "23456");
            Assert.IsInstanceOf<UnauthorizedResult>(result);
        }
示例#28
0
        public async Task Test_Search_DropPoint_As_User_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "23456",
                testDropPointName,
                testAddress);
            var dropPoints = new List<DropPoint>() { DropPoint };

            DropPointServiceMock.Setup(x => x.SearchDropPoints(testUserId, It.IsAny<string>()))
                .ReturnsAsync(dropPoints);

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(false);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(false);

            Mock<HttpRequestMessage> httpRequestMock = new Mock<HttpRequestMessage>();

            Controller.User = IIPrincipalMock.Object;
            Controller.Request = httpRequestMock.Object;

            var result = await Controller.Search("test_query", "23456");
            Assert.IsInstanceOf<UnauthorizedResult>(result);
        }
示例#29
0
        public async Task Test_Search_DropPoint_As_Administrator_With_Other_UserId()
        {
            DropPoint = new DropPoint(
                "23456",
                testDropPointName,
                testAddress);
            var dropPoints = new List<DropPoint>() { DropPoint };

            DropPointServiceMock.Setup(x => x.SearchDropPoints(testUserId, It.IsAny<string>()))
                .ReturnsAsync(dropPoints);

            SetupAuth();
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_ADMINISTRATOR)).Returns(true);
            IIPrincipalMock.Setup(x => x.IsInRole(RoleNames.ROLE_BACKOFFICEADMIN)).Returns(true);

            Mock<HttpRequestMessage> httpRequestMock = new Mock<HttpRequestMessage>();

            Controller.User = IIPrincipalMock.Object;
            Controller.Request = httpRequestMock.Object;

            var result = await Controller.Search("test_query", testUserId);
            Assert.IsInstanceOf<OkNegotiatedContentResult<PageEnvelope<DropPoint>>>(result);
            
            var convertedResult = result as OkNegotiatedContentResult<PageEnvelope<DropPoint>>;
            Assert.IsNotNull(convertedResult);
            Assert.AreEqual(1, convertedResult.Content.data.Count());
            Assert.AreEqual(DropPoint, convertedResult.Content.data.First());
        }
示例#30
0
 public async Task<DropPoint> Update(DropPoint obj)
 {
     if (string.IsNullOrWhiteSpace(obj.Id))
     {
         throw new ArgumentNullException(nameof(obj.Id));
     }
     var result = await Collection.FindOneAndReplaceAsync(x => x.Id == obj.Id, obj);
     if (result == null)
         throw new EntityUpdateException(typeof(DropPoint), obj.Id);
     return result;
 }