Exemplo n.º 1
0
        public void CanParseReturnsExpectedResultWhenValueIsUnknown()
        {
            var value  = _fixture.Create <string>();
            var result = LifeCycleStageType.CanParse(value);

            Assert.False(result);
        }
Exemplo n.º 2
0
        public void CanParseReturnsExpectedResultWhenValueIsWellKnown()
        {
            var value  = _knownValues[new Random().Next(0, _knownValues.Length)];
            var result = LifeCycleStageType.CanParse(value);

            Assert.True(result);
        }
Exemplo n.º 3
0
        public void ToStringReturnsExpectedResult()
        {
            var value  = _knownValues[new Random().Next(0, _knownValues.Length)];
            var sut    = LifeCycleStageType.Parse(value);
            var result = sut.ToString();

            Assert.Equal(value, result);
        }
Exemplo n.º 4
0
        public void TryParseReturnsExpectedResultWhenValueIsUnknown()
        {
            var value  = _fixture.Create <string>();
            var result = LifeCycleStageType.TryParse(value, out var parsed);

            Assert.False(result);
            Assert.Null(parsed);
        }
Exemplo n.º 5
0
        public void TryParseReturnsExpectedResultWhenValueIsWellKnown()
        {
            var value  = _knownValues[new Random().Next(0, _knownValues.Length)];
            var result = LifeCycleStageType.TryParse(value, out var parsed);

            Assert.True(result);
            Assert.NotNull(parsed);
            Assert.Equal(value, parsed.ToString());
        }
 public AddStageToLifeCycle(
     PublicServiceId publicServiceId,
     LifeCycleStageType lifeCycleStageType,
     LifeCycleStagePeriod lifeCycleStagePeriod)
 {
     PublicServiceId      = publicServiceId;
     LifeCycleStageType   = lifeCycleStageType;
     LifeCycleStagePeriod = lifeCycleStagePeriod;
 }
 public StageWasAddedToLifeCycle(PublicServiceId publicServiceId,
     LifeCycleStageId lifeCycleStageId,
     LifeCycleStageType lifeCycleStageType,
     LifeCycleStagePeriod period)
 {
     PublicServiceId = publicServiceId;
     LifeCycleStageId = lifeCycleStageId;
     LifeCycleStageType = lifeCycleStageType;
     From = period.Start;
     To = period.End;
 }
Exemplo n.º 8
0
 public void WithValidData(
     PublicServiceId publicServiceId,
     PublicServiceName publicServiceName,
     LifeCycleStageType lifeCycleStageType,
     LifeCycleStagePeriod period)
 {
     Assert(new Scenario()
            .Given(publicServiceId,
                   new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered))
            .When(new AddStageToLifeCycle(publicServiceId, lifeCycleStageType, period))
            .Then(publicServiceId,
                  new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(1), lifeCycleStageType, period)));
 }
Exemplo n.º 9
0
 public void CannotSetOnRemovedPublicService(
     PublicServiceId publicServiceId,
     PublicServiceName publicServiceName,
     ReasonForRemoval reasonForRemoval,
     LifeCycleStageType lifeCycleStageType,
     LifeCycleStagePeriod period)
 {
     Assert(new Scenario()
            .Given(publicServiceId,
                   new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered),
                   new PublicServiceWasRemoved(publicServiceId, reasonForRemoval))
            .When(new AddStageToLifeCycle(publicServiceId, lifeCycleStageType, period))
            .Throws(new CannotPerformActionOnRemovedPublicService()));
 }
Exemplo n.º 10
0
        public void AddStage(LifeCycleStageType lifeCycleStageType, LifeCycleStagePeriod period)
        {
            if (_lifeCycleStagePeriods.Any(pair => pair.Value.OverlapsWith(period)))
            {
                throw new LifeCycleCannotHaveOverlappingPeriods();
            }

            Apply(
                new StageWasAddedToLifeCycle(
                    _publicServiceId,
                    _lastUsedId.Next(),
                    lifeCycleStageType,
                    period));
        }
Exemplo n.º 11
0
 public void WithValidData(
     PublicServiceId publicServiceId,
     PublicServiceName publicServiceName,
     LifeCycleStageType lifeCycleStageType,
     LifeCycleStagePeriod period,
     LifeCycleStageId lifeCycleStageLocalId)
 {
     Assert(new Scenario()
            .Given(publicServiceId,
                   new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered),
                   new StageWasAddedToLifeCycle(publicServiceId, lifeCycleStageLocalId, lifeCycleStageType, period))
            .When(new ChangePeriodOfLifeCycleStage(publicServiceId, lifeCycleStageLocalId, period))
            .Then(publicServiceId,
                  new PeriodOfLifeCycleStageWasChanged(publicServiceId, lifeCycleStageLocalId, period)));
 }
Exemplo n.º 12
0
        public void LifeCycleCannotHaveOverlappingPeriods(
            PublicServiceId publicServiceId,
            PublicServiceName publicServiceName,
            LifeCycleStageType lifeCycleStage1,
            LifeCycleStageType lifeCycleStage2)
        {
            var period1 = new LifeCycleStagePeriod(new ValidFrom(2018, LifeCycleStageId.FromNumber(1), 1), new ValidTo(2020, LifeCycleStageId.FromNumber(1), 1));
            var period2 = new LifeCycleStagePeriod(new ValidFrom(2019, LifeCycleStageId.FromNumber(1), 1), new ValidTo(2021, LifeCycleStageId.FromNumber(1), 1));

            Assert(new Scenario()
                   .Given(publicServiceId,
                          new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered),
                          new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(1), lifeCycleStage1, period1))
                   .When(new AddStageToLifeCycle(publicServiceId, lifeCycleStage2, period2))
                   .Throws(new LifeCycleCannotHaveOverlappingPeriods()));
        }
Exemplo n.º 13
0
        public void LifeCycleOverlapsTakesChangesIntoAccount(
            PublicServiceId publicServiceId,
            PublicServiceName publicServiceName,
            LifeCycleStageType lifeCycleStageType)
        {
            var period1 = new LifeCycleStagePeriod(new ValidFrom(2018, 1, 1), new ValidTo(2018, 1, 1));
            var period2 = new LifeCycleStagePeriod(new ValidFrom(2020, 1, 2), new ValidTo(2022, 1, 1));
            // Combining period2 with period3 will cause an overlap.
            var period3 = new LifeCycleStagePeriod(new ValidFrom(2019, 1, 1), new ValidTo(2021, 1, 1));

            Assert(new Scenario()
                   .Given(publicServiceId,
                          new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered),
                          new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(1), lifeCycleStageType, period1),
                          new PeriodOfLifeCycleStageWasChanged(publicServiceId, LifeCycleStageId.FromNumber(1), period2))
                   .When(new AddStageToLifeCycle(publicServiceId, lifeCycleStageType, period3))
                   .Throws(new LifeCycleCannotHaveOverlappingPeriods()));
        }
Exemplo n.º 14
0
        public void LifeCycleCannotHaveOverlappingPeriods(
            PublicServiceId publicServiceId,
            PublicServiceName publicServiceName,
            LifeCycleStageType lifeCycleStageType)
        {
            // These two periods are ok because they don't overlap
            var period1 = new LifeCycleStagePeriod(new ValidFrom(2018, 1, 1), new ValidTo(2020, 1, 1));
            var period2 = new LifeCycleStagePeriod(new ValidFrom(2020, 1, 2), new ValidTo(2021, 1, 1));
            // Combining period1 with period3 will cause an overlap, however.
            var period3 = new LifeCycleStagePeriod(new ValidFrom(2018, 1, 1), new ValidTo(2020, 1, 1));

            Assert(new Scenario()
                   .Given(publicServiceId,
                          new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered),
                          new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(1), lifeCycleStageType, period1),
                          new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(2), lifeCycleStageType, period2))
                   .When(new ChangePeriodOfLifeCycleStage(publicServiceId, LifeCycleStageId.FromNumber(2), period3))
                   .Throws(new LifeCycleCannotHaveOverlappingPeriods()));
        }
Exemplo n.º 15
0
        public void LifeCycleStageDoesNotOverlapWhenChangingItsOwnPeriod(
            PublicServiceId publicServiceId,
            PublicServiceName publicServiceName,
            LifeCycleStageType lifeCycleStageType)
        {
            // These two periods are ok because they don't overlap
            var period1 = new LifeCycleStagePeriod(new ValidFrom(2018, 1, 1), new ValidTo(2020, 1, 1));
            var period2 = new LifeCycleStagePeriod(new ValidFrom(2020, 1, 2), new ValidTo(2021, 1, 1));
            // Changing period1 to period3 for '1' will not cause an overlap
            var period3 = new LifeCycleStagePeriod(new ValidFrom(2018, 1, 1), new ValidTo(2019, 1, 1));

            Assert(new Scenario()
                   .Given(publicServiceId,
                          new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered),
                          new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(1), lifeCycleStageType, period1),
                          new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(2), lifeCycleStageType, period2))
                   .When(new ChangePeriodOfLifeCycleStage(publicServiceId, LifeCycleStageId.FromNumber(1), period3))
                   .Then(publicServiceId,
                         new PeriodOfLifeCycleStageWasChanged(publicServiceId, LifeCycleStageId.FromNumber(1), period3)));
        }
Exemplo n.º 16
0
        public void ParseReturnsExpectedResultWhenValueIsWellKnown()
        {
            var value = _knownValues[new Random().Next(0, _knownValues.Length)];

            Assert.NotNull(LifeCycleStageType.Parse(value));
        }
Exemplo n.º 17
0
 public void ParseValueCanNotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() => LifeCycleStageType.Parse(null));
 }
Exemplo n.º 18
0
        public void ParseReturnsExpectedResultWhenValueIsUnknown()
        {
            var value = _fixture.Create <string>();

            Assert.Throws <FormatException>(() => LifeCycleStageType.Parse(value));
        }
        public void AddStageToLifeCycle(LifeCycleStageType lifeCycleStageType, LifeCycleStagePeriod period)
        {
            EnsureNotRemoved();

            _lifeCycle.AddStage(lifeCycleStageType, period);
        }