示例#1
0
        public void Should_Create_New_Monitor()
        {
            MockExternalLinks();

            var userAndOrg = new UserAndOrganizationDTO()
            {
                OrganizationId = 2,
                UserId         = "1"
            };

            var monitor = new MonitorDTO()
            {
                Name = "Test4"
            };

            _monitorService.CreateMonitor(monitor, userAndOrg);
            _monitorsDbSet.Received(1).Add(Arg.Any <Monitor>());
        }
示例#2
0
        public void Should_Throw_When_Creating_Monitor_With_Existing_Name()
        {
            MockExternalLinks();

            var userAndOrg = new UserAndOrganizationDTO()
            {
                OrganizationId = 2,
                UserId         = "1"
            };
            var monitor = new MonitorDTO()
            {
                Name = "Test1"
            };

            var ex = Assert.Throws <ValidationException>(() => _monitorService.CreateMonitor(monitor, userAndOrg));

            Assert.That(ex.ErrorCode, Is.EqualTo(ErrorCodes.DuplicatesIntolerable));
        }
示例#3
0
        public void Should_Update_Monitor()
        {
            MockExternalLinks();

            var userAndOrg = new UserAndOrganizationDTO()
            {
                OrganizationId = 2,
                UserId         = "1"
            };

            var monitor = new MonitorDTO()
            {
                Name = "Test4", Id = 1
            };

            _monitorService.UpdateMonitor(monitor, userAndOrg);
            _uow.Received(1).SaveChanges(false);
        }
示例#4
0
        public void Should_Throw_When_Updating_Not_Existing_Monitor()
        {
            MockExternalLinks();

            var userAndOrg = new UserAndOrganizationDTO()
            {
                OrganizationId = 2,
                UserId         = "1"
            };

            var monitor = new MonitorDTO()
            {
                Name = "Test2", Id = 5
            };

            var ex = Assert.Throws <ValidationException>(() => _monitorService.UpdateMonitor(monitor, userAndOrg));

            Assert.That(ex.ErrorCode, Is.EqualTo(ErrorCodes.ContentDoesNotExist));
        }
示例#5
0
        public void CreateMonitor(MonitorDTO newMonitor, UserAndOrganizationDTO userAndOrganizationDTO)
        {
            if (_monitorsDbSet.Any(x => x.Name == newMonitor.Name &&
                                   x.OrganizationId == userAndOrganizationDTO.OrganizationId))
            {
                throw new ValidationException(ErrorCodes.DuplicatesIntolerable, "Monitor names should be unique");
            }

            var timestamp = DateTime.UtcNow;
            var monitor   = new Monitor()
            {
                Created        = timestamp,
                Modified       = timestamp,
                CreatedBy      = userAndOrganizationDTO.UserId,
                ModifiedBy     = userAndOrganizationDTO.UserId,
                Name           = newMonitor.Name,
                OrganizationId = userAndOrganizationDTO.OrganizationId
            };

            _monitorsDbSet.Add(monitor);
            _uow.SaveChanges(false);
        }
示例#6
0
        public void UpdateMonitor(MonitorDTO monitorDTO, UserAndOrganizationDTO userAndOrganizationDTO)
        {
            var monitor = _monitorsDbSet.FirstOrDefault(x => x.Id == monitorDTO.Id &&
                                                        x.OrganizationId == userAndOrganizationDTO.OrganizationId);

            if (monitor == null)
            {
                throw new ValidationException(ErrorCodes.ContentDoesNotExist, "Monitor does not exist");
            }

            var nameAlreadyExist = _monitorsDbSet.Any(x => x.Name == monitorDTO.Name &&
                                                      x.OrganizationId == userAndOrganizationDTO.OrganizationId);

            if (monitorDTO.Name != monitor.Name && nameAlreadyExist)
            {
                throw new ValidationException(ErrorCodes.DuplicatesIntolerable, "Monitor names should be unique");
            }

            monitor.Name       = monitorDTO.Name;
            monitor.Modified   = DateTime.UtcNow;
            monitor.ModifiedBy = userAndOrganizationDTO.UserId;
            _uow.SaveChanges(false);
        }