public void TestCopyPolicy_Nominal()
        {
            //set up environment
            IPolicy sourcePolicy = PolicyFactory.CreatePolicy("TestPolicy", m_sourcePolicySet, PolicyStatus.Active, "None");
            m_sourcePolicySet.Policies.Add(sourcePolicy);

            //set up test object
            CopyPolicyState state = new CopyPolicyState();
            state.PolicySet = m_destinationPolicySet;
            state.SourcePolicy = sourcePolicy;
            state.StateMachine = (IStateMachine)m_stateMachine.MockInstance;
            MDIChildForm childForm = (MDIChildForm)m_childForm.MockInstance;

            //pre-test asserts
            Assert.AreEqual(0, m_destinationPolicySet.Policies.Count, "Unexpected number of policies in policy set");

            //set up mocks
            object[] args = new object[0] { };
            m_stateMachine.ExpectAndReturn("get_ChildForm", childForm, args);
            m_childForm.Expect("set_IsModified", true);
            IState initState = new InitState();
            m_stateMachine.ExpectAndReturn("GetState", initState, StateTypeEnum.Init);
            m_stateMachine.Expect("SetState", initState);

            //test policy isn't yet there
            Assert.AreEqual(0, m_destinationPolicySet.Policies.Count, "Unexpected number of policies in policy set");

            //copy policy
            state.Enter();

            //test policy is added correctly
            Assert.AreEqual(1, m_destinationPolicySet.Policies.Count, "Unexpected number of conditions in conditionGroup.Conditions");
            IPolicy copiedPolicy = m_destinationPolicySet.Policies[0];
            Assert.AreNotEqual(copiedPolicy.Identifier, sourcePolicy.Identifier, "Identifier in copied policy matches source policy");
            Assert.AreNotEqual(copiedPolicy.Name.Identifier, sourcePolicy.Name.Identifier, "Name.Identifier in copied policy matches source policy");
            Assert.AreEqual(copiedPolicy.Name.Value, sourcePolicy.Name.Value, "Name.Value in copied policy doesn't match source policy");
            Assert.AreEqual(copiedPolicy.Status, sourcePolicy.Status, "Status in copied policy doesn't match source policy");
            Assert.AreEqual(copiedPolicy.Channels.Count, sourcePolicy.Channels.Count, "Channels.Count in copied policy doesn't match source policy");
            Assert.AreNotEqual(copiedPolicy.Channels[0].Identifier, sourcePolicy.Channels[0].Identifier, "Channels[0].Identifier in copied policy matches source policy");
            Assert.AreEqual(copiedPolicy.Conditions.Count, sourcePolicy.Conditions.Count, "Conditions.Count in copied policy doesn't match source policy");
            Assert.AreNotEqual(copiedPolicy.Conditions[0].Identifier, sourcePolicy.Conditions[0].Identifier, "Conditions[0].Identifier in copied policy matches source policy");
            //assume that all subsequent data in the policy has been copied correctly.

            m_stateMachine.Verify();
            m_childForm.Verify();
        }
        public void TestCopyPolicy_NullPolicySet()
        {
            //set up environment
            IPolicy sourcePolicy = PolicyFactory.CreatePolicy("TestPolicy", m_sourcePolicySet, PolicyStatus.Active, "None");
            m_sourcePolicySet.Policies.Add(sourcePolicy);

            //set up test object
            CopyPolicyState state = new CopyPolicyState();
            state.PolicySet = null;
            state.SourcePolicy = sourcePolicy;
            state.StateMachine = (IStateMachine)m_stateMachine.MockInstance;
            MDIChildForm childForm = (MDIChildForm)m_childForm.MockInstance;

            //pre-test asserts
            Assert.AreEqual(0, m_destinationPolicySet.Policies.Count, "Unexpected number of policies in policy set");

            //set up mocks
            object[] args = new object[0] { };
            m_childForm.ExpectNoCall("set_IsModified");
            m_stateMachine.ExpectNoCall("SetState");

            //copy policy
            try
            {
                state.Enter();
                Assert.Fail("Didn't throw");
            }
            catch (ArgumentNullException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.Fail("Threw unexpected exception");
            }

            m_stateMachine.Verify();
            m_childForm.Verify();
        }
        public void TestCopyPolicy_NullPolicy()
        {
            //set up test object
            CopyPolicyState state = new CopyPolicyState();
            state.PolicySet = m_destinationPolicySet;
            state.SourcePolicy = null;
            state.StateMachine = (IStateMachine)m_stateMachine.MockInstance;
            MDIChildForm childForm = (MDIChildForm)m_childForm.MockInstance;

            //pre-test asserts
            Assert.AreEqual(0, m_destinationPolicySet.Policies.Count, "Unexpected number of policies in policy set");

            //set up mocks
            object[] args = new object[0] { };
            m_childForm.ExpectNoCall("set_IsModified");
            m_stateMachine.ExpectNoCall("SetState");

            //test policy isn't yet there
            Assert.AreEqual(0, m_destinationPolicySet.Policies.Count, "Unexpected number of policies in policy set");

            //copy policy
            try
            {
                state.Enter();
                Assert.Fail("Didn't throw");
            }
            catch (ArgumentNullException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.Fail("Threw unexpected exception");
            }

            //test policy wasn't added
            Assert.AreEqual(0, m_destinationPolicySet.Policies.Count, "Unexpected number of conditions in conditionGroup.Conditions");

            m_stateMachine.Verify();
            m_childForm.Verify();
        }