Пример #1
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);
     }
 }
Пример #2
0
        public void ObservableReadOnlyList_IReadOnlyCollection_Implemented()
        {
            //------------Setup for test--------------------------
            var observableReadOnlyList = new ObservableReadOnlyList <string>();

            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            Assert.IsInstanceOfType(observableReadOnlyList, typeof(IReadOnlyCollection <string>));
            Assert.IsTrue(observableReadOnlyList.IsReadOnly);

            observableReadOnlyList.Add("Item1");
            observableReadOnlyList.Add("Item2");
            observableReadOnlyList.Add("Item3");

            Assert.AreEqual(3, observableReadOnlyList.Count);
            Assert.AreEqual("Item1", observableReadOnlyList[0]);
            Assert.AreEqual("Item2", observableReadOnlyList[1]);
            Assert.AreEqual("Item3", observableReadOnlyList[2]);

            var contains    = observableReadOnlyList.Contains("Item3");
            var notContains = observableReadOnlyList.Contains("Item4");

            Assert.IsTrue(contains);
            Assert.IsFalse(notContains);

            observableReadOnlyList.Remove("Item2");
            Assert.AreEqual(2, observableReadOnlyList.Count);
            Assert.AreEqual("Item1", observableReadOnlyList[0]);
            Assert.AreEqual("Item3", observableReadOnlyList[1]);

            var array = new string[3];

            observableReadOnlyList.CopyTo(array, 1);

            Assert.IsNull(array[0]);
            Assert.AreEqual("Item1", array[1]);
            Assert.AreEqual("Item3", array[2]);
        }
        public void ObservableReadOnlyList_IReadOnlyCollection_Implemented()
        {
            //------------Setup for test--------------------------
            var observableReadOnlyList = new ObservableReadOnlyList<string>();

            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            Assert.IsInstanceOfType(observableReadOnlyList, typeof(IReadOnlyCollection<string>));
            Assert.IsTrue(observableReadOnlyList.IsReadOnly);

            observableReadOnlyList.Add("Item1");
            observableReadOnlyList.Add("Item2");
            observableReadOnlyList.Add("Item3");

            Assert.AreEqual(3, observableReadOnlyList.Count);
            Assert.AreEqual("Item1", observableReadOnlyList[0]);
            Assert.AreEqual("Item2", observableReadOnlyList[1]);
            Assert.AreEqual("Item3", observableReadOnlyList[2]);

            var contains = observableReadOnlyList.Contains("Item3");
            var notContains = observableReadOnlyList.Contains("Item4");
            Assert.IsTrue(contains);
            Assert.IsFalse(notContains);

            observableReadOnlyList.Remove("Item2");
            Assert.AreEqual(2, observableReadOnlyList.Count);
            Assert.AreEqual("Item1", observableReadOnlyList[0]);
            Assert.AreEqual("Item3", observableReadOnlyList[1]);

            var array = new string[3];
            observableReadOnlyList.CopyTo(array, 1);

            Assert.IsNull(array[0]);
            Assert.AreEqual("Item1", array[1]);
            Assert.AreEqual("Item3", array[2]);
        }
Пример #4
0
        public void ObservableReadOnlyList_INotifyCollectionChanged_Implemented()
        {
            //------------Setup for test--------------------------
            var observableReadOnlyList = new ObservableReadOnlyList <string>(new List <string> {
                "Item1", "Item2", "Item3"
            });

            var collectionChanged = false;

            observableReadOnlyList.CollectionChanged += (sender, args) => collectionChanged = true;

            //------------Execute Test---------------------------
            observableReadOnlyList.Add("item4");

            //------------Assert Results-------------------------
            Assert.IsInstanceOfType(observableReadOnlyList, typeof(INotifyCollectionChanged));
            Assert.IsTrue(collectionChanged);
        }
Пример #5
0
        public static Mock <IContextualResourceModel> CreateResourceModel(Guid resourceID, out Mock <IResourceRepository> resourceRepository, params IErrorInfo[] resourceErrors)
        {
            var connection = new Mock <IEnvironmentConnection>();

            connection.Setup(conn => conn.ServerEvents).Returns(new EventPublisher());

            var environmentID = Guid.NewGuid();
            var environment   = new Mock <IEnvironmentModel>();

            environment.Setup(e => e.Connection).Returns(connection.Object);
            environment.Setup(e => e.ID).Returns(environmentID);
            environment.Setup(e => e.IsConnected).Returns(true);

            var errors = new ObservableReadOnlyList <IErrorInfo>();

            if (resourceErrors != null)
            {
                foreach (var resourceError in resourceErrors)
                {
                    errors.Add(resourceError);
                }
            }

            var model = new Mock <IContextualResourceModel>();

            model.Setup(r => r.ResourceName).Returns("TestResource");
            model.Setup(r => r.ServerID).Returns(Guid.NewGuid());
            model.Setup(r => r.WorkflowXaml).Returns(new StringBuilder("<root/>"));
            model.Setup(m => m.Errors).Returns(errors);
            model.Setup(m => m.ID).Returns(resourceID);
            model.Setup(m => m.Environment).Returns(environment.Object);
            model.Setup(m => m.GetErrors(It.IsAny <Guid>())).Returns(errors);
            model.Setup(m => m.RemoveError(It.IsAny <IErrorInfo>())).Callback((IErrorInfo error) => errors.Remove(error));

            resourceRepository = new Mock <IResourceRepository>();

            environment.Setup(e => e.ResourceRepository).Returns(resourceRepository.Object);
            return(model);
        }
        static Mock<IContextualResourceModel> CreateResourceModel(Guid resourceID, out Mock<IResourceRepository> resourceRepository, params IErrorInfo[] resourceErrors)
        {
            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(conn => conn.ServerEvents).Returns(new EventPublisher());

            var environmentID = Guid.NewGuid();
            var environment = new Mock<IEnvironmentModel>();
            environment.Setup(e => e.Connection).Returns(connection.Object);
            environment.Setup(e => e.ID).Returns(environmentID);
            environment.Setup(e => e.IsConnected).Returns(true);
            environment.Setup(e => e.HasLoadedResources).Returns(true);
            environment.Setup(e => e.IsLocalHost).Returns(true);
            environment.Setup(e => e.IsLocalHostCheck()).Returns(true);
            var errors = new ObservableReadOnlyList<IErrorInfo>();
            if (resourceErrors != null)
            {
                foreach (var resourceError in resourceErrors)
                {
                    errors.Add(resourceError);
                }
            }

            var model = new Mock<IContextualResourceModel>();
            model.Setup(r => r.ResourceName).Returns("TestResource");
            model.Setup(r => r.ServerID).Returns(Guid.NewGuid());
            model.Setup(r => r.WorkflowXaml).Returns(new StringBuilder("<root/>"));
            model.Setup(m => m.Errors).Returns(errors);
            model.Setup(m => m.ID).Returns(resourceID);
            var environmentModel = environment.Object;
            model.Setup(m => m.Environment).Returns(environmentModel);
            model.Setup(m => m.GetErrors(It.IsAny<Guid>())).Returns(errors);
            model.Setup(m => m.HasErrors).Returns(() => model.Object.Errors.Count > 0);
            model.SetupProperty(m => m.IsValid);
            model.Setup(m => m.RemoveError(It.IsAny<IErrorInfo>())).Callback((IErrorInfo error) => errors.Remove(error));

            resourceRepository = new Mock<IResourceRepository>();
            var mockEnvironmentRepository = new Mock<IEnvironmentRepository>();
            mockEnvironmentRepository.Setup(e => e.LookupEnvironments(It.IsAny<IEnvironmentModel>(), null)).Returns(new List<IEnvironmentModel> { environmentModel });
            // ReSharper disable ObjectCreationAsStatement
            new EnvironmentRepository(mockEnvironmentRepository.Object);
            // ReSharper restore ObjectCreationAsStatement
            environment.Setup(e => e.ResourceRepository).Returns(resourceRepository.Object);
            return model;
        }
Пример #7
0
        public static Mock<IContextualResourceModel> CreateResourceModel(Guid resourceID, out Mock<IResourceRepository> resourceRepository, params IErrorInfo[] resourceErrors)
        {
            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(conn => conn.ServerEvents).Returns(new EventPublisher());

            var environmentID = Guid.NewGuid();
            var environment = new Mock<IEnvironmentModel>();
            environment.Setup(e => e.Connection).Returns(connection.Object);
            environment.Setup(e => e.ID).Returns(environmentID);
            environment.Setup(e => e.IsConnected).Returns(true);

            var errors = new ObservableReadOnlyList<IErrorInfo>();
            if (resourceErrors != null)
            {
                foreach (var resourceError in resourceErrors)
                {
                    errors.Add(resourceError);
                }
            }

            var model = new Mock<IContextualResourceModel>();
            model.Setup(r => r.ResourceName).Returns("TestResource");
            model.Setup(r => r.ServerID).Returns(Guid.NewGuid());
            model.Setup(r => r.WorkflowXaml).Returns(new StringBuilder("<root/>"));
            model.Setup(m => m.Errors).Returns(errors);
            model.Setup(m => m.ID).Returns(resourceID);
            model.Setup(m => m.Environment).Returns(environment.Object);
            model.Setup(m => m.GetErrors(It.IsAny<Guid>())).Returns(errors);
            model.Setup(m => m.RemoveError(It.IsAny<IErrorInfo>())).Callback((IErrorInfo error) => errors.Remove(error));

            resourceRepository = new Mock<IResourceRepository>();

            environment.Setup(e => e.ResourceRepository).Returns(resourceRepository.Object);
            return model;
        }
        public void ObservableReadOnlyList_INotifyCollectionChanged_Implemented()
        {
            //------------Setup for test--------------------------
            var observableReadOnlyList = new ObservableReadOnlyList<string>(new List<string> { "Item1", "Item2", "Item3" });

            var collectionChanged = false;
            observableReadOnlyList.CollectionChanged += (sender, args) => collectionChanged = true;

            //------------Execute Test---------------------------
            observableReadOnlyList.Add("item4");

            //------------Assert Results-------------------------
            Assert.IsInstanceOfType(observableReadOnlyList, typeof(INotifyCollectionChanged));
            Assert.IsTrue(collectionChanged);
        }