public void PerfcounterViewModel_UpdatePerfCounter_ResourceCounterSetDeleted_ShouldNotSaveCounter()
        {
            //------------Setup for test--------------------------
            var performanceCounterTo = new PerformanceCounterTo();

            performanceCounterTo.NativeCounters.Add(new TestCounter(WarewolfPerfCounterType.AverageExecutionTime));
            performanceCounterTo.NativeCounters.Add(new TestCounter(WarewolfPerfCounterType.ConcurrentRequests));
            var resourceId = Guid.NewGuid();

            performanceCounterTo.ResourceCounters.Add(new TestResourceCounter(WarewolfPerfCounterType.AverageExecutionTime, resourceId));
            performanceCounterTo.ResourceCounters.Add(new TestResourceCounter(WarewolfPerfCounterType.RequestsPerSecond, resourceId));
            var perfcounterViewModel = new PerfcounterViewModel(performanceCounterTo, new Mock <IServer>().Object, () => new Mock <IResourcePickerDialog>().Object);

            //------------Assert Preconditions-------------------
            Assert.IsNotNull(perfcounterViewModel.ServerCounters);
            Assert.IsNotNull(perfcounterViewModel.ResourceCounters);
            Assert.AreEqual(1, perfcounterViewModel.ServerCounters.Count);
            Assert.AreEqual(2, perfcounterViewModel.ResourceCounters.Count);
            var serverCounter      = perfcounterViewModel.ServerCounters[0];
            var resourceCounter    = perfcounterViewModel.ResourceCounters[0];
            var newResourceCounter = perfcounterViewModel.ResourceCounters[1];

            Assert.IsTrue(newResourceCounter.IsNew);
            Assert.IsNotNull(serverCounter);
            Assert.IsNotNull(resourceCounter);
            Assert.IsFalse(resourceCounter.IsDeleted);
            //------------Execute Test---------------------------
            resourceCounter.RemoveRow.Execute(null);
            //------------Assert Results-------------------------
            Assert.IsTrue(resourceCounter.IsDeleted);
            perfcounterViewModel.Save(performanceCounterTo);
            Assert.AreEqual(1, perfcounterViewModel.ResourceCounters.Count);
        }
        public void PerfcounterViewModel_Save_ShouldUpdatePerfCounterTo()
        {
            //------------Setup for test--------------------------
            var performanceCounterTo = new PerformanceCounterTo();

            performanceCounterTo.NativeCounters.Add(new TestCounter(WarewolfPerfCounterType.AverageExecutionTime, false));
            performanceCounterTo.NativeCounters.Add(new TestCounter(WarewolfPerfCounterType.ConcurrentRequests, false));
            performanceCounterTo.NativeCounters.Add(new TestCounter(WarewolfPerfCounterType.ExecutionErrors, false));
            performanceCounterTo.NativeCounters.Add(new TestCounter(WarewolfPerfCounterType.NotAuthorisedErrors, false));
            performanceCounterTo.NativeCounters.Add(new TestCounter(WarewolfPerfCounterType.RequestsPerSecond, false));
            performanceCounterTo.NativeCounters.Add(new TestCounter(WarewolfPerfCounterType.ServicesNotFound, false));
            var resourceId = Guid.NewGuid();

            performanceCounterTo.ResourceCounters.Add(new TestResourceCounter(WarewolfPerfCounterType.AverageExecutionTime, resourceId));
            performanceCounterTo.ResourceCounters.Add(new TestResourceCounter(WarewolfPerfCounterType.RequestsPerSecond, resourceId));
            var perfcounterViewModel = new PerfcounterViewModel(performanceCounterTo, new Mock <IServer>().Object, () => new Mock <IResourcePickerDialog>().Object);
            //------------Assert Preconditions-------------------
            var serverCounter      = perfcounterViewModel.ServerCounters[0];
            var newResourceCounter = perfcounterViewModel.ResourceCounters[1];

            Assert.IsTrue(newResourceCounter.IsNew);
            Assert.IsNotNull(serverCounter);
            serverCounter.TotalErrors          = true;
            serverCounter.AverageExecutionTime = true;
            serverCounter.ConcurrentRequests   = true;
            serverCounter.NotAuthorisedErrors  = true;
            serverCounter.RequestPerSecond     = true;
            serverCounter.WorkFlowsNotFound    = true;
            newResourceCounter.CounterName     = "new resource";
            var newResourceId = Guid.NewGuid();

            newResourceCounter.ResourceId           = newResourceId;
            newResourceCounter.RequestPerSecond     = true;
            newResourceCounter.TotalErrors          = true;
            newResourceCounter.AverageExecutionTime = true;
            newResourceCounter.ConcurrentRequests   = true;
            //------------Execute Test---------------------------
            perfcounterViewModel.Save(performanceCounterTo);
            //------------Assert Results-------------------------
            Assert.AreEqual(6, performanceCounterTo.NativeCounters.Count);
            Assert.IsTrue(performanceCounterTo.NativeCounters[0].IsActive);
            Assert.IsTrue(performanceCounterTo.NativeCounters[1].IsActive);
            Assert.IsTrue(performanceCounterTo.NativeCounters[2].IsActive);
            Assert.IsTrue(performanceCounterTo.NativeCounters[3].IsActive);
            Assert.IsTrue(performanceCounterTo.NativeCounters[4].IsActive);
            Assert.IsTrue(performanceCounterTo.NativeCounters[5].IsActive);
            Assert.AreEqual(6, performanceCounterTo.ResourceCounters.Count);
            Assert.IsTrue(performanceCounterTo.ResourceCounters.Any(counter => counter.PerfCounterType == WarewolfPerfCounterType.AverageExecutionTime));
            Assert.IsTrue(performanceCounterTo.ResourceCounters.Any(counter => counter.PerfCounterType == WarewolfPerfCounterType.RequestsPerSecond));
            Assert.IsTrue(performanceCounterTo.ResourceCounters.Any(counter => counter.PerfCounterType == WarewolfPerfCounterType.ConcurrentRequests));
            Assert.IsTrue(performanceCounterTo.ResourceCounters.Any(counter => counter.PerfCounterType == WarewolfPerfCounterType.ExecutionErrors));
            Assert.AreEqual("new resource", performanceCounterTo.ResourceCounters[2].CategoryInstanceName);
            Assert.AreEqual(newResourceId, performanceCounterTo.ResourceCounters[2].ResourceId);
            Assert.AreEqual("new resource", performanceCounterTo.ResourceCounters[3].CategoryInstanceName);
            Assert.AreEqual(newResourceId, performanceCounterTo.ResourceCounters[3].ResourceId);
            Assert.AreEqual("new resource", performanceCounterTo.ResourceCounters[4].CategoryInstanceName);
            Assert.AreEqual(newResourceId, performanceCounterTo.ResourceCounters[4].ResourceId);
            Assert.AreEqual("new resource", performanceCounterTo.ResourceCounters[5].CategoryInstanceName);
            Assert.AreEqual(newResourceId, performanceCounterTo.ResourceCounters[5].ResourceId);
        }