public void SecurityCodeBusinessLogic_CreateSecurityCode_Only_Applies_To_Active_Or_Pending(
            OrganisationStatuses organisationStatus,
            bool expectedToFail)
        {
            // Arrange
            var securityCodeBusinessLogic = new SecurityCodeBusinessLogic();
            var organisation = new Organisation {
                Status = organisationStatus
            };
            var securityCodeExpiryDateTime = VirtualDateTime.Now.AddDays(7);

            // Act
            var creationResult =
                securityCodeBusinessLogic.CreateSecurityCode(organisation, securityCodeExpiryDateTime);

            // Assert
            var wasWasnt = expectedToFail ? "was" : "was not";
            var didDidnt = expectedToFail ? "didn't" : "did";

            Assert.AreEqual(
                expectedToFail,
                creationResult.Failed,
                $"Organisation status '{organisationStatus.ToString()}' {wasWasnt} expected to fail, but it {didDidnt}.");

            if (expectedToFail)
            {
                Assert.AreEqual(
                    $"Generation of security codes cannot be performed for retired organisations. Organisation '' employerReference '' has status '{organisationStatus.ToString()}'.",
                    creationResult.ErrorMessage.Description);
            }
        }
        public void SecurityCodeBusinessLogic_CreateSecurityCode_Succeeds()
        {
            // Arrange
            var securityCodeBusinessLogic = new SecurityCodeBusinessLogic();
            var organisation = new Organisation {
                Status = OrganisationStatuses.Active
            };
            var securityCodeExpiryDateTime = VirtualDateTime.Now.AddDays(1);

            // Act
            var creationResult =
                securityCodeBusinessLogic.CreateSecurityCode(organisation, securityCodeExpiryDateTime);

            Assert.True(creationResult.Succeeded);

            var modifiedOrganisation = creationResult.Result;

            // Assert
            Assert.NotNull(modifiedOrganisation.SecurityCode);
            Assert.AreEqual(securityCodeExpiryDateTime, modifiedOrganisation.SecurityCodeExpiryDateTime);
            Assert.NotNull(modifiedOrganisation.SecurityCodeCreatedDateTime);
        }
        public void SecurityCodeBusinessLogic_CreateSecurityCode_Must_Expire_In_The_Future()
        {
            // Arrange
            var securityCodeBusinessLogic = new SecurityCodeBusinessLogic();
            var organisation = new Organisation {
                Status = OrganisationStatuses.Active
            };
            var securityCodeExpiryDateTime = VirtualDateTime.Now.AddDays(-1);

            // Act
            var creationResult =
                securityCodeBusinessLogic.CreateSecurityCode(organisation, securityCodeExpiryDateTime);

            Assert.True(creationResult.Failed);
            Assert.Null(creationResult.Result);

            var actualError = creationResult.ErrorMessage;

            // Assert
            Assert.NotNull(actualError);
            Assert.AreEqual(4004, actualError.Code);
            Assert.AreEqual("Security code must expire in the future", actualError.Description);
        }