示例#1
0
        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());
        }
示例#2
0
        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));
        }
示例#3
0
        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));
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        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));
        }