public void GivenInvalidIdentifierException_WhenGetMessage_ShouldReturnExpected()
        {
            var name      = "tagname";
            var value     = "tagvalue";
            var exception = new InvalidIdentifierException(name, value);

            Assert.Equal($"Dicom element '{name}' with value '{value}' failed validation for VR 'UI': DICOM Identifier is invalid. Value length should not exceed the maximum length of 64 characters. Value should contain characters in '0'-'9' and '.'. Each component must start with non-zero number.", exception.Message);
        }
Exemple #2
0
        public void Add(User user)
        {
            if (ReferenceEquals(user, null))
            {
                var ex = new ArgumentNullException($"{nameof(user)} is null");
                this.logger?.Error(ex, ex.Message);
                throw ex;
            }

            if (ReferenceEquals(user.FirstName, null) || ReferenceEquals(user.LastName, null))
            {
                var ex = new InvalidUserException($"{nameof(user)} isn't fully initialized");
                this.logger?.Error(ex, ex.Message);
                throw ex;
            }

            if (this.storage.Contains(user))
            {
                var ex = new UserAlreadyExistException($"{nameof(user)} already exists");
                this.logger?.Error(ex, ex.Message);
                throw ex;
            }

            rwLockSlim.EnterWriteLock();
            try
            {
                user.Identifier = this.generateIdentifierFunction();

                if (user.Identifier < 0)
                {
                    var ex = new InvalidIdentifierException($"{nameof(user.Identifier)} can't be under zero");
                    this.logger?.Error(ex, ex.Message);
                    throw ex;
                }

                if (storage.Select(usr => usr.Identifier).Contains(user.Identifier))
                {
                    var ex = new InvalidIdentifierException($"{nameof(user.Identifier)} '{user.Identifier}' already has been taken");
                    this.logger?.Error(ex, ex.Message);
                    throw ex;
                }

                this.logger?.Info($"Added {nameof(user)} with fields:\n ID:{user.Identifier}\n FirstName:{user.FirstName}\n LastName:{user.LastName}\n Age:{user.Age}");

                this.storage.Add(user);
            }
            finally
            {
                rwLockSlim.ExitWriteLock();
            }

            Notify(new Message {
                Action = Action.Add, User = user.Clone()
            });
        }