// ReSharper disable InconsistentNaming
 public void DesignValidationMemoConstructor_UnitTest_Intialization_ErrorsNotNullAndIsValidTrue()
 // ReSharper restore InconsistentNaming
 {
     var memo = new DesignValidationMemo();
     Assert.IsNotNull(memo.Errors);
     Assert.IsTrue(memo.IsValid);
 }
        // ReSharper disable InconsistentNaming
        public void EventPublisherPublish_UnitTest_RegisteredType_FindsSubjectAndInvokesOnNext()
        // ReSharper restore InconsistentNaming
        {
            var memo = new DesignValidationMemo();

            var publisher = new EventPublisher();
            var subscription = publisher.GetEvent<DesignValidationMemo>().Subscribe(m => Assert.AreSame(memo, m));

            publisher.Publish(memo);
            subscription.Dispose();
        }
Ejemplo n.º 3
0
 // BUG 9634 - 2013.07.17 - TWR : added
 void ReceiveEnvironmentValidation(DesignValidationMemo memo)
 {
     foreach (var error in memo.Errors)
     {
         _errors.Add(error);
     }
     if (OnEnvironmentValidationReceived != null)
     {
         OnEnvironmentValidationReceived(this, memo);
     }
 }
Ejemplo n.º 4
0
 void ReceiveDesignValidation(DesignValidationMemo memo)
 {
     if (memo.Errors.Any(info => info.InstanceID != Guid.Empty))
     {
         IsValid = memo.IsValid && _errors.Count == 0;
         if (memo.Errors.Count > 0)
         {
             foreach (var error in Errors.Where(error => !memo.Errors.Contains(error)))
             {
                 _fixedErrors.Add(error);
             }
             if (_errors.Count > 0)
             {
                 _errors.Clear();
             }
             foreach (var error in memo.Errors)
             {
                 _errors.Add(error);
             }
         }
     }
     if (OnDesignValidationReceived != null)
     {
         OnDesignValidationReceived(this, memo);
     }
 }
        public void ServiceDesignerViewModel_DesignValidation_ServicePublishingNoErrors_UpdatesErrorsWithNoError()
        {
            var instanceID = Guid.NewGuid();
            var model = CreateServiceDesignerViewModel(instanceID);

            var memo = new DesignValidationMemo { InstanceID = instanceID };

            model.OnDesignValidationReceived += (s, m) =>
            {
                Assert.AreEqual(1, model.DesignValidationErrors.Count);
                Assert.AreSame(ServiceDesignerViewModel.NoError, model.DesignValidationErrors[0]);
            };

            model.ResourceModel.Environment.Connection.ServerEvents.Publish(memo);
        }
        public void ServiceDesignerViewModel_DesignValidation_ServicePublishingErrors_UpdatesErrors()
        {
            var instanceID = Guid.NewGuid();
            var model = CreateServiceDesignerViewModel(instanceID);

            var memo = new DesignValidationMemo { InstanceID = instanceID };
            memo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, Message = "Critical error.", InstanceID = instanceID });
            memo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Warning, Message = "Warning error.", InstanceID = instanceID });

            model.OnDesignValidationReceived += (s, m) =>
            {
                Assert.AreEqual(m.Errors.Count, model.DesignValidationErrors.Count);
                Assert.AreEqual(ErrorType.Critical, model.WorstError);

                foreach (var error in m.Errors)
                {
                    IErrorInfo currentError = error;
                    var modelError = model.DesignValidationErrors.FirstOrDefault(me => me.ErrorType == currentError.ErrorType && me.Message == currentError.Message);
                    Assert.AreSame(error, modelError);
                }
                Assert.AreEqual(m.Errors.Count, model.DesignValidationErrors.Count);
            };

            model.ResourceModel.Environment.Connection.ServerEvents.Publish(memo);
        }
        // ReSharper disable InconsistentNaming
        public void ServiceDesignerViewModel_DesignValidation_ForOtherActivity_NotReceived()
        // ReSharper restore InconsistentNaming
        {
            var instanceID = Guid.NewGuid();
            var instanceID2 = Guid.NewGuid();

            var hitCount = 0;
            var model = CreateServiceDesignerViewModel(instanceID);
            model.OnDesignValidationReceived += (s, m) =>
            {
                hitCount++;
            };

            var expected = model.LastValidationMemo;

            var memo = new DesignValidationMemo { InstanceID = instanceID2 };
            model.ResourceModel.Environment.Connection.ServerEvents.Publish(memo);

            Assert.AreEqual(0, hitCount, "Activity received memo for a different instance ID.");
            Assert.AreNotSame(memo, model.LastValidationMemo, "Activity updated LastValidationMemo with memo for a different instance ID.");
            Assert.AreSame(expected, model.LastValidationMemo, "Activity updated LastValidationMemo with memo for a different instance ID.");
        }
        // ReSharper disable InconsistentNaming
        public void ServiceDesignerViewModel_DesignValidation_ForThisActivity_Received()
        // ReSharper restore InconsistentNaming
        {
            var instanceID = Guid.NewGuid();

            var hitCount = 0;
            var model = CreateServiceDesignerViewModel(instanceID);
            model.OnDesignValidationReceived += (s, m) =>
            {
                hitCount++;
            };

            var memo = new DesignValidationMemo { InstanceID = instanceID };
            model.ResourceModel.Environment.Connection.ServerEvents.Publish(memo);

            Assert.AreEqual(1, hitCount, "Activity did not receive a memo matching it's instance ID.");
            Assert.AreSame(memo, model.LastValidationMemo, "Activity did not update LastValidationMemo with a memo matching it's instance ID.");
        }
Ejemplo n.º 9
0
        public void ResourceModel_Rollback_FixedErrorsRestored()
        {
            //Setup();
            var eventPublisher = new EventPublisher();
            var environmentModel = CreateMockEnvironment(eventPublisher);

            var instanceID = Guid.NewGuid();
            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID
            };

            var hitCount = 0;
            model.OnDesignValidationReceived += (sender, memo) =>
            {
                switch (hitCount++)
                {
                    case 0:
                        Assert.AreEqual(2, model.Errors.Count);
                        Assert.AreEqual(0, model.FixedErrors.Count);
                        break;

                    case 1:
                        Assert.AreEqual(1, model.Errors.Count);
                        Assert.AreEqual(1, model.FixedErrors.Count);

                        model.Rollback();

                        Assert.AreEqual(2, model.Errors.Count);
                        Assert.AreEqual(0, model.FixedErrors.Count);
                        break;
                }
            };

            // Publish 2 errors
            var pubMemo = new DesignValidationMemo { InstanceID = instanceID };
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, Message = "Critical error.", InstanceID = instanceID });
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Warning, Message = "Warning error.", InstanceID = instanceID });
            eventPublisher.Publish(pubMemo);

            // Fix 1 error and publish
            pubMemo.Errors.RemoveAt(1);
            eventPublisher.Publish(pubMemo);
        }
Ejemplo n.º 10
0
        public void ResourceModel_Environment_DesignValidationService_WiredUp()
        {
            var eventPublisher = new EventPublisher();

            var environmentID = Guid.NewGuid();
            var environment = new Mock<IEnvironmentModel>();
            environment.Setup(e => e.ID).Returns(environmentID);
            environment.Setup(e => e.Connection.ServerEvents).Returns(eventPublisher);

            var instanceID = Guid.NewGuid();
            var model = new ResourceModel(environment.Object, new Mock<IEventAggregator>().Object);

            var errors = model.GetErrors(instanceID);
            Assert.AreEqual(0, errors.Count);

            var err = new ErrorInfo
            {
                InstanceID = instanceID,
            };

            var memo = new DesignValidationMemo
            {
                InstanceID = environmentID,
                Errors = new List<IErrorInfo>
                {
                    err
                }
            };

            //------------Execute Test---------------------------
            eventPublisher.Publish(memo);

            //------------Assert Results-------------------------
            errors = model.GetErrors(instanceID);
            Assert.AreEqual(1, errors.Count);
            Assert.AreSame(err, errors[0]);
        }
Ejemplo n.º 11
0
        public void ResourceModel_DesignValidationServicePublishingMemo_UpdatesErrors()
        {
            //Setup();
            var instanceID = Guid.NewGuid();
            var pubMemo = new DesignValidationMemo { InstanceID = instanceID };
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, Message = "Critical error.", InstanceID = instanceID });
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Warning, Message = "Warning error.", InstanceID = instanceID });

            var eventPublisher = new EventPublisher();
            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(e => e.ServerEvents).Returns(eventPublisher);

            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID
            };

            model.OnDesignValidationReceived += (sender, memo) =>
            {
                Assert.AreEqual(memo.Errors.Count, model.Errors.Count, "OnDesignValidationReceived did not update the number of errors correctly.");

                foreach (var error in memo.Errors)
                {
                    var modelError = model.Errors.FirstOrDefault(me => me.ErrorType == error.ErrorType && me.Message == error.Message);
                    Assert.AreSame(error, modelError, "OnDesignValidationReceived did not set the error.");
                }
            };

            eventPublisher.Publish(pubMemo);
        }
Ejemplo n.º 12
0
        public void ResourceModel_DesignValidationServicePublishingMemo_NoInstanceID_DoesNotUpdatesErrors()
        {
            //Setup();
            var instanceID = Guid.NewGuid();
            var pubMemo = new DesignValidationMemo { InstanceID = instanceID };
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, Message = "Critical error." });
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Warning, Message = "Warning error." });

            var eventPublisher = new EventPublisher();
            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(e => e.ServerEvents).Returns(eventPublisher);

            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID
            };

            model.OnDesignValidationReceived += (sender, memo) => Assert.AreEqual(0, model.Errors.Count, "OnDesignValidationReceived did not update the number of errors correctly.");

            eventPublisher.Publish(pubMemo);
        }