public void Setup_OkState() { _tagIds = new List <int> { TagId1, TagId2 }; _tagIdsWithRowVersion = new List <IdAndRowVersion> { new IdAndRowVersion(TagId1, RowVersion1), new IdAndRowVersion(TagId2, RowVersion2) }; _projectValidatorMock = new Mock <IProjectValidator>(); _projectValidatorMock.Setup(p => p.AllTagsInSameProjectAsync(_tagIds, default)).Returns(Task.FromResult(true)); _tagValidatorMock = new Mock <ITagValidator>(); _tagValidatorMock.Setup(r => r.ExistsAsync(TagId1, default)).Returns(Task.FromResult(true)); _tagValidatorMock.Setup(r => r.ExistsAsync(TagId2, default)).Returns(Task.FromResult(true)); _tagValidatorMock.Setup(r => r.IsReadyToBeRescheduledAsync(TagId1, default)).Returns(Task.FromResult(true)); _tagValidatorMock.Setup(r => r.IsReadyToBeRescheduledAsync(TagId2, default)).Returns(Task.FromResult(true)); _command = new RescheduleCommand(_tagIdsWithRowVersion, 1, RescheduledDirection.Later, "Comment"); _rowVersionValidatorMock = new Mock <IRowVersionValidator>(); _rowVersionValidatorMock.Setup(r => r.IsValid(RowVersion1)).Returns(true); _rowVersionValidatorMock.Setup(r => r.IsValid(RowVersion2)).Returns(true); _dut = new RescheduleCommandValidator( _projectValidatorMock.Object, _tagValidatorMock.Object, _rowVersionValidatorMock.Object); }
public void Validate_ShouldFail_WhenNoTagsGiven() { var command = new RescheduleCommand(new List <IdAndRowVersion>(), 1, RescheduledDirection.Later, "Comment"); var result = _dut.Validate(command); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith("At least 1 tag must be given!")); }
public void Validate_ShouldFail_WhenWeeksToHigh() { var command = new RescheduleCommand(_tagIdsWithRowVersion, RescheduleCommandValidator.MaxRescheduleWeeks + 1, RescheduledDirection.Later, "Comment"); var result = _dut.Validate(command); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith($"Rescheduling must be in range of 1 to {RescheduleCommandValidator.MaxRescheduleWeeks} week(s)!")); }
public void Setup() { var stepMock = new Mock <Step>(); stepMock.SetupGet(s => s.Plant).Returns(TestPlant); _rd1Mock = new Mock <RequirementDefinition>(); _rd1Mock.SetupGet(rd => rd.Id).Returns(_rdId1); _rd1Mock.SetupGet(rd => rd.Plant).Returns(TestPlant); _rd2Mock = new Mock <RequirementDefinition>(); _rd2Mock.SetupGet(rd => rd.Id).Returns(_rdId2); _rd2Mock.SetupGet(rd => rd.Plant).Returns(TestPlant); _req1OnTag1 = new TagRequirement(TestPlant, 1, _rd1Mock.Object); _req2OnTag1 = new TagRequirement(TestPlant, 2, _rd2Mock.Object); _req1OnTag2 = new TagRequirement(TestPlant, 3, _rd1Mock.Object); _req2OnTag2 = new TagRequirement(TestPlant, 4, _rd2Mock.Object); _tag1 = new Tag(TestPlant, TagType.Standard, "", "", stepMock.Object, new List <TagRequirement> { _req1OnTag1, _req2OnTag1 }); _tag1.StartPreservation(); _tag1.SetProtectedIdForTesting(_tagId1); _tag2 = new Tag(TestPlant, TagType.Standard, "", "", stepMock.Object, new List <TagRequirement> { _req1OnTag2, _req2OnTag2 }); _tag2.StartPreservation(); _tag2.SetProtectedIdForTesting(_tagId2); var tags = new List <Tag> { _tag1, _tag2 }; var tagIds = new List <int> { _tagId1, _tagId2 }; var tagIdsWithRowVersion = new List <IdAndRowVersion> { new IdAndRowVersion(_tagId1, _rowVersion1), new IdAndRowVersion(_tagId2, _rowVersion2) }; _projectRepoMock = new Mock <IProjectRepository>(); _projectRepoMock.Setup(r => r.GetTagsByTagIdsAsync(tagIds)).Returns(Task.FromResult(tags)); _rescheduleOneWeekLaterCommand = new RescheduleCommand(tagIdsWithRowVersion, 1, RescheduledDirection.Later, "Comment"); _rescheduleFourWeeksEarlierCommand = new RescheduleCommand(tagIdsWithRowVersion, 4, RescheduledDirection.Earlier, "Comment"); _dut = new RescheduleCommandHandler(_projectRepoMock.Object, UnitOfWorkMock.Object); }
public void Validate_ShouldFail_WhenTagsNotUnique() { var command = new RescheduleCommand( new List <IdAndRowVersion> { new IdAndRowVersion(1, null), new IdAndRowVersion(1, null) }, 1, RescheduledDirection.Later, "Comment"); var result = _dut.Validate(command); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith("Tags must be unique!")); }