public void TestUserHasNoRightstoRetrieveUnits() { Unit aUnit = new Unit() { UNIT_ID = 1001 }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; mockUnitProfileService.Setup(s => s.GetById(It.IsAny <long>())).Returns(Task.FromResult(unitProfile)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(false); unitController = new UnitController(mockUnitProfileService.Object); Assert.ThrowsAsync <UnauthorizedAccessException>(async() => await unitController.GetAll()); }
public void TestRetrieveaUnitById() { Unit aUnit = new Unit() { UNIT_ID = 1001 }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; mockUnitProfileService.Setup(s => s.GetById(It.IsAny <long>())).Returns(Task.FromResult(unitProfile)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(true); unitController = new UnitController(mockUnitProfileService.Object); var result = unitController.Get(aUnit.UNIT_ID); var entity = result.Result; Assert.That(entity.Unit.UNIT_ID, Is.EqualTo(aUnit.UNIT_ID)); }
public void TestUserhasPrivsToDeactivateUnit() { Unit aUnit = new Unit() { UNIT_ID = 1001, UNIT_CODE = "R10001", ACTIVE_FLAG = 0 }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; mockUnitProfileService.Setup(s => s.RemoveItem(It.IsAny <UnitProfile>())).Returns(Task.FromResult(unitProfile)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(true); unitController = new UnitController(mockUnitProfileService.Object); Assert.DoesNotThrowAsync(async() => await unitController.Post(unitProfile)); }
public void TestUserHasNoPrivstoDeactivateUnits() { Unit aUnit = new Unit() { UNIT_ID = 1001, UNIT_CODE = "R10001", ACTIVE_FLAG = 0 }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; // mockUnitService.Setup(s => s.RemoveItem(It.IsAny<Unit>())).Returns(Task.FromResult(aUnit)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(false); unitController = new UnitController(mockUnitProfileService.Object); Assert.ThrowsAsync <UnauthorizedAccessException>(async() => await unitController.Post(unitProfile)); }
public void TestUserUpdateUnitWithUpdateResponse() { Unit aUnit = new Unit() { UNIT_ID = 1001, UNIT_CODE = "R10001" }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; mockUnitProfileService.Setup(s => s.SaveOrUpdate(It.IsAny <UnitProfile>())).Returns(Task.FromResult(unitProfile)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(true); unitController = new UnitController(mockUnitProfileService.Object); var result = unitController.Post(unitProfile); var resultingProfile = result.Result; Assert.That(resultingProfile.Unit.UNIT_CODE, Is.EqualTo(aUnit.UNIT_CODE)); }
public void TestUserUpdateUnitDeactivatedUpdateResponse() { Unit aUnit = new Unit() { UNIT_ID = 1001, UNIT_CODE = "R10001", ACTIVE_FLAG = 0 }; UnitProfile unitProfile = new UnitProfile() { Unit = aUnit }; mockUnitProfileService.Setup(s => s.RemoveItem(It.IsAny <UnitProfile>())).Returns(Task.FromResult(unitProfile)); mockAuthenticationService.Setup(s => s.UserHasPrivs(It.IsAny <User>())).Returns(true); unitController = new UnitController(mockUnitProfileService.Object); var result = unitController.Post(unitProfile); var resultingProfile = result.Result; Assert.That(resultingProfile.Unit.ACTIVE_FLAG, Is.EqualTo(0)); }