Beispiel #1
0
        public void RecordCheckBoxValueForField_ShouldThrowException_ForInfoField()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            Assert.ThrowsException <Exception>(() => dut.RecordCheckBoxValueForField(_infoField, true));
            Assert.AreEqual(0, dut.FieldValues.Count);
        }
        private void GetPreservationDetailsFromField(
            StringBuilder preservationDetails, Field field,
            PreservationPeriod preservationPeriod)
        {
            if (!field.FieldType.NeedsUserInput())
            {
                return;
            }

            preservationDetails.Append($"{field.Label}=");

            var currentValue = preservationPeriod.GetFieldValue(field.Id);
            var value        = string.Empty;

            switch (field.FieldType)
            {
            case FieldType.Number:
                value = GetNumberValueAsString(currentValue);
                break;

            case FieldType.CheckBox:
                value = GetCheckBoxValueAsString(currentValue);
                break;

            case FieldType.Attachment:
                value = GetAttachmentValueAsString(currentValue);
                break;
            }
            preservationDetails.Append($"{value}. ");
        }
Beispiel #3
0
        public void SetComment_ShouldSetComment()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            dut.SetComment("Comment");

            Assert.AreEqual("Comment", dut.Comment);
        }
Beispiel #4
0
        public void RecordCheckBoxValueForField_ShouldAddFieldValueToFieldValuesList_ForCheckBoxField()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            dut.RecordCheckBoxValueForField(_checkBoxField, true);

            Assert.AreEqual(1, dut.FieldValues.Count);
        }
Beispiel #5
0
        public void Constructor_ShouldSetProperties()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            Assert.AreEqual(TestPlant, dut.Plant);
            Assert.AreEqual(_timeProvider.UtcNow, dut.DueTimeUtc);
            Assert.AreEqual(PreservationPeriodStatus.ReadyToBePreserved, dut.Status);
            Assert.IsNull(dut.PreservationRecord);
        }
Beispiel #6
0
        public void RecordCheckBoxValueForField_ShouldThrowException_AfterPreserved()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            dut.Preserve(_preservedByMock.Object, true);

            Assert.ThrowsException <Exception>(() => dut.RecordCheckBoxValueForField(_checkBoxField, true));
            Assert.AreEqual(0, dut.FieldValues.Count);
        }
Beispiel #7
0
        public void Preserve_ShouldThrowException_WhenNeedsUserInput()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.NeedsUserInput);

            Assert.AreEqual(PreservationPeriodStatus.NeedsUserInput, dut.Status);

            // act
            Assert.ThrowsException <Exception>(() => dut.Preserve(_preservedByMock.Object, true));
        }
Beispiel #8
0
        public void Preserve_ShouldThrowException_WhenPreserveTwice()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            Assert.IsNull(dut.PreservationRecord);
            dut.Preserve(_preservedByMock.Object, true);

            // act
            Assert.ThrowsException <Exception>(() => dut.Preserve(_preservedByMock.Object, true));
        }
Beispiel #9
0
        public void SetComment_ShouldThrowException_AfterPreserved()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            dut.SetComment("Comment");
            Assert.AreEqual("Comment", dut.Comment);

            dut.Preserve(_preservedByMock.Object, true);

            Assert.ThrowsException <Exception>(() => dut.SetComment("X"));
            Assert.AreEqual("Comment", dut.Comment);
        }
Beispiel #10
0
        public void Reschedule_Later_ShouldUpdateDueTimeToLater()
        {
            // Arrange
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            Assert.AreEqual(_dueUtc, dut.DueTimeUtc);
            var expectedNextDueTimeUtc = dut.DueTimeUtc.AddWeeks(4);

            // Act
            dut.Reschedule(4, RescheduledDirection.Later);

            Assert.AreEqual(expectedNextDueTimeUtc, dut.DueTimeUtc);
        }
Beispiel #11
0
        public void SetNewDueTimeUtc_ShouldUpdateDueTime()
        {
            // Arrange
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            Assert.AreEqual(_dueUtc, dut.DueTimeUtc);

            // Act
            dut.SetNewDueTimeUtc(2);

            var expectedNextDueTimeUtc = _timeProvider.UtcNow.AddWeeks(2);

            Assert.AreEqual(expectedNextDueTimeUtc, dut.DueTimeUtc);
        }
Beispiel #12
0
        public void GetFieldValue_ShouldGetANumberValue_AfterRecordingNumber()
        {
            var dut   = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);
            var fMock = new Mock <Field>("", "", FieldType.Number, 0, "mm", true);

            fMock.SetupGet(f => f.Id).Returns(12);
            fMock.SetupGet(f => f.Plant).Returns(TestPlant);
            var field = fMock.Object;

            dut.RecordNumberValueForField(field, 1);

            var fieldValue = dut.GetFieldValue(12);

            Assert.IsNotNull(fieldValue);
            Assert.IsInstanceOfType(fieldValue, typeof(NumberValue));
        }
Beispiel #13
0
        public void GetFieldValue_ShouldGetACheckBoxCheckedValue_AfterRecordingCheckBoxValue()
        {
            var dut   = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);
            var fMock = new Mock <Field>(TestPlant, "", FieldType.CheckBox, 0, null, null);

            fMock.SetupGet(f => f.Id).Returns(12);
            fMock.SetupGet(f => f.Plant).Returns(TestPlant);
            var field = fMock.Object;

            dut.RecordCheckBoxValueForField(field, true);

            var fieldValue = dut.GetFieldValue(12);

            Assert.IsNotNull(fieldValue);
            Assert.IsInstanceOfType(fieldValue, typeof(CheckBoxChecked));
        }
Beispiel #14
0
        public void Preserve_ShouldPreserve_WhenReadyToBePreserved()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            Assert.AreEqual(PreservationPeriodStatus.ReadyToBePreserved, dut.Status);
            Assert.IsNull(dut.PreservationRecord);

            // act
            _timeProvider.Elapse(TimeSpan.FromDays(12));
            dut.Preserve(_preservedByMock.Object, true);

            // assert
            var record = dut.PreservationRecord;

            Assert.IsNotNull(record);
            Assert.AreEqual(PreservationPeriodStatus.Preserved, dut.Status);
            Assert.AreEqual(PreservedById, record.PreservedById);
            Assert.AreEqual(_timeProvider.UtcNow, record.PreservedAtUtc);
            Assert.IsTrue(record.BulkPreserved);
        }
Beispiel #15
0
        public void Constructor_ShouldAllowStatusNeedsUserInput()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.NeedsUserInput);

            Assert.AreEqual(PreservationPeriodStatus.NeedsUserInput, dut.Status);
        }
Beispiel #16
0
        public void RecordAttachmentValueForField_ShouldThrowException_ForInfoField()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            Assert.ThrowsException <Exception>(() => dut.RecordAttachmentValueForField(_infoField, null));
        }
Beispiel #17
0
        public void GetFieldValue_ShouldReturnNull_ForUnknownField()
        {
            var dut = new PreservationPeriod(TestPlant, _dueUtc, PreservationPeriodStatus.ReadyToBePreserved);

            Assert.IsNull(dut.GetFieldValue(12));
        }
        public void Setup()
        {
            var responsible = new Responsible(TestPlant, "C", "D");

            var supplierMode = new Mode(TestPlant, "SUP", true);

            supplierMode.SetProtectedIdForTesting(SupplierModeId);
            _supplierStep = new Step(TestPlant, "SUP", supplierMode, responsible);
            _supplierStep.SetProtectedIdForTesting(SupplierStepId);

            var otherMode = new Mode(TestPlant, "OTHER", false);

            otherMode.SetProtectedIdForTesting(OtherModeId);
            _otherStep = new Step(TestPlant, "OTHER", otherMode, responsible);
            _otherStep.SetProtectedIdForTesting(OtherStepId);

            var rdForSupplier = new RequirementDefinition(TestPlant, "ForSupp", Interval, RequirementUsage.ForSuppliersOnly, 1);
            var rdForOther    = new RequirementDefinition(TestPlant, "ForOther", Interval, RequirementUsage.ForOtherThanSuppliers, 2);

            _requirementForSupplier = new TagRequirement(TestPlant, Interval, rdForSupplier);
            _requirementForSupplier.SetProtectedIdForTesting(RequirementForSupplierId);

            _requirementForOther = new TagRequirement(TestPlant, Interval, rdForOther);
            _requirementForOther.SetProtectedIdForTesting(RequirementForOtherId);

            _tagInSupplierStep = new Tag(TestPlant, TagType.Standard, "", "", _supplierStep, new List <TagRequirement>
            {
                _requirementForSupplier
            });
            _tagInSupplierStep.SetProtectedIdForTesting(TagInSupplierStepId);
            _tagInOtherStep = new Tag(TestPlant, TagType.Standard, "", "", _otherStep, new List <TagRequirement>
            {
                _requirementForOther
            });
            _tagInOtherStep.SetProtectedIdForTesting(TagInOtherStepId);

            _projectRepoMock = new Mock <IProjectRepository>();
            _projectRepoMock.Setup(r => r.GetTagByTagIdAsync(TagInSupplierStepId)).Returns(Task.FromResult(_tagInSupplierStep));
            _projectRepoMock.Setup(r => r.GetTagByTagIdAsync(TagInOtherStepId)).Returns(Task.FromResult(_tagInOtherStep));
            _personRepoMock = new Mock <IPersonRepository>();
            _personRepoMock
            .Setup(p => p.GetByOidAsync(It.Is <Guid>(x => x == CurrentUserOid)))
            .Returns(Task.FromResult(new Person(CurrentUserOid, "Test", "User")));

            _commandForSupplierRequirement = new PreserveCommand(TagInSupplierStepId, RequirementForSupplierId);
            _commandForOtherRequirement    = new PreserveCommand(TagInOtherStepId, RequirementForOtherId);

            _timeProvider.Elapse(TimeSpan.FromDays(-1));
            _tagInSupplierStep.StartPreservation();
            _tagInOtherStep.StartPreservation();

            _timeProvider.SetTime(_utcNow);

            _initialPreservationPeriodForSupplierRequirement = _requirementForSupplier.PreservationPeriods.Single();
            _initialPreservationPeriodForOtherRequirement    = _requirementForOther.PreservationPeriods.Single();

            _dut = new PreserveCommandHandler(
                _projectRepoMock.Object,
                _personRepoMock.Object,
                UnitOfWorkMock.Object,
                CurrentUserProviderMock.Object);
        }