AddError() public method

public AddError ( IErrorInfo error ) : void
error IErrorInfo
return void
Exemplo n.º 1
0
        public void ResourceModel_ClearErrors_ClearsErrors()
        {
            //------------Setup for test--------------------------
            var instanceID = Guid.NewGuid();

            var err1 = new Mock<IErrorInfo>();
            err1.Setup(e => e.InstanceID).Returns(instanceID);
            var err2 = new Mock<IErrorInfo>();
            err2.Setup(e => e.InstanceID).Returns(Guid.NewGuid());
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);
            model.AddError(err1.Object);
            model.AddError(err2.Object);

            var errorInfos = model.Errors;

            //------------Assert Preconditions-------------------------
            Assert.AreEqual(2, errorInfos.Count);
            //------------Execute Test---------------------------
            model.ClearErrors();
            //-------------Assert Results------------------------
            errorInfos = model.Errors;
            Assert.AreEqual(0, errorInfos.Count);
        }
Exemplo n.º 2
0
        public void ResourceModel_RemoveError_ErrorIsNotFound_DoesNothing()
        {
            var instanceID = Guid.NewGuid();

            IErrorInfo err1 = new ErrorInfo
            {
                InstanceID = instanceID,
                ErrorType = ErrorType.Critical,
                FixType = FixType.ReloadMapping
            };

            IErrorInfo err2 = new ErrorInfo
            {
                InstanceID = instanceID,
                ErrorType = ErrorType.Warning,
                FixType = FixType.ReloadMapping
            };
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);
            model.AddError(err1);
            model.AddError(err2);

            //------------Execute Test---------------------------
            model.RemoveError(new ErrorInfo
            {
                InstanceID = instanceID,
                ErrorType = ErrorType.None,
                FixType = FixType.Delete
            });

            //------------Assert Results-------------------------
            var errors = model.GetErrors(instanceID);

            Assert.AreEqual(2, errors.Count);
            Assert.AreSame(err1, errors[0]);
            Assert.AreSame(err2, errors[1]);
        }
Exemplo n.º 3
0
        public void ResourceModel_GetErrors_ErrorsForInstance()
        {
            //------------Setup for test--------------------------
            var instanceID = Guid.NewGuid();

            var err1 = new Mock<IErrorInfo>();
            err1.Setup(e => e.InstanceID).Returns(instanceID);
            var err2 = new Mock<IErrorInfo>();
            err2.Setup(e => e.InstanceID).Returns(Guid.NewGuid());
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);
            model.AddError(err1.Object);
            model.AddError(err2.Object);

            //------------Execute Test---------------------------
            var errors = model.GetErrors(instanceID);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, errors.Count);
            Assert.AreEqual(instanceID, errors[0].InstanceID);
        }
Exemplo n.º 4
0
        public void ResourceModel_IDataErrorInfo_ThisAccessor_ResourceName()
        {
            //------------Setup for test--------------------------
            var instanceID = Guid.NewGuid();

            var err1 = new Mock<IErrorInfo>();
            err1.Setup(e => e.InstanceID).Returns(instanceID);
            var err2 = new Mock<IErrorInfo>();
            err2.Setup(e => e.InstanceID).Returns(Guid.NewGuid());
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);
            model.AddError(err1.Object);
            model.AddError(err2.Object);
            //------------Execute Test---------------------------
            var errMessage = model["ResourceName"];
            //-------------Assert Results------------------------
            Assert.IsNotNull(errMessage);
            Assert.AreEqual("Please enter a name for this resource", errMessage);
        }
Exemplo n.º 5
0
        public void ResourceModel_ClearErrors_FiresPropertyChangeForErrors()
        {
            //------------Setup for test--------------------------
            var instanceID = Guid.NewGuid();

            var err1 = new Mock<IErrorInfo>();
            err1.Setup(e => e.InstanceID).Returns(instanceID);
            var err2 = new Mock<IErrorInfo>();
            err2.Setup(e => e.InstanceID).Returns(Guid.NewGuid());
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);
            model.AddError(err1.Object);
            model.AddError(err2.Object);
            var _propertyChangedFired = false;
            model.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "Errors")
                {
                    _propertyChangedFired = true;
                }
            };
            //------------Execute Test---------------------------
            model.ClearErrors();
            //-------------Assert Results------------------------
            Assert.IsTrue(_propertyChangedFired);
        }