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()); }
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))); } }
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); }
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)); }
// 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; }
// 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; }
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)); } }
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)); }
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()); }
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); }
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); }
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); }
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); }
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); }
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)); } }
public async Task <DropPoint> Insert(DropPoint obj) { await Collection.InsertOneAsync(obj); return(obj); }
public void InsertPoint(DropPoint dp) { _dbContext.Add(dp); Save(); }
public void UpdatePoint(DropPoint dp) { _dbContext.Entry(dp).State = EntityState.Modified; Save(); }
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; }
public async Task<DropPoint> Insert(DropPoint obj) { await Collection.InsertOneAsync(obj); return obj; }
public DragQuery(Block b, int x, int y) { DraggedBlock = b; DragStartpoint.Set(x, y); DropPoint.Set(x, y); }
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_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_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_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()); }
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; }