public async Task SaveNewMaintenanceLogFromViewModel_POSTEntityNotInUsersDepartment_ShouldFail()
        {
            //Arrange
            var model = new MaintenanceLogItemViewModel
            {
                EntityId          = 1,
                ComponentId       = 1,
                Name              = "Component1",
                SerialNumber      = "ABC",
                TaskDescription   = "Task1",
                ActionDescription = "Action1"
            };

            _entity.DepartmentId = 3;
            _entityRepositoryMock
            .Setup(x => x
                   .Get(It.Is <int>(i => i == model.EntityId)))
            .Returns(_entity);

            //Act
            var result = await _maintenanceLogController.Save(model);

            //Assert
            Assert.IsTrue(result.GetType() == typeof(UnauthorizedObjectResult));
        }
        public async Task SaveNewMaintenanceLogFromViewModel_POSTForEntity_ShouldSucceed()
        {
            //Arrange
            var model = new MaintenanceLogItemViewModel
            {
                EntityId          = 1,
                ComponentId       = 0,
                Name              = "Entity1",
                SerialNumber      = "ABC",
                TaskDescription   = "Task1",
                ActionDescription = "Action1"
            };

            _entityRepositoryMock
            .Setup(x => x
                   .Get(It.Is <int>(i => i == model.EntityId)))
            .Returns(_entity);

            _componentRepositoryMock
            .Setup(x => x
                   .Update(It.IsAny <Component>()));

            _entityRepositoryMock
            .Setup(x => x
                   .Update(It.IsAny <Entity>()));

            _maintenanceLogRepositoryMock
            .Setup(x => x
                   .Save(It.IsAny <MaintenanceLog>()))
            .Callback <MaintenanceLog>(x => x.MaintenanceLogId = 1);

            //Act
            var result = await _maintenanceLogController.Save(model);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.GetType() == typeof(OkObjectResult));
            _maintenanceLogRepositoryMock.VerifyAll();
            _maintenanceLogRepositoryMock.Verify(x => x.Save(It.IsAny <MaintenanceLog>()), Times.Exactly(1));
            _componentRepositoryMock.VerifyAll();
            _componentRepositoryMock.Verify(x => x.Update(It.IsAny <Component>()), Times.AtLeast(2));
            _entityRepositoryMock.VerifyAll();
            _entityRepositoryMock.Verify(x => x.Update(It.IsAny <Entity>()), Times.Exactly(1));
        }
        public async Task SaveNewMaintenanceLogFromViewModel_POSTSavingToDbFailed_ShouldFailAndNotUpdateEntityOrComponents()
        {
            //Arrange
            var model = new MaintenanceLogItemViewModel
            {
                EntityId          = 1,
                ComponentId       = 0,
                Name              = "Entity1",
                SerialNumber      = "ABC",
                TaskDescription   = "Task1",
                ActionDescription = "Action1"
            };

            _entityRepositoryMock
            .Setup(x => x
                   .Get(It.Is <int>(i => i == model.EntityId)))
            .Returns(_entity);

            _entityRepositoryMock
            .Setup(x => x
                   .Update(It.IsAny <Entity>()));

            _maintenanceLogRepositoryMock
            .Setup(x => x
                   .Save(It.IsAny <MaintenanceLog>()))
            .Callback <MaintenanceLog>(x => x.MaintenanceLogId = 0);

            //Act
            var result = await _maintenanceLogController.Save(model);

            var failResult = result as ObjectResult;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(ObjectResult), result.GetType());
            Assert.IsNotNull(failResult);
            Assert.AreEqual(500, failResult.StatusCode);
        }